Skip to content

Commit

Permalink
Replace println with print
Browse files Browse the repository at this point in the history
  • Loading branch information
grasshopper47 committed Nov 27, 2023
1 parent 2c4f4e8 commit 2784290
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 24 deletions.
3 changes: 1 addition & 2 deletions compiler/noirc_frontend/src/monomorphization/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -883,8 +883,7 @@ impl<'interner> Monomorphizer<'interner> {

if let ast::Expression::Ident(ident) = original_func.as_ref() {
if let Definition::Oracle(name) = &ident.definition {
let name_str = name.as_str();
if (name_str == "println") | (name_str == "print") {
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);
Expand Down
13 changes: 6 additions & 7 deletions noir_stdlib/src/lib.nr
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,7 @@ mod string;
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(println)]
unconstrained fn println_oracle<T>(_input: T) {}

unconstrained pub fn println<T>(input: T) {
println_oracle(input);
}
// Thus, the only argument to the `print` oracle is expected to always be an ident

#[oracle(print)]
unconstrained fn print_oracle<T>(_input: T) {}
Expand All @@ -36,6 +30,11 @@ unconstrained pub fn print<T>(input: T) {
print_oracle(input);
}

unconstrained pub fn println<T>(input: T) {
print(input);
print("\n");
}

#[foreign(recursive_aggregation)]
pub fn verify_proof<N>(
_verification_key: [Field],
Expand Down
15 changes: 0 additions & 15 deletions tooling/nargo/src/ops/foreign_calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ pub trait ForeignCallExecutor {
/// This enumeration represents the Brillig foreign calls that are natively supported by nargo.
/// After resolution of a foreign call, nargo will restart execution of the ACVM
pub(crate) enum ForeignCall {
Println,
Print,
Sequence,
ReverseSequence,
Expand All @@ -35,7 +34,6 @@ impl std::fmt::Display for ForeignCall {
impl ForeignCall {
pub(crate) fn name(&self) -> &'static str {
match self {
ForeignCall::Println => "println",
ForeignCall::Print => "print",
ForeignCall::Sequence => "get_number_sequence",
ForeignCall::ReverseSequence => "get_reverse_number_sequence",
Expand All @@ -49,7 +47,6 @@ impl ForeignCall {

pub(crate) fn lookup(op_name: &str) -> Option<ForeignCall> {
match op_name {
"println" => Some(ForeignCall::Println),
"print" => Some(ForeignCall::Print),
"get_number_sequence" => Some(ForeignCall::Sequence),
"get_reverse_number_sequence" => Some(ForeignCall::ReverseSequence),
Expand Down Expand Up @@ -130,12 +127,6 @@ impl DefaultForeignCallExecutor {
decode_string_value(&fields)
}

fn execute_println(foreign_call_inputs: &[ForeignCallParam]) -> Result<(), ForeignCallError> {
let display_values: PrintableValueDisplay = foreign_call_inputs.try_into()?;
println!("{display_values}");
Ok(())
}

fn execute_print(foreign_call_inputs: &[ForeignCallParam]) -> Result<(), ForeignCallError> {
let display_values: PrintableValueDisplay = foreign_call_inputs.try_into()?;
print!("{display_values}");
Expand All @@ -150,12 +141,6 @@ impl ForeignCallExecutor for DefaultForeignCallExecutor {
) -> Result<ForeignCallResult, ForeignCallError> {
let foreign_call_name = foreign_call.function.as_str();
match ForeignCall::lookup(foreign_call_name) {
Some(ForeignCall::Println) => {
if self.show_output {
Self::execute_println(&foreign_call.inputs)?;
}
Ok(ForeignCallResult { values: vec![] })
}
Some(ForeignCall::Print) => {
if self.show_output {
Self::execute_print(&foreign_call.inputs)?;
Expand Down

0 comments on commit 2784290

Please sign in to comment.