diff --git a/compiler/noirc_frontend/src/monomorphization/printer.rs b/compiler/noirc_frontend/src/monomorphization/printer.rs index edae2dda56a..3d8ac93c55d 100644 --- a/compiler/noirc_frontend/src/monomorphization/printer.rs +++ b/compiler/noirc_frontend/src/monomorphization/printer.rs @@ -259,7 +259,7 @@ impl AstPrinter { write!(f, "]") } super::ast::Literal::Integer(x, typ, _) => { - if self.show_type_of_int_literal { + if self.show_type_of_int_literal && *typ != Type::Field { write!(f, "{x}_{typ}") } else { x.fmt(f) diff --git a/tooling/ast_fuzzer/fuzz/src/targets/acir_vs_brillig.rs b/tooling/ast_fuzzer/fuzz/src/targets/acir_vs_brillig.rs index aabfa46445a..be9d5ca8fdf 100644 --- a/tooling/ast_fuzzer/fuzz/src/targets/acir_vs_brillig.rs +++ b/tooling/ast_fuzzer/fuzz/src/targets/acir_vs_brillig.rs @@ -13,7 +13,6 @@ pub fn fuzz(u: &mut Unstructured) -> eyre::Result<()> { // Overflows can be triggered easily, so in half the cases we avoid them, // to make sure they don't mask other errors. avoid_overflow: u.arbitrary()?, - avoid_large_int_literals: true, ..Default::default() }; diff --git a/tooling/ast_fuzzer/fuzz/src/targets/comptime_vs_brillig_direct.rs b/tooling/ast_fuzzer/fuzz/src/targets/comptime_vs_brillig_direct.rs index f2b77bd0970..309501cf545 100644 --- a/tooling/ast_fuzzer/fuzz/src/targets/comptime_vs_brillig_direct.rs +++ b/tooling/ast_fuzzer/fuzz/src/targets/comptime_vs_brillig_direct.rs @@ -16,16 +16,14 @@ use noir_ast_fuzzer::rewrite::change_all_functions_into_unconstrained; pub fn fuzz(u: &mut Unstructured) -> eyre::Result<()> { let config = Config { - // Avoid using large integers in for loops that the frontend would reject. - avoid_large_int_literals: true, - // Also avoid negative integers, because the frontend rejects them for loops. - avoid_negative_int_literals: true, // Avoid break/continue avoid_loop_control: true, // Has to only use expressions valid in comptime comptime_friendly: true, // Force brillig, to generate loops that the interpreter can do but ACIR cannot. force_brillig: true, + // Allow overflows half the time. + avoid_overflow: u.arbitrary()?, // Slices need some parts of the stdlib that we can't just append to the source // the way it is currently done to support prints, because they are low level extensions. avoid_slices: true, diff --git a/tooling/ast_fuzzer/fuzz/src/targets/comptime_vs_brillig_nargo.rs b/tooling/ast_fuzzer/fuzz/src/targets/comptime_vs_brillig_nargo.rs index f631c0b0f46..85e45cb7634 100644 --- a/tooling/ast_fuzzer/fuzz/src/targets/comptime_vs_brillig_nargo.rs +++ b/tooling/ast_fuzzer/fuzz/src/targets/comptime_vs_brillig_nargo.rs @@ -18,10 +18,6 @@ pub fn fuzz(u: &mut Unstructured) -> eyre::Result<()> { let config = Config { // It's easy to overflow. avoid_overflow: u.arbitrary()?, - // Avoid using large integers in for loops that the frontend would reject. - avoid_large_int_literals: true, - // Also avoid negative integers, because the frontend rejects them for loops. - avoid_negative_int_literals: true, // Avoid break/continue avoid_loop_control: true, // Has to only use expressions valid in comptime diff --git a/tooling/ast_fuzzer/fuzz/src/targets/min_vs_full.rs b/tooling/ast_fuzzer/fuzz/src/targets/min_vs_full.rs index 364e8a83450..514179614be 100644 --- a/tooling/ast_fuzzer/fuzz/src/targets/min_vs_full.rs +++ b/tooling/ast_fuzzer/fuzz/src/targets/min_vs_full.rs @@ -17,7 +17,6 @@ pub fn fuzz(u: &mut Unstructured) -> eyre::Result<()> { let config = Config { // Overflows are easy to trigger. avoid_overflow: u.arbitrary()?, - avoid_large_int_literals: true, ..Default::default() }; diff --git a/tooling/ast_fuzzer/fuzz/src/targets/orig_vs_morph.rs b/tooling/ast_fuzzer/fuzz/src/targets/orig_vs_morph.rs index 98d32a57eaa..a68e298ac45 100644 --- a/tooling/ast_fuzzer/fuzz/src/targets/orig_vs_morph.rs +++ b/tooling/ast_fuzzer/fuzz/src/targets/orig_vs_morph.rs @@ -18,11 +18,7 @@ use noirc_frontend::monomorphization::ast::{ pub fn fuzz(u: &mut Unstructured) -> eyre::Result<()> { let rules = rules::all(); let max_rewrites = 10; - let config = Config { - avoid_overflow: u.arbitrary()?, - avoid_large_int_literals: true, - ..Default::default() - }; + let config = Config { avoid_overflow: u.arbitrary()?, ..Default::default() }; let inputs = CompareMorph::arb( u, config, diff --git a/tooling/ast_fuzzer/src/program/mod.rs b/tooling/ast_fuzzer/src/program/mod.rs index 61c39de77b4..8d06cc8cee8 100644 --- a/tooling/ast_fuzzer/src/program/mod.rs +++ b/tooling/ast_fuzzer/src/program/mod.rs @@ -582,7 +582,9 @@ impl std::fmt::Display for DisplayAstAsNoir<'_> { printer.show_type_in_let = true; // Most of the time it doesn't affect testing, except the comptime tests where // we parse back the code. For that we use `DisplayAstAsNoirComptime`. - printer.show_type_of_int_literal = false; + // But printing ints with their type makes it much easier to replicate errors in integration tests, + // otherwise the frontend rejects negative or large numbers in many contexts. + printer.show_type_of_int_literal = true; printer.print_program(self.0, f) } } diff --git a/tooling/ast_fuzzer/src/program/tests.rs b/tooling/ast_fuzzer/src/program/tests.rs index 72889d11fe6..bfe00213bd0 100644 --- a/tooling/ast_fuzzer/src/program/tests.rs +++ b/tooling/ast_fuzzer/src/program/tests.rs @@ -203,34 +203,34 @@ fn test_recursion_limit_rewrite() { insta::assert_snapshot!(code, @r" #[inline_always] fn main() -> () { - let mut ctx_limit: u32 = 25; + let mut ctx_limit: u32 = 25_u32; foo((&mut ctx_limit)) } #[inline_always] fn foo(ctx_limit: &mut u32) -> () { - if ((*ctx_limit) == 0) { + if ((*ctx_limit) == 0_u32) { () } else { - *ctx_limit = ((*ctx_limit) - 1); + *ctx_limit = ((*ctx_limit) - 1_u32); unsafe { bar_proxy((*ctx_limit)) } } } #[inline_always] unconstrained fn bar(ctx_limit: &mut u32) -> () { - if ((*ctx_limit) == 0) { + if ((*ctx_limit) == 0_u32) { () } else { - *ctx_limit = ((*ctx_limit) - 1); + *ctx_limit = ((*ctx_limit) - 1_u32); baz(ctx_limit); qux(ctx_limit) } } #[inline_always] unconstrained fn baz(ctx_limit: &mut u32) -> () { - if ((*ctx_limit) == 0) { + if ((*ctx_limit) == 0_u32) { () } else { - *ctx_limit = ((*ctx_limit) - 1); + *ctx_limit = ((*ctx_limit) - 1_u32); baz(ctx_limit) } }