Skip to content

Commit

Permalink
Remove subs type optimization causing find method issues (#6532)
Browse files Browse the repository at this point in the history
## Description

This PR fixes #6491

## Checklist

- [x] I have linked to any relevant issues.
- [ ] I have commented my code, particularly in hard-to-understand
areas.
- [ ] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [ ] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [ ] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.

---------

Co-authored-by: Joshua Batty <joshpbatty@gmail.com>
  • Loading branch information
xunilrj and JoshuaBatty authored Sep 12, 2024
1 parent 11d8f54 commit fa3dafa
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
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
}

0 comments on commit fa3dafa

Please sign in to comment.