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

find_method_for_type improvements #6744

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

esdrubal
Copy link
Contributor

@esdrubal esdrubal commented Nov 20, 2024

Description

TraitMap::insert now verifies that type parameters trait constraints are satisfied before throwing a duplicate method error.

find_method_for_type was also changed, so it now checks that trait constraints are satisfied before returning the matched method. It also now does a preemptive TraitMap::insert_trait_implementation_for_type this allow us to have:

impl<Z> S<Z>
where
Z: Cat,
{
    fn foo(self) -> u64 {
        1 
    }
}

impl S<u32> {
    fn foo(self) -> u64 {
        1 
    }
}

and still find both methods. Before the change, the compiler would pick the second implementation without inserting the first one into the trait map.

It was added to find_method_for_type exact matching check that avoids Multiple applicable items in scope error for refs and ref must.

Updated find_method_for_type blanket implementation logic where, when we have impl<T> FromBytes for T and impl FromBytes for DataPoint we pick the second implementation.

TraitMap::insert_trait_implementation_for_type now caches the already inserted types to avoid adding multiple times the same types.

Checklist

  • 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).
  • 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.
  • I have done my best to ensure that my PR adheres to the Fuel Labs Code Review Standards.
  • I have requested a review from the relevant team or maintainers.

@esdrubal esdrubal added the compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen label Nov 20, 2024
@esdrubal esdrubal self-assigned this Nov 20, 2024
@esdrubal esdrubal force-pushed the esdrubal/find_method_for_type_improvements branch 2 times, most recently from 0f9283d to 6785778 Compare November 20, 2024 13:30
Copy link

codspeed-hq bot commented Nov 20, 2024

CodSpeed Performance Report

Merging #6744 will degrade performances by 46.29%

Comparing esdrubal/find_method_for_type_improvements (5b58adc) with master (bcd15c3)

Summary

❌ 2 regressions
✅ 20 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark master esdrubal/find_method_for_type_improvements Change
compile 5.4 s 10.1 s -46.29%
did_change_with_caching 506.2 ms 565.8 ms -10.54%

@esdrubal esdrubal force-pushed the esdrubal/find_method_for_type_improvements branch from 63e964b to 35bd558 Compare November 25, 2024 11:27
@esdrubal esdrubal force-pushed the esdrubal/find_method_for_type_improvements branch from 35bd558 to 9a2c809 Compare November 26, 2024 11:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant