Skip to content

fix: Matching generics in traits and structs #93

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

Merged
merged 4 commits into from
May 22, 2025
Merged

Conversation

mpenciak
Copy link
Contributor

@mpenciak mpenciak commented May 13, 2025

This PR fixes a small issue where if the trait and type both use the same generic type variable in a trait impl block, then the extractor would extract the generic parameter multiple times.

An example is

trait Foo<I> {
    fn foo(self) -> I
}

struct Pair<I> {
    a : I,
    b : I,
}

impl<I> Foo<I> for Pair<I> {
    fn foo(self) -> I {
        self.a
    }
}

used to extract to

nr_struct_def multiple_generics::Pair<I> {
    a : I,
    b : I
}

nr_trait_impl[impl_405] <I, I> multiple_generics::Foo<I> for multiple_generics::Pair<I> where  {
    fn «multiple_generics»::«foo»<> (self : multiple_generics::Pair<I>) -> I {
        (self as multiple_generics::Pair<I>).a;
}
}

But now extracts to

nr_trait_impl[impl_405] <I> multiple_generics::Foo<I> for multiple_generics::Pair<I> where ...

This PR also tries to slightly clean up the end to end testing infrastructure. With the merging of #84 we can now lump a number of tests into a single noir/lampe project.

To this end I've added an ExtractionTests folder that starts the process of merging some of the simpler tests. For tests in the Examples/ folder that only check whether Lampe successfully extracts and parses the resulting extracted Lean correctly, we can start adding the tests as separate files in the ExtractionTests folder.

@mpenciak mpenciak force-pushed the mp/multiple_generics branch 2 times, most recently from 730ed6b to d5e4961 Compare May 21, 2025 02:55
@mpenciak mpenciak changed the title fix: when the trait and implementer have the same generics, do not re… fix: Matching generics in traits and structs May 21, 2025
@mpenciak mpenciak marked this pull request as ready for review May 21, 2025 03:11
@mpenciak mpenciak requested review from piohei and iamrecursion May 21, 2025 03:12
Copy link
Collaborator

@iamrecursion iamrecursion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me, with the caveat that I am not overly familiar with the current state of the extractor. Nevertheless, the logic and the extracted result both make intuitive sense to me.

@mpenciak mpenciak force-pushed the mp/multiple_generics branch from d5e4961 to dbf7bb0 Compare May 22, 2025 19:33
@mpenciak mpenciak merged commit e478b35 into main May 22, 2025
4 checks passed
@mpenciak mpenciak deleted the mp/multiple_generics branch May 22, 2025 22:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants