Skip to content

feat: Allow TraitAsType syntax to refer to associated constants in expressions#9041

Merged
asterite merged 28 commits intomasterfrom
jf/assoc-consts
Jul 3, 2025
Merged

feat: Allow TraitAsType syntax to refer to associated constants in expressions#9041
asterite merged 28 commits intomasterfrom
jf/assoc-consts

Conversation

@jfecher
Copy link
Contributor

@jfecher jfecher commented Jun 27, 2025

Description

Problem*

Resolves #8797

Summary

Implements <Type as Trait>::Constant in an expression position.

This also makes T::Constant work in a context where we have T: Trait.

Additional Context

I wanted to implement this without adding new concepts or things for the compiler to track. I ended up generalizing TraitMethodId into a TraitItemId by changing the method_index: usize into a definition_id: DefinitionId field and giving associated constants a definition id. I did end up adding some new things to track these new definition ids though so it isn't perfect.

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.

Copy link
Contributor Author

@jfecher jfecher left a comment

Choose a reason for hiding this comment

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

Unnecessary test changes

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Test Suite Duration'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.20.

Benchmark suite Current: 41d25ee Previous: 6145aaa Ratio
test_report_zkpassport_noir_rsa_ 1 s 0 s +∞

This comment was automatically generated by workflow using github-action-benchmark.

CC: @TomAFrench

@asterite asterite marked this pull request as ready for review July 3, 2025 15:26
@asterite asterite requested a review from a team July 3, 2025 15:52
@asterite
Copy link
Collaborator

asterite commented Jul 3, 2025

I reviewed this and it looks good, though I added some more commits so it might be better for someone else to also review this.

@asterite asterite enabled auto-merge July 3, 2025 16:07
@asterite asterite disabled auto-merge July 3, 2025 16:07
@asterite asterite enabled auto-merge July 3, 2025 16:34
Copy link
Collaborator

@asterite asterite left a comment

Choose a reason for hiding this comment

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

Looks great!

@asterite asterite added this pull request to the merge queue Jul 3, 2025
@asterite asterite removed this pull request from the merge queue due to a manual request Jul 3, 2025
Copy link
Member

@TomAFrench TomAFrench left a comment

Choose a reason for hiding this comment

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

LGTM

@asterite asterite added this pull request to the merge queue Jul 3, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jul 3, 2025
@asterite asterite added this pull request to the merge queue Jul 3, 2025
Merged via the queue into master with commit e64ae7d Jul 3, 2025
152 of 153 checks passed
@asterite asterite deleted the jf/assoc-consts branch July 3, 2025 17:49
github-merge-queue bot pushed a commit to AztecProtocol/aztec-packages that referenced this pull request Jul 4, 2025
Automated pull of nightly from the
[noir](https://github.com/noir-lang/noir) programming language, a
dependency of Aztec.
BEGIN_COMMIT_OVERRIDE
chore: remove redundant associated constant lookup
(noir-lang/noir#9114)
chore: test that associated function and constant with the same name
collide (noir-lang/noir#9112)
feat: Allow TraitAsType syntax to refer to associated constants in
expressions (noir-lang/noir#9041)
chore: clippy (noir-lang/noir#9101)
chore(fuzz): Recursively generate lvalue for multi dimensional arrays
and nested tuples (noir-lang/noir#9086)
fix!: remove `hash_to_field` from stdlib
(noir-lang/noir#9098)
chore(docs): Brillig gen (noir-lang/noir#9085)
chore(fuzz): Test AST print-and-parse roundtrip
(noir-lang/noir#9083)
fix(ssa): Do not fail for static assertions in a map over empty dynamic
slices (noir-lang/noir#9060)
chore: merge `RangeCheckFailed` and `RangeCheckFailedWithMessage`
(noir-lang/noir#9093)
chore(fuzz): Capture printed output in `comptime_vs_brillig_direct`
(noir-lang/noir#9090)
chore(debug): Add trait constraint to string helper
(noir-lang/noir#9082)
chore: bump some deps (noir-lang/noir#9076)
END_COMMIT_OVERRIDE

---------

Co-authored-by: AztecBot <tech@aztecprotocol.com>
Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com>
danielntmd pushed a commit to danielntmd/aztec-packages that referenced this pull request Jul 16, 2025
Automated pull of nightly from the
[noir](https://github.com/noir-lang/noir) programming language, a
dependency of Aztec.
BEGIN_COMMIT_OVERRIDE
chore: remove redundant associated constant lookup
(noir-lang/noir#9114)
chore: test that associated function and constant with the same name
collide (noir-lang/noir#9112)
feat: Allow TraitAsType syntax to refer to associated constants in
expressions (noir-lang/noir#9041)
chore: clippy (noir-lang/noir#9101)
chore(fuzz): Recursively generate lvalue for multi dimensional arrays
and nested tuples (noir-lang/noir#9086)
fix!: remove `hash_to_field` from stdlib
(noir-lang/noir#9098)
chore(docs): Brillig gen (noir-lang/noir#9085)
chore(fuzz): Test AST print-and-parse roundtrip
(noir-lang/noir#9083)
fix(ssa): Do not fail for static assertions in a map over empty dynamic
slices (noir-lang/noir#9060)
chore: merge `RangeCheckFailed` and `RangeCheckFailedWithMessage`
(noir-lang/noir#9093)
chore(fuzz): Capture printed output in `comptime_vs_brillig_direct`
(noir-lang/noir#9090)
chore(debug): Add trait constraint to string helper
(noir-lang/noir#9082)
chore: bump some deps (noir-lang/noir#9076)
END_COMMIT_OVERRIDE

---------

Co-authored-by: AztecBot <tech@aztecprotocol.com>
Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com>
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.

Can't access associated constants via AsTraitPath in expressions

3 participants