Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove subs type optimization causing find method issues #6532

Merged
merged 3 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions sway-core/src/decl_engine/ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,19 +147,13 @@ where
ctx: &SubstTypesContext,
) -> Option<Self> {
let decl_engine = ctx.engines.de();
if type_mapping.source_ids_contains_concrete_type(ctx.engines)
|| !decl_engine.get(&self.id).is_concrete(ctx.engines)
{
let mut decl = (*decl_engine.get(&self.id)).clone();
if decl.subst(type_mapping, ctx).has_changes() {
Some(
decl_engine
.insert(decl, decl_engine.get_parsed_decl_id(&self.id).as_ref())
.with_parent(decl_engine, self.id.into()),
)
} else {
None
}
let mut decl = (*decl_engine.get(&self.id)).clone();
if decl.subst(type_mapping, ctx).has_changes() {
Some(
decl_engine
.insert(decl, decl_engine.get_parsed_decl_id(&self.id).as_ref())
.with_parent(decl_engine, self.id.into()),
)
} else {
None
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,21 @@ impl MyFrom<Struct4> for Struct3 {
}
}

// call an associated function through generic constraints
pub trait SizeInBytes {
fn size() -> u64;
}

impl SizeInBytes for u64 {
fn size() -> u64 {
8
}
}

fn call_size<T>() -> u64 where T: SizeInBytes {
T::size()
}

fn main() -> bool {
let s1 = Struct {data: 1_u64 };
assert_eq(s1.data.my_add(1,2),3);
Expand All @@ -72,5 +87,8 @@ fn main() -> bool {
let s4: Struct3 = Struct4{data:42}.my_into();
assert_eq(s4.data,42);

// call an associated function through generic constraints
assert_eq(call_size::<u64>(), 8);

true
}
Loading