Skip to content

Commit

Permalink
Removes is_impl_type_changeable optimization.
Browse files Browse the repository at this point in the history
This optimization is now removed from the TraitMAp because it breaks
the insert_implementation_for_type of mutable references.
  • Loading branch information
esdrubal committed Dec 12, 2024
1 parent 2f830e4 commit aaed7cc
Showing 1 changed file with 3 additions and 30 deletions.
33 changes: 3 additions & 30 deletions sway-core/src/semantic_analysis/namespace/trait_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ struct TraitValue {
trait_items: TraitItems,
/// The span of the entire impl block.
impl_span: Span,
is_impl_type_changeable: bool,
}

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -271,7 +270,6 @@ impl TraitMap {
TraitValue {
trait_items: map_trait_items,
impl_span: existing_impl_span,
is_impl_type_changeable: _,
},
} in trait_impls.iter()
{
Expand Down Expand Up @@ -441,17 +439,12 @@ impl TraitMap {
is_absolute: trait_name.is_absolute,
});

let is_impl_type_changeable = engines
.te()
.is_type_changeable(engines, &engines.te().get(type_id));

// even if there is a conflicting definition, add the trait anyway
self.insert_inner(
trait_name,
impl_span.clone(),
trait_decl_span,
type_id,
is_impl_type_changeable,
trait_items,
engines,
);
Expand All @@ -466,7 +459,6 @@ impl TraitMap {
impl_span: Span,
trait_decl_span: Option<Span>,
type_id: TypeId,
is_impl_type_changeable: bool,
trait_methods: TraitItems,
engines: &Engines,
) {
Expand All @@ -478,7 +470,6 @@ impl TraitMap {
let value = TraitValue {
trait_items: trait_methods,
impl_span,
is_impl_type_changeable,
};
let entry = TraitEntry { key, value };
let mut trait_impls: TraitImpls = HashMap::<TypeRootFilter, Vec<TraitEntry>>::new();
Expand Down Expand Up @@ -594,7 +585,7 @@ impl TraitMap {
let trait_map = &mut lexical_scope.items.implemented_traits;

base_trait_map.extend(
trait_map.filter_by_type(type_id, engines, true, code_block_first_pass.clone()),
trait_map.filter_by_type(type_id, engines, code_block_first_pass.clone()),
engines,
);
Ok(None::<()>)
Expand Down Expand Up @@ -775,7 +766,6 @@ impl TraitMap {
&self,
type_id: TypeId,
engines: &Engines,
consider_only_type_changeable: bool,
code_block_first_pass: CodeBlockFirstPass,
) -> TraitMap {
let unify_checker = UnifyCheck::constraint_subset(engines);
Expand All @@ -785,13 +775,7 @@ impl TraitMap {
let mut all_types = type_id.extract_inner_types(engines, IncludeSelf::No);
all_types.insert(type_id);
let all_types = all_types.into_iter().collect::<Vec<_>>();
self.filter_by_type_inner(
engines,
all_types,
decider,
consider_only_type_changeable,
code_block_first_pass,
)
self.filter_by_type_inner(engines, all_types, decider, code_block_first_pass)
}

/// Filters the entries in `self` with the given [TypeId] `type_id` and
Expand Down Expand Up @@ -869,7 +853,6 @@ impl TraitMap {
engines,
vec![type_id],
decider,
false,
code_block_first_pass.clone(),
);
let all_types = type_id
Expand All @@ -880,7 +863,7 @@ impl TraitMap {
let decider2 = |left: TypeId, right: TypeId| unify_checker.check(left, right);

trait_map.extend(
self.filter_by_type_inner(engines, all_types, decider2, false, code_block_first_pass),
self.filter_by_type_inner(engines, all_types, decider2, code_block_first_pass),
engines,
);
trait_map
Expand All @@ -891,7 +874,6 @@ impl TraitMap {
engines: &Engines,
mut all_types: Vec<TypeId>,
decider: impl Fn(TypeId, TypeId) -> bool,
consider_only_type_changeable: bool,
code_block_first_pass: CodeBlockFirstPass,
) -> TraitMap {
let type_engine = engines.te();
Expand All @@ -911,22 +893,16 @@ impl TraitMap {
TraitValue {
trait_items: map_trait_items,
impl_span,
is_impl_type_changeable,
},
} in impls.iter()
{
if consider_only_type_changeable && !is_impl_type_changeable {
continue;
}

if !type_engine.is_type_changeable(engines, &type_info) && *type_id == *map_type_id
{
trait_map.insert_inner(
map_trait_name.clone(),
impl_span.clone(),
map_trait_decl_span.clone(),
*type_id,
false,
map_trait_items.clone(),
engines,
);
Expand Down Expand Up @@ -1020,14 +996,11 @@ impl TraitMap {
})
.collect();

let is_impl_type_changeable =
type_engine.is_type_changeable(engines, &type_info);
trait_map.insert_inner(
map_trait_name.clone(),
impl_span.clone(),
map_trait_decl_span.clone(),
*type_id,
is_impl_type_changeable,
trait_items,
engines,
);
Expand Down

0 comments on commit aaed7cc

Please sign in to comment.