Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/noirc_frontend/src/hir/comptime/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ impl<'local, 'interner> Interpreter<'local, 'interner> {
) -> IResult<Value> {
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
31 changes: 28 additions & 3 deletions tooling/ast_fuzzer/src/compare/comptime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(with_newline: bool, input: T) {{}}

unconstrained fn print_unconstrained<T>(with_newline: bool, input: T) {{
print_oracle(with_newline, input);
}}

pub fn println<T>(input: T) {{
unsafe {{
print_unconstrained(true, input);
}}
}}

pub fn print<T>(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 {
Expand Down
2 changes: 2 additions & 0 deletions tooling/ast_fuzzer/src/program/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -607,6 +608,7 @@ impl std::fmt::Display for DisplayAstAsNoirComptime<'_> {
printer.print_function(function, f, FunctionPrintOptions::default())?;
}
}

Ok(())
}
}
Loading