fix: allowing accessing associated constants via Self::...#8403
Merged
fix: allowing accessing associated constants via Self::...#8403
Self::...#8403Conversation
5 tasks
Collaborator
Author
|
I created #8417 as an incomplete follow-up PR to show how this could be implemented for the general case. I think we need a new But... given that I'm not too familiar with definition IDs I'd prefer to do that as a follow-up PR, if that approach would be correct. |
TomAFrench
approved these changes
May 13, 2025
Member
TomAFrench
left a comment
There was a problem hiding this comment.
Forgot to hit approve on this.
github-merge-queue bot
pushed a commit
to AztecProtocol/aztec-packages
that referenced
this pull request
May 14, 2025
Automated pull of nightly from the [noir](https://github.com/noir-lang/noir) programming language, a dependency of Aztec. BEGIN_COMMIT_OVERRIDE fix: pass Field to ToBits intrinsic in remove_bit_shifts optimization (noir-lang/noir#8493) fix: don't produce `index Field` in value merger (noir-lang/noir#8492) fix: allowing accessing associated constants via `Self::...` (noir-lang/noir#8403) fix: remove unused generic in static_assert (noir-lang/noir#8488) fix: disallow generics on entry points (noir-lang/noir#8490) chore(test): Replicate comptime stack overflow in a test (noir-lang/noir#8473) feat: `#[test(only_fail_with = "...")]` (noir-lang/noir#8460) fix: variable used in fmtstr inside lambda wasn't tracked as captured (noir-lang/noir#8487) chore(test): Add more tests for defunctionalization (noir-lang/noir#8481) END_COMMIT_OVERRIDE Co-authored-by: AztecBot <tech@aztecprotocol.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Problem
Part of #7812
Part of #8096
Summary
This PR only solves two very specific cases.
Self::Ninside a traitThis now compiles fine:
For this, if we find
Self::Nwhile being inside a trait, we search for an associated constant. If we find one, that's the type of the expression. The value of the expression doesn't matter (I used zero) because trait methods never produce code, only trait impl methods.Self::Ninside a trait implThis now compiles fine:
For this, if we find
Self::Nwhile being inside a trait impl, we search for an associated constant. If we find one and it has a constant value, we use that value.What still doesn't work?
The other way to access an associated constant is in code like this:
This case is trickier because even though we can find the associated type, we don't know it's value and I think we have to defer that until monomorphization... but we don't have anything to represent that, yet.
Another thing that doesn't work is the
Self::Ncase inside a trait impl whereNis an associated constant without a constant value. For example:Here, like in the previous case, we can only know the value of
Nduring monomorphization.I still think this PR might be worth on its own because the logic to solve at least the last case would be around the new code, except that we need something new to represent it. And then, the two cases implemented here cover a lot of use cases, probably the most common ones.
Additional Context
Type::Constantholds aFieldElement, but I'm thinking it should probably hold aSignedField.nargo expandfixes regarding associated constants. I needed those for the new tests, but in the end the new tests fail for a different reason... but some of the existing ignored tests could be unignored.Documentation
Check one:
PR Checklist
cargo fmton default settings.