diff --git a/compiler/noirc_frontend/src/hir/comptime/interpreter.rs b/compiler/noirc_frontend/src/hir/comptime/interpreter.rs index 1eaf9834fe2..51ae66d7252 100644 --- a/compiler/noirc_frontend/src/hir/comptime/interpreter.rs +++ b/compiler/noirc_frontend/src/hir/comptime/interpreter.rs @@ -249,7 +249,7 @@ impl<'local, 'interner> Interpreter<'local, 'interner> { ) -> IResult { let attributes = self.elaborator.interner.function_attributes(&function); let func_attrs = &attributes.function() - .expect("all builtin functions must contain a function attribute which contains the opcode which it links to").kind; + .expect("all builtin functions must contain a function attribute which contains the opcode which it links to").kind; if let Some(builtin) = func_attrs.builtin() { self.call_builtin(builtin.clone().as_str(), arguments, return_type, location) 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 050e1de9ba3..2f4ede08d30 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 @@ -31,8 +31,6 @@ pub fn fuzz(u: &mut Unstructured) -> eyre::Result<()> { avoid_overflow: true, avoid_err_by_zero: true, avoid_constrain: true, - // At the moment prints aren't recognized by elaborator - avoid_print: true, // Use lower limits because of the interpreter, to avoid stack overflow max_loop_size: 5, max_recursive_calls: 5, diff --git a/tooling/ast_fuzzer/src/compare/comptime.rs b/tooling/ast_fuzzer/src/compare/comptime.rs index 9ddad63ebcb..a6b27bbf36c 100644 --- a/tooling/ast_fuzzer/src/compare/comptime.rs +++ b/tooling/ast_fuzzer/src/compare/comptime.rs @@ -93,12 +93,37 @@ impl CompareComptime { let initial_witness = self.input_witness()?; let (res2, _) = Self::exec_bytecode(&self.ssa.artifact.program, initial_witness.clone()); - // TODO(#8973): The print output is currently not captured by the elaborator, so we have to ignore it. + // Include the print part of stdlib for the elaborator to be able to use the print oracle + let import_print = r#" + #[oracle(print)] + unconstrained fn print_oracle(with_newline: bool, input: T) {{}} + + unconstrained fn print_unconstrained(with_newline: bool, input: T) {{ + print_oracle(with_newline, input); + }} + + pub fn println(input: T) {{ + unsafe {{ + print_unconstrained(true, input); + }} + }} + + pub fn print(input: T) {{ + unsafe {{ + print_unconstrained(false, input); + }} + }} + "#; + + // Add comptime modifier for main + let source = format!("comptime {}{}", self.source, import_print); + + // TODO(#9054): re-enable print output comparison let empty_print = ""; - // log source code before interpreting + // Log source code before interpreting log::debug!("comptime src:\n{}", self.source); - let comptime_expr = match interpret(&format!("comptime {}", self.source)) { + let comptime_expr = match interpret(source.as_str()) { Ok(expr) => expr, Err(e) => { let assertion_diagnostic = match &e { diff --git a/tooling/ast_fuzzer/src/program/mod.rs b/tooling/ast_fuzzer/src/program/mod.rs index 0c7ea9ace0f..20fe5b949eb 100644 --- a/tooling/ast_fuzzer/src/program/mod.rs +++ b/tooling/ast_fuzzer/src/program/mod.rs @@ -597,6 +597,7 @@ impl std::fmt::Display for DisplayAstAsNoirComptime<'_> { // for example `for i in (5 / 10) as u32 .. 2` is `0..2` or `1..2` depending on whether 5 and 10 // were some number in the AST or `Field` when parsed by the test. printer.show_type_of_int_literal = true; + for function in &self.0.functions { if function.id == Program::main_id() { let mut function = function.clone(); @@ -607,6 +608,7 @@ impl std::fmt::Display for DisplayAstAsNoirComptime<'_> { printer.print_function(function, f, FunctionPrintOptions::default())?; } } + Ok(()) } }