Skip to content

Commit

Permalink
Swap newline and ident T args in print oracle
Browse files Browse the repository at this point in the history
  • Loading branch information
grasshopper47 committed Dec 4, 2023
1 parent 3eecd07 commit e22cbc5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
5 changes: 3 additions & 2 deletions compiler/noirc_frontend/src/monomorphization/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -891,8 +891,9 @@ impl<'interner> Monomorphizer<'interner> {
if let Definition::Oracle(name) = &ident.definition {
if name.as_str() == "print" {
// Oracle calls are required to be wrapped in an unconstrained function
// Thus, the only argument to the `println` oracle is expected to always be an ident
self.append_printable_type_info(&hir_arguments[0], &mut arguments);
// The first argument to the `print` oracle is a bool, indicating a newline to be inserted at the end of the input
// The second argument is expected to always be an ident
self.append_printable_type_info(&hir_arguments[1], &mut arguments);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions noir_stdlib/src/lib.nr
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ mod test;
// Oracle calls are required to be wrapped in an unconstrained function
// Thus, the only argument to the `println` oracle is expected to always be an ident
#[oracle(print)]
unconstrained fn print_oracle<T>(_input: T, _with_newline: bool) {}
unconstrained fn print_oracle<T>(_with_newline: bool, _input: T) {}

unconstrained pub fn print<T>(input: T) {
print_oracle(input, false);
print_oracle(false, input);
}

unconstrained pub fn println<T>(input: T) {
print_oracle(input, true);
print_oracle(true, input);
}

#[foreign(recursive_aggregation)]
Expand Down
10 changes: 2 additions & 8 deletions tooling/nargo/src/ops/foreign_calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,8 @@ impl DefaultForeignCallExecutor {
}

fn execute_print(foreign_call_inputs: &[ForeignCallParam]) -> Result<(), ForeignCallError> {
let display_values: PrintableValueDisplay = foreign_call_inputs.try_into()?;

// The skip_newline parameter is the third to last, behind the format string.
// Since the type to print is generic, it may take up more than 1 argument
// so we need to count back from the end here instead of starting from the beginning.
let skip_newline = &foreign_call_inputs[foreign_call_inputs.len() - 3];
let skip_newline = skip_newline.unwrap_value().is_zero();

let skip_newline = foreign_call_inputs[0].unwrap_value().is_zero();
let display_values: PrintableValueDisplay = foreign_call_inputs.split_first().ok_or(ForeignCallError::MissingForeignCallInputs)?.1.try_into()?;
print!("{display_values}{}", if skip_newline { "" } else { "\n" });
Ok(())
}
Expand Down

0 comments on commit e22cbc5

Please sign in to comment.