Skip to content

chore(fuzz): Test AST print-and-parse roundtrip#9083

Merged
aakoshh merged 16 commits intomasterfrom
af/9058-fuzz-ast-roundtrip
Jul 2, 2025
Merged

chore(fuzz): Test AST print-and-parse roundtrip#9083
aakoshh merged 16 commits intomasterfrom
af/9058-fuzz-ast-roundtrip

Conversation

@aakoshh
Copy link
Contributor

@aakoshh aakoshh commented Jul 2, 2025

Description

Problem*

Resolves #9058

Summary*

Adds a new prop test to the AST fuzzer to ensure that if we render the monomorphized AST created by the fuzzer and parse it back, it renders the same way a second time, indicating that there are no significant differences between the fuzzer and the compiler, no hidden assumptions that the generator does not respect.

cargo test -p noir_ast_fuzzer --test mono

Additional Context

The can be subtle differences, for example rendering Unary { op: Minus, rhs: Literal(1) } could be parsed back as Literal(-1). These don't cause a test failure, because we only compare the printed Noir source, and I made some changes to the printer to ensure they appear identical. Other instances that cause no harm such as --1 being parsed as 1 are handled in the test itself.

The test did highlight some actual semantic differences, such as a misunderstanding in the return_type of a unary reference, which resulted in an extra &mut in the printed output. Similarly it uncovered that the separation of array indexes into a temporary variable had a different definition of "side effect" than the fuzzer.

After investigation there remains a discrepancy in how these array indexes are handled for multi-dimensional arrays: the compiler creates temporary variables for all dimensions in a single block, ie. a[0 + 1][2 - 1] = 3; is turned into { let i_1 = 0 - 1; let i_2 = 2 - 1; a[i][j] = 3;. The generator only considers a single index. This doesn't cause an issue at the moment because the generator doesn't assign to multiple dimensions, only the top one. I'll create a follow-up PR to add multi-dimensional assignments.

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.

@aakoshh aakoshh changed the title chore(fuzz): Test AST print and parse roundtrip chore(fuzz): Test AST print-and-parse roundtrip Jul 2, 2025
@aakoshh aakoshh requested a review from a team July 2, 2025 08:42
@aakoshh aakoshh requested a review from rkarabut July 2, 2025 09:08
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: 8450e51 Previous: 6a68ca1 Ratio
test_report_noir-lang_noir_bigcurve_ 314 s 240 s 1.31

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

CC: @TomAFrench

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!

@aakoshh aakoshh added this pull request to the merge queue Jul 2, 2025
Merged via the queue into master with commit d356b92 Jul 2, 2025
118 checks passed
@aakoshh aakoshh deleted the af/9058-fuzz-ast-roundtrip branch July 2, 2025 19:33
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.

Fuzz test the AST generation and parse roundtrip

2 participants