noir-lang / noir

Noir is a domain specific language for zero knowledge proofs
https://noir-lang.org
Apache License 2.0
821 stars 177 forks source link

feat(frontend): Where clause on impl #5320

Closed vezenovm closed 6 days ago

vezenovm commented 6 days ago

Description

Problem*

Resolves #4508

Summary*

This enables the simple functionality of being able to declare a where clause directly on a struct implementation such as below:

impl<T> MyStruct<T> where T: MyEq {
    fn my_eq(self, other: Self) -> bool {
        (self.a == other.a) & self.b.my_eq(other.b)
    }
}

The code above is essentially syntactic sugar where we now every method in the struct impl a where clause. As the logic for resolving trait constraints already exists this PR really just updates the parser to accept where clauses and during definition collection attaches them to each method in an impl.

Additional Context

Documentation*

Check one:

PR Checklist*

github-actions[bot] commented 6 days ago

🚀 Deployed on https://6679df5139fd8c382cfa4791--noir-docs.netlify.app

vezenovm commented 6 days ago

Converting back to draft because the formatter needs updating

vezenovm commented 6 days ago

Converting back to draft because the formatter needs updating

The formatter was deleting the where clause on impls. I did a quick hack to get things working. I could make it more robust but I feel it can also be done in a follow-up to improve the robustness of formatting impls in general.

We should also maybe consider committing some time to larger formatter refactors/testing again.

github-actions[bot] commented 6 days ago

FYI @noir-lang/developerrelations on Noir doc changes.