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

feat: Allow associated types to be ellided from trait constraints #7026

Merged
merged 14 commits into from
Jan 14, 2025

Conversation

jfecher
Copy link
Contributor

@jfecher jfecher commented Jan 10, 2025

Description

Problem*

Resolves #6571 (but does not implement #6811)
Resolves #7039

Summary*

Allows users to elide associated types from trait constraints. E.g. given a trait Iterator with an associated type Elem, we now allow constraints of the form T: Iterator in addition to the previous T: Iterator<Elem = U>.

Additional Context

Implementing this usually means finding where to insert implicit type variables for the associated types, this location is different for each item (functions, trait impls, trait definitions).

Because of constraints like where T: Foo, <T as Foo>::Bar: Eq, we have to introduce these assumed trait impls to scope as we go, otherwise we'll get an error that there's no impl for T: Foo when resolving the type <T as Foo>::Bar. Since I've chosen to do this in order, constraints like this rely on their ordering so where <T as Foo>::Bar: Eq, T: Foo will give an error.

This PR does not implement this feature for trait definitions (see #7024). I had trouble getting this working and believe this to be the rarest use case (compared to constraints on functions & trait impls) so I'm opting to leave this for a later PR.

Documentation*

Check one:

  • No documentation needed.
  • Documentation included in this PR.
  • [For Experimental Features] Documentation to be submitted in a separate PR.

PR Checklist*

  • I have tested the changes locally.
  • I have formatted the changes with Prettier and/or cargo fmt on default settings.

@jfecher jfecher requested a review from a team January 10, 2025 18:10
@github-actions github-actions bot added the documentation Improvements or additions to documentation label Jan 10, 2025
Copy link
Contributor

github-actions bot commented Jan 10, 2025

Compilation Memory Report

Program Peak Memory
keccak256 78.13M
workspace 123.92M
regression_4709 424.09M
ram_blowup_regression 1.58G
rollup-base-public 4.85G
rollup-base-private 1.26G
private-kernel-tail 207.18M
private-kernel-reset 669.26M
private-kernel-inner 294.40M

Copy link
Contributor

github-actions bot commented Jan 10, 2025

Execution Memory Report

Program Peak Memory
keccak256 74.67M
workspace 123.84M
regression_4709 316.00M
ram_blowup_regression 512.61M
rollup-base-public 478.87M
rollup-base-private 325.48M
private-kernel-tail 180.47M
private-kernel-reset 245.16M
private-kernel-inner 208.55M

Copy link
Contributor

github-actions bot commented Jan 10, 2025

Execution Report

Program Execution Time %
sha256_regression 0.052s 0%
regression_4709 0.001s 0%
ram_blowup_regression 0.602s -1%
rollup-root 0.105s 0%
rollup-merge 0.007s 16%
rollup-block-merge 0.104s -1%
rollup-base-public 1.222s -1%
rollup-base-private 0.449s -1%
private-kernel-tail 0.019s 0%
private-kernel-reset 0.313s 0%
private-kernel-inner 0.068s -2%

Copy link
Contributor

github-actions bot commented Jan 10, 2025

Compilation Report

Program Compilation Time %
sha256_regression 1.272s 1%
regression_4709 0.793s 1%
ram_blowup_regression 18.200s 1%
rollup-root 3.596s 7%
rollup-merge 1.960s 5%
rollup-block-merge 3.430s -3%
rollup-base-public 40.340s -7%
rollup-base-private 12.300s -1%
private-kernel-tail 0.944s -6%
private-kernel-reset 6.352s -2%
private-kernel-inner 1.986s -5%

Copy link
Contributor

github-actions bot commented Jan 10, 2025

compiler/noirc_frontend/src/elaborator/mod.rs Outdated Show resolved Hide resolved
compiler/noirc_frontend/src/elaborator/mod.rs Outdated Show resolved Hide resolved
compiler/noirc_frontend/src/elaborator/mod.rs Show resolved Hide resolved
compiler/noirc_frontend/src/elaborator/mod.rs Outdated Show resolved Hide resolved
@jfecher
Copy link
Contributor Author

jfecher commented Jan 10, 2025

The unit tests found a regression that I'm fixing atm. We apparently:

  • Don't error anymore if the user forgets to specify an associated type in a trait impl (not a constraint, the actual impl)
  • Error twice instead of once if an impl's constraint is to a trait that doesn't exist

@michaeljklein
Copy link
Contributor

Don't error anymore if the user forgets to specify an associated type in a trait impl (not a constraint, the actual impl)

I think that might be this line? https://github.com/noir-lang/noir/pull/7026/files#diff-ac857943134bba360eee936142f9043704ff127f0a9a188e6feba623ae68d93aL386

Was wondering when I saw it how we could be sure that the error is thrown elsewhere and it sounds similar.

@jfecher
Copy link
Contributor Author

jfecher commented Jan 13, 2025

@michaeljklein it was, yeah. The short of it was that in most cases we do allow associated types to be elided but in trait impls we also use that method for checking the trait being implemented has all its generics and associated types, so in that case we want to disallow them.

With that fixed, there's still one more test to fix which is that we issue the "no trait Foo in scope" error twice now in one case.

@jfecher
Copy link
Contributor Author

jfecher commented Jan 13, 2025

@michaeljklein ready for re-review

@jfecher
Copy link
Contributor Author

jfecher commented Jan 13, 2025

Currently blocked by #7039

Thanks @asterite for unblocking this

Copy link
Contributor

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

@jfecher jfecher requested a review from michaeljklein January 13, 2025 20:58
@jfecher jfecher enabled auto-merge January 13, 2025 20:59
Copy link
Contributor

@michaeljklein michaeljklein left a comment

Choose a reason for hiding this comment

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

LGTM

@jfecher jfecher added this pull request to the merge queue Jan 14, 2025
Merged via the queue into master with commit aa7b91c Jan 14, 2025
88 checks passed
@jfecher jfecher deleted the jf/assoc-types branch January 14, 2025 16:36
AztecBot added a commit to AztecProtocol/aztec-packages that referenced this pull request Jan 14, 2025
…oir-lang/noir#7066)

feat!: Handle generic fields in `StructDefinition::fields` and move old functionality to `StructDefinition::fields_as_written` (noir-lang/noir#7067)
chore(ci): Check various inliner aggressiveness setttings in Brillig reports (noir-lang/noir#7049)
chore: reenable reports on rollup root circuits (noir-lang/noir#7061)
fix: don't always select trait impl when verifying trait constraints (noir-lang/noir#7041)
chore: mark some critical libraries as good again (noir-lang/noir#7065)
fix: Reduce memory usage in mem2reg (noir-lang/noir#7053)
feat: Allow associated types to be ellided from trait constraints (noir-lang/noir#7026)
chore(perf): try using vec-collections's VecSet in AliasSet (noir-lang/noir#7058)
chore: reduce number of iterations of `acvm::compiler::compile` (noir-lang/noir#7050)
chore: add `noir_check_shuffle` as a critical library (noir-lang/noir#7056)
chore: clippy warning fix (noir-lang/noir#7051)
chore(ci): Unify compilation/execution report jobs that take averages with single runs  (noir-lang/noir#7048)
fix(nargo_fmt): let doc comment could come after regular comment (noir-lang/noir#7046)
fix(nargo_fmt): don't consider identifiers the same if they are equal… (noir-lang/noir#7043)
feat: auto-import traits when suggesting trait methods (noir-lang/noir#7037)
feat: avoid inserting `inc_rc` instructions into ACIR (noir-lang/noir#7036)
fix(lsp): suggest all possible trait methods, but only visible ones (noir-lang/noir#7027)
chore: add more protocol circuits to reports (noir-lang/noir#6977)
feat: avoid generating a new witness when checking if linear expression is zero (noir-lang/noir#7031)
feat: skip codegen of zero iteration loops (noir-lang/noir#7030)
AztecBot added a commit to AztecProtocol/aztec-packages that referenced this pull request Jan 14, 2025
…ir#7066)

feat!: Handle generic fields in `StructDefinition::fields` and move old functionality to `StructDefinition::fields_as_written` (noir-lang/noir#7067)
chore(ci): Check various inliner aggressiveness setttings in Brillig reports (noir-lang/noir#7049)
chore: reenable reports on rollup root circuits (noir-lang/noir#7061)
fix: don't always select trait impl when verifying trait constraints (noir-lang/noir#7041)
chore: mark some critical libraries as good again (noir-lang/noir#7065)
fix: Reduce memory usage in mem2reg (noir-lang/noir#7053)
feat: Allow associated types to be ellided from trait constraints (noir-lang/noir#7026)
chore(perf): try using vec-collections's VecSet in AliasSet (noir-lang/noir#7058)
chore: reduce number of iterations of `acvm::compiler::compile` (noir-lang/noir#7050)
chore: add `noir_check_shuffle` as a critical library (noir-lang/noir#7056)
chore: clippy warning fix (noir-lang/noir#7051)
chore(ci): Unify compilation/execution report jobs that take averages with single runs  (noir-lang/noir#7048)
fix(nargo_fmt): let doc comment could come after regular comment (noir-lang/noir#7046)
fix(nargo_fmt): don't consider identifiers the same if they are equal… (noir-lang/noir#7043)
feat: auto-import traits when suggesting trait methods (noir-lang/noir#7037)
feat: avoid inserting `inc_rc` instructions into ACIR (noir-lang/noir#7036)
fix(lsp): suggest all possible trait methods, but only visible ones (noir-lang/noir#7027)
chore: add more protocol circuits to reports (noir-lang/noir#6977)
feat: avoid generating a new witness when checking if linear expression is zero (noir-lang/noir#7031)
feat: skip codegen of zero iteration loops (noir-lang/noir#7030)
AztecBot added a commit to AztecProtocol/aztec-packages that referenced this pull request Jan 15, 2025
…ir#7070)

feat(LSP): code action to import trait in a method call (noir-lang/noir#7066)
feat!: Handle generic fields in `StructDefinition::fields` and move old functionality to `StructDefinition::fields_as_written` (noir-lang/noir#7067)
chore(ci): Check various inliner aggressiveness setttings in Brillig reports (noir-lang/noir#7049)
chore: reenable reports on rollup root circuits (noir-lang/noir#7061)
fix: don't always select trait impl when verifying trait constraints (noir-lang/noir#7041)
chore: mark some critical libraries as good again (noir-lang/noir#7065)
fix: Reduce memory usage in mem2reg (noir-lang/noir#7053)
feat: Allow associated types to be ellided from trait constraints (noir-lang/noir#7026)
chore(perf): try using vec-collections's VecSet in AliasSet (noir-lang/noir#7058)
chore: reduce number of iterations of `acvm::compiler::compile` (noir-lang/noir#7050)
chore: add `noir_check_shuffle` as a critical library (noir-lang/noir#7056)
chore: clippy warning fix (noir-lang/noir#7051)
chore(ci): Unify compilation/execution report jobs that take averages with single runs  (noir-lang/noir#7048)
fix(nargo_fmt): let doc comment could come after regular comment (noir-lang/noir#7046)
fix(nargo_fmt): don't consider identifiers the same if they are equal… (noir-lang/noir#7043)
feat: auto-import traits when suggesting trait methods (noir-lang/noir#7037)
feat: avoid inserting `inc_rc` instructions into ACIR (noir-lang/noir#7036)
fix(lsp): suggest all possible trait methods, but only visible ones (noir-lang/noir#7027)
chore: add more protocol circuits to reports (noir-lang/noir#6977)
feat: avoid generating a new witness when checking if linear expression is zero (noir-lang/noir#7031)
feat: skip codegen of zero iteration loops (noir-lang/noir#7030)
AztecBot added a commit to AztecProtocol/aztec-packages that referenced this pull request Jan 15, 2025
feat(LSP): code action to import trait in a method call (noir-lang/noir#7066)
feat!: Handle generic fields in `StructDefinition::fields` and move old functionality to `StructDefinition::fields_as_written` (noir-lang/noir#7067)
chore(ci): Check various inliner aggressiveness setttings in Brillig reports (noir-lang/noir#7049)
chore: reenable reports on rollup root circuits (noir-lang/noir#7061)
fix: don't always select trait impl when verifying trait constraints (noir-lang/noir#7041)
chore: mark some critical libraries as good again (noir-lang/noir#7065)
fix: Reduce memory usage in mem2reg (noir-lang/noir#7053)
feat: Allow associated types to be ellided from trait constraints (noir-lang/noir#7026)
chore(perf): try using vec-collections's VecSet in AliasSet (noir-lang/noir#7058)
chore: reduce number of iterations of `acvm::compiler::compile` (noir-lang/noir#7050)
chore: add `noir_check_shuffle` as a critical library (noir-lang/noir#7056)
chore: clippy warning fix (noir-lang/noir#7051)
chore(ci): Unify compilation/execution report jobs that take averages with single runs  (noir-lang/noir#7048)
fix(nargo_fmt): let doc comment could come after regular comment (noir-lang/noir#7046)
fix(nargo_fmt): don't consider identifiers the same if they are equal… (noir-lang/noir#7043)
feat: auto-import traits when suggesting trait methods (noir-lang/noir#7037)
feat: avoid inserting `inc_rc` instructions into ACIR (noir-lang/noir#7036)
fix(lsp): suggest all possible trait methods, but only visible ones (noir-lang/noir#7027)
chore: add more protocol circuits to reports (noir-lang/noir#6977)
feat: avoid generating a new witness when checking if linear expression is zero (noir-lang/noir#7031)
feat: skip codegen of zero iteration loops (noir-lang/noir#7030)
TomAFrench added a commit to AztecProtocol/aztec-packages that referenced this pull request Jan 15, 2025
Automated pull of development from the
[noir](https://github.com/noir-lang/noir) programming language, a
dependency of Aztec.
BEGIN_COMMIT_OVERRIDE
chore: add end step for formatting workflow
(noir-lang/noir#7070)
feat(LSP): code action to import trait in a method call
(noir-lang/noir#7066)
feat!: Handle generic fields in `StructDefinition::fields` and move old
functionality to `StructDefinition::fields_as_written`
(noir-lang/noir#7067)
chore(ci): Check various inliner aggressiveness setttings in Brillig
reports (noir-lang/noir#7049)
chore: reenable reports on rollup root circuits
(noir-lang/noir#7061)
fix: don't always select trait impl when verifying trait constraints
(noir-lang/noir#7041)
chore: mark some critical libraries as good again
(noir-lang/noir#7065)
fix: Reduce memory usage in mem2reg
(noir-lang/noir#7053)
feat: Allow associated types to be ellided from trait constraints
(noir-lang/noir#7026)
chore(perf): try using vec-collections's VecSet in AliasSet
(noir-lang/noir#7058)
chore: reduce number of iterations of `acvm::compiler::compile`
(noir-lang/noir#7050)
chore: add `noir_check_shuffle` as a critical library
(noir-lang/noir#7056)
chore: clippy warning fix (noir-lang/noir#7051)
chore(ci): Unify compilation/execution report jobs that take averages
with single runs (noir-lang/noir#7048)
fix(nargo_fmt): let doc comment could come after regular comment
(noir-lang/noir#7046)
fix(nargo_fmt): don't consider identifiers the same if they are equal…
(noir-lang/noir#7043)
feat: auto-import traits when suggesting trait methods
(noir-lang/noir#7037)
feat: avoid inserting `inc_rc` instructions into ACIR
(noir-lang/noir#7036)
fix(lsp): suggest all possible trait methods, but only visible ones
(noir-lang/noir#7027)
chore: add more protocol circuits to reports
(noir-lang/noir#6977)
feat: avoid generating a new witness when checking if linear expression
is zero (noir-lang/noir#7031)
feat: skip codegen of zero iteration loops
(noir-lang/noir#7030)
END_COMMIT_OVERRIDE

---------

Co-authored-by: Tom French <[email protected]>
Co-authored-by: Tom French <[email protected]>
Co-authored-by: Jake Fecher <[email protected]>
AztecBot added a commit to AztecProtocol/aztec-nr that referenced this pull request Jan 16, 2025
Automated pull of development from the
[noir](https://github.com/noir-lang/noir) programming language, a
dependency of Aztec.
BEGIN_COMMIT_OVERRIDE
chore: add end step for formatting workflow
(noir-lang/noir#7070)
feat(LSP): code action to import trait in a method call
(noir-lang/noir#7066)
feat!: Handle generic fields in `StructDefinition::fields` and move old
functionality to `StructDefinition::fields_as_written`
(noir-lang/noir#7067)
chore(ci): Check various inliner aggressiveness setttings in Brillig
reports (noir-lang/noir#7049)
chore: reenable reports on rollup root circuits
(noir-lang/noir#7061)
fix: don't always select trait impl when verifying trait constraints
(noir-lang/noir#7041)
chore: mark some critical libraries as good again
(noir-lang/noir#7065)
fix: Reduce memory usage in mem2reg
(noir-lang/noir#7053)
feat: Allow associated types to be ellided from trait constraints
(noir-lang/noir#7026)
chore(perf): try using vec-collections's VecSet in AliasSet
(noir-lang/noir#7058)
chore: reduce number of iterations of `acvm::compiler::compile`
(noir-lang/noir#7050)
chore: add `noir_check_shuffle` as a critical library
(noir-lang/noir#7056)
chore: clippy warning fix (noir-lang/noir#7051)
chore(ci): Unify compilation/execution report jobs that take averages
with single runs (noir-lang/noir#7048)
fix(nargo_fmt): let doc comment could come after regular comment
(noir-lang/noir#7046)
fix(nargo_fmt): don't consider identifiers the same if they are equal…
(noir-lang/noir#7043)
feat: auto-import traits when suggesting trait methods
(noir-lang/noir#7037)
feat: avoid inserting `inc_rc` instructions into ACIR
(noir-lang/noir#7036)
fix(lsp): suggest all possible trait methods, but only visible ones
(noir-lang/noir#7027)
chore: add more protocol circuits to reports
(noir-lang/noir#6977)
feat: avoid generating a new witness when checking if linear expression
is zero (noir-lang/noir#7031)
feat: skip codegen of zero iteration loops
(noir-lang/noir#7030)
END_COMMIT_OVERRIDE

---------

Co-authored-by: Tom French <[email protected]>
Co-authored-by: Tom French <[email protected]>
Co-authored-by: Jake Fecher <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect private warning Traits with associated types can't be used in where clauses
3 participants