fix(frontend)!: Preserve int type when quoting tokens #10330
fix(frontend)!: Preserve int type when quoting tokens #10330
Conversation
|
Does this run into the same issues found in #8369 ? |
We can make a case like in #8369: fn main() {
let got: u8 = comptime {
let original: u8 = 10;
unquote!(quote { $original })
};
assert_eq(got, 10);
}
comptime fn unquote(code: Quoted) -> Quoted {
code
}On nightly this fails with It looks like #10326 can cause similar issues to #8369, but the cause is not exactly the same. In #8369 we were not appropriately binding the return type from a comptime context and thus ultimately unifying two different types (such as i32 and Field). The fact that we bind the polymorphic integer to a Field in #8369 feels like a separate issue. In this case, we have explicitly specified a type and are losing type information just when quoting values within the same comptime context. As per the linked issue we then get a type mismatch error (which is expected as we have dropped the original u8 type for a Field). |
There was a problem hiding this comment.
⚠️ 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: b3e21ec | Previous: fe0bfa0 | Ratio |
|---|---|---|---|
test_report_zkpassport_noir_rsa_ |
2 s |
0 s |
+∞ |
This comment was automatically generated by workflow using github-action-benchmark.
CC: @TomAFrench
|
Looks like we're getting some errors related to attribute argument types and numeric generics. We're getting a lot of errors in noir-bignum for the type supplied to a numeric generic https://github.com/noir-lang/noir/actions/runs/18953822445/job/54125951530?pr=10330. Will need to investigate deeper to figure out what is going on. |
|
Right, I think Jake tried it in the past when suffixes were introduced: #8970 (comment) |
|
external repos should be compiling now. The issue was the kind checking for integer literals w/ type suffixes used in a type position was wrong. We were using To fix this I introduced a new helper, added some notes on both functions on when to use them, and added a regression. |
|
From some quick tests it looks like aztec-nr and friends were a bit lax in making use of this unintended feature of integers changing types. Lots of errors like: So there are some updates required to those repos - I think this PR is correct, just breaking. |
|
Ah, one more thing. Including the integer type suffix messes up using integers as tuple field accesses currently: Edit: Fixed by just allowing integer type suffixes in that position. |
There was a problem hiding this comment.
⚠️ Performance Alert ⚠️
Possible performance regression was detected for benchmark 'Execution Time'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.20.
| Benchmark suite | Current: 5d09254 | Previous: 60bfcf2 | Ratio |
|---|---|---|---|
rollup-block-root-single-tx |
0.003 s |
0.002 s |
1.50 |
sha512-100-bytes |
0.095 s |
0.072 s |
1.32 |
This comment was automatically generated by workflow using github-action-benchmark.
CC: @TomAFrench
) After noir-lang/noir#10330, noir will start enforcing the types of unquoted integers remain the same type. Before, when you unquoted an integer such as `let n: u32 = 4;` e.g. in `quote { let x = $n; }` the unquoted `n` would be a polymorphic integer literal of any type. With the above PR, it unquotes instead to `let x = 4u32;` - the type is preserved. We consider it a bug to rely on the previous behavior, and there were 3 instances of it in aztec-nr so this is a patch for those cases.
) After noir-lang/noir#10330, noir will start enforcing the types of unquoted integers remain the same type. Before, when you unquoted an integer such as `let n: u32 = 4;` e.g. in `quote { let x = $n; }` the unquoted `n` would be a polymorphic integer literal of any type. With the above PR, it unquotes instead to `let x = 4u32;` - the type is preserved. We consider it a bug to rely on the previous behavior, and there were 3 instances of it in aztec-nr so this is a patch for those cases.
) After noir-lang/noir#10330, noir will start enforcing the types of unquoted integers remain the same type. Before, when you unquoted an integer such as `let n: u32 = 4;` e.g. in `quote { let x = $n; }` the unquoted `n` would be a polymorphic integer literal of any type. With the above PR, it unquotes instead to `let x = 4u32;` - the type is preserved. We consider it a bug to rely on the previous behavior, and there were 3 instances of it in aztec-nr so this is a patch for those cases.
) After noir-lang/noir#10330, noir will start enforcing the types of unquoted integers remain the same type. Before, when you unquoted an integer such as `let n: u32 = 4;` e.g. in `quote { let x = $n; }` the unquoted `n` would be a polymorphic integer literal of any type. With the above PR, it unquotes instead to `let x = 4u32;` - the type is preserved. We consider it a bug to rely on the previous behavior, and there were 3 instances of it in aztec-nr so this is a patch for those cases.
|
Looks like we're good here post the external repos commit. Reviewed the changes made since the initial review and all looks good. Going to merge. |
Automated pull of nightly from the [noir](https://github.com/noir-lang/noir) programming language, a dependency of Aztec. BEGIN_COMMIT_OVERRIDE fix(frontend)!: Preserve int type when quoting tokens (noir-lang/noir#10330) fix: check overflow for Pedersen grumpkin scalars (noir-lang/noir#10462) chore(frontend): Various tests in elaborator expressions submodule and minor refactors (noir-lang/noir#10475) chore: bump external pinned commits (noir-lang/noir#10477) fix: disallow keywords in attributes (noir-lang/noir#10473) chore: refactor codegen_control_flow (noir-lang/noir#10320) fix: builtin with body now errors instead of crashing (noir-lang/noir#10474) fix: handle ambiguous trait methods in assumed traits (noir-lang/noir#10468) fix: force_substitute bindings during monomorphization for associated constants (noir-lang/noir#10467) fix(brillig): Skip decrementing ref-count in array/vector copy and other refactors (noir-lang/noir#10335) fix(ssa): Cast to `u64` when inserting OOB checks in DIE (noir-lang/noir#10463) fix: disallow comptime-only types in non-comptime globals (noir-lang/noir#10458) chore(fuzzing): fix default artifact for brillig target (noir-lang/noir#10465) END_COMMIT_OVERRIDE
Automated pull of nightly from the [noir](https://github.com/noir-lang/noir) programming language, a dependency of Aztec. BEGIN_COMMIT_OVERRIDE fix(frontend)!: Preserve int type when quoting tokens (noir-lang/noir#10330) fix: check overflow for Pedersen grumpkin scalars (noir-lang/noir#10462) chore(frontend): Various tests in elaborator expressions submodule and minor refactors (noir-lang/noir#10475) chore: bump external pinned commits (noir-lang/noir#10477) fix: disallow keywords in attributes (noir-lang/noir#10473) chore: refactor codegen_control_flow (noir-lang/noir#10320) fix: builtin with body now errors instead of crashing (noir-lang/noir#10474) fix: handle ambiguous trait methods in assumed traits (noir-lang/noir#10468) fix: force_substitute bindings during monomorphization for associated constants (noir-lang/noir#10467) fix(brillig): Skip decrementing ref-count in array/vector copy and other refactors (noir-lang/noir#10335) fix(ssa): Cast to `u64` when inserting OOB checks in DIE (noir-lang/noir#10463) fix: disallow comptime-only types in non-comptime globals (noir-lang/noir#10458) chore(fuzzing): fix default artifact for brillig target (noir-lang/noir#10465) END_COMMIT_OVERRIDE
Automated pull of nightly from the [noir](https://github.com/noir-lang/noir) programming language, a dependency of Aztec. BEGIN_COMMIT_OVERRIDE fix(frontend)!: Preserve int type when quoting tokens (noir-lang/noir#10330) fix: check overflow for Pedersen grumpkin scalars (noir-lang/noir#10462) chore(frontend): Various tests in elaborator expressions submodule and minor refactors (noir-lang/noir#10475) chore: bump external pinned commits (noir-lang/noir#10477) fix: disallow keywords in attributes (noir-lang/noir#10473) chore: refactor codegen_control_flow (noir-lang/noir#10320) fix: builtin with body now errors instead of crashing (noir-lang/noir#10474) fix: handle ambiguous trait methods in assumed traits (noir-lang/noir#10468) fix: force_substitute bindings during monomorphization for associated constants (noir-lang/noir#10467) fix(brillig): Skip decrementing ref-count in array/vector copy and other refactors (noir-lang/noir#10335) fix(ssa): Cast to `u64` when inserting OOB checks in DIE (noir-lang/noir#10463) fix: disallow comptime-only types in non-comptime globals (noir-lang/noir#10458) chore(fuzzing): fix default artifact for brillig target (noir-lang/noir#10465) END_COMMIT_OVERRIDE
Description
Problem*
Resolves #10326
Summary*
I just updated the
Value::into_tokensmethod to keep the appropriate suffix type when converting aValueintoTokens. Thus the tokens in theQuotedvalue now maintain their integer type. When we then look to unquote those tokens they will be parsed with their appropriate integer type.Working on this issue revealed #10328
Additional Context
Documentation*
Check one:
PR Checklist*
cargo fmton default settings.