Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Remove unused Intrinsic::Println #2358

Merged
merged 5 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 0 additions & 2 deletions crates/noirc_evaluator/src/ssa/acir_gen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -993,8 +993,6 @@ impl Context {

self.acir_context.bit_decompose(endian, field, bit_size, result_type)
}
// TODO(#2115): Remove the println intrinsic as the oracle println is now used instead
Intrinsic::Println => Ok(Vec::new()),
Intrinsic::Sort => {
let inputs = vecmap(arguments, |arg| self.convert_value(*arg, dfg));
// We flatten the inputs and retrieve the bit_size of the elements
Expand Down
5 changes: 1 addition & 4 deletions crates/noirc_evaluator/src/ssa/ir/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ pub(crate) enum Intrinsic {
SliceInsert,
SliceRemove,
StrAsBytes,
Println,
ToBits(Endian),
ToRadix(Endian),
BlackBox(BlackBoxFunc),
Expand All @@ -50,7 +49,6 @@ pub(crate) enum Intrinsic {
impl std::fmt::Display for Intrinsic {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Intrinsic::Println => write!(f, "println"),
Intrinsic::Sort => write!(f, "arraysort"),
Intrinsic::ArrayLen => write!(f, "array_len"),
Intrinsic::AssertConstant => write!(f, "assert_constant"),
Expand All @@ -76,7 +74,7 @@ impl Intrinsic {
/// If there are no side effects then the `Intrinsic` can be removed if the result is unused.
pub(crate) fn has_side_effects(&self) -> bool {
match self {
Intrinsic::Println | Intrinsic::AssertConstant => true,
Intrinsic::AssertConstant => true,

Intrinsic::Sort
| Intrinsic::ArrayLen
Expand All @@ -99,7 +97,6 @@ impl Intrinsic {
/// If there is no such intrinsic by that name, None is returned.
pub(crate) fn lookup(name: &str) -> Option<Intrinsic> {
match name {
"println" => Some(Intrinsic::Println),
"arraysort" => Some(Intrinsic::Sort),
"array_len" => Some(Intrinsic::ArrayLen),
"assert_constant" => Some(Intrinsic::AssertConstant),
Expand Down
1 change: 0 additions & 1 deletion crates/noirc_evaluator/src/ssa/ir/instruction/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ pub(super) fn simplify_call(
}
Intrinsic::BlackBox(bb_func) => simplify_black_box_func(bb_func, arguments, dfg),
Intrinsic::Sort => simplify_sort(dfg, arguments),
Intrinsic::Println => SimplifyResult::None,
}
}

Expand Down
12 changes: 6 additions & 6 deletions crates/noirc_evaluator/src/ssa/opt/die.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ mod test {
use crate::ssa::{
ir::{
function::RuntimeType,
instruction::{BinaryOp, Intrinsic},
instruction::{BinaryOp, Endian::Little, Intrinsic},
map::Id,
types::Type,
},
Expand All @@ -155,7 +155,7 @@ mod test {
// v9 = add v7, Field 2
// v10 = add v7, Field 3
// v11 = add v10, v10
// call println(v8)
// call to_le_bits(v8)
// return v9
// }
let main_id = Id::test_new(0);
Expand Down Expand Up @@ -187,8 +187,8 @@ mod test {
let v10 = builder.insert_binary(v7, BinaryOp::Add, three);
let _v11 = builder.insert_binary(v10, BinaryOp::Add, v10);

let println_id = builder.import_intrinsic_id(Intrinsic::Println);
builder.insert_call(println_id, vec![v8], vec![]);
let to_le_bits_id = builder.import_intrinsic_id(Intrinsic::ToBits(Little));
builder.insert_call(to_le_bits_id, vec![v8], vec![]);
builder.terminate_with_return(vec![v9]);

let ssa = builder.finish();
Expand All @@ -210,13 +210,13 @@ mod test {
// v7 = load v6
// v8 = add v7, Field 1
// v9 = add v7, Field 2
// call println(v8)
// call to_le_bits(v8)
// return v9
// }
let ssa = ssa.dead_instruction_elimination();
let main = ssa.main();

assert_eq!(main.dfg[main.entry_block()].instructions().len(), 1);
assert_eq!(main.dfg[b1].instructions().len(), 6);
assert_eq!(main.dfg[b1].instructions().len(), 4);
jfecher marked this conversation as resolved.
Show resolved Hide resolved
}
}
54 changes: 27 additions & 27 deletions crates/noirc_evaluator/src/ssa/opt/flatten_cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1040,54 +1040,54 @@ mod test {
builder.insert_store(r1, value);
};

let println = builder.import_intrinsic_id(Intrinsic::Println);
let sort = builder.import_intrinsic_id(Intrinsic::Sort);
jfecher marked this conversation as resolved.
Show resolved Hide resolved

let call_println = |builder: &mut FunctionBuilder, block: u128| {
let call_sort = |builder: &mut FunctionBuilder, block: u128| {
let block = builder.field_constant(block);
let load = builder.insert_load(r1, Type::field());
builder.insert_call(println, vec![block, load], Vec::new());
builder.insert_call(sort, vec![block, load], Vec::new());
};

let switch_store_and_print = |builder: &mut FunctionBuilder, block, block_number: u128| {
let switch_store_and_sort = |builder: &mut FunctionBuilder, block, block_number: u128| {
builder.switch_to_block(block);
store_value(builder, block_number);
call_println(builder, block_number);
call_sort(builder, block_number);
};

let switch_and_print = |builder: &mut FunctionBuilder, block, block_number: u128| {
let switch_and_sort = |builder: &mut FunctionBuilder, block, block_number: u128| {
builder.switch_to_block(block);
call_println(builder, block_number);
call_sort(builder, block_number);
};

store_value(&mut builder, 0);
call_println(&mut builder, 0);
call_sort(&mut builder, 0);
builder.terminate_with_jmp(b1, vec![]);

switch_store_and_print(&mut builder, b1, 1);
switch_store_and_sort(&mut builder, b1, 1);
builder.terminate_with_jmpif(c1, b2, b3);

switch_store_and_print(&mut builder, b2, 2);
switch_store_and_sort(&mut builder, b2, 2);
builder.terminate_with_jmp(b4, vec![]);

switch_store_and_print(&mut builder, b3, 3);
switch_store_and_sort(&mut builder, b3, 3);
builder.terminate_with_jmp(b8, vec![]);

switch_and_print(&mut builder, b4, 4);
switch_and_sort(&mut builder, b4, 4);
builder.terminate_with_jmpif(c4, b5, b6);

switch_store_and_print(&mut builder, b5, 5);
switch_store_and_sort(&mut builder, b5, 5);
builder.terminate_with_jmp(b7, vec![]);

switch_store_and_print(&mut builder, b6, 6);
switch_store_and_sort(&mut builder, b6, 6);
builder.terminate_with_jmp(b7, vec![]);

switch_and_print(&mut builder, b7, 7);
switch_and_sort(&mut builder, b7, 7);
builder.terminate_with_jmp(b9, vec![]);

switch_and_print(&mut builder, b8, 8);
switch_and_sort(&mut builder, b8, 8);
builder.terminate_with_jmp(b9, vec![]);

switch_and_print(&mut builder, b9, 9);
switch_and_sort(&mut builder, b9, 9);
let load = builder.insert_load(r1, Type::field());
builder.terminate_with_return(vec![load]);

Expand All @@ -1097,39 +1097,39 @@ mod test {
//
// fn main f0 {
// b0(v0: u1, v1: u1):
// call println(Field 0, Field 0)
// call println(Field 1, Field 1)
// call sort(Field 0, Field 0)
// call sort(Field 1, Field 1)
// enable_side_effects v0
// call println(Field 2, Field 2)
// call println(Field 4, Field 2)
// call sort(Field 2, Field 2)
// call sort(Field 4, Field 2)
// v29 = and v0, v1
// enable_side_effects v29
// call println(Field 5, Field 5)
// call sort(Field 5, Field 5)
// v32 = not v1
// v33 = and v0, v32
// enable_side_effects v33
// call println(Field 6, Field 6)
// call sort(Field 6, Field 6)
// enable_side_effects v0
// v36 = mul v1, Field 5
// v37 = mul v32, Field 2
// v38 = add v36, v37
// v39 = mul v1, Field 5
// v40 = mul v32, Field 6
// v41 = add v39, v40
// call println(Field 7, v42)
// call sort(Field 7, v42)
// v43 = not v0
// enable_side_effects v43
// store Field 3 at v2
// call println(Field 3, Field 3)
// call println(Field 8, Field 3)
// call sort(Field 3, Field 3)
// call sort(Field 8, Field 3)
// enable_side_effects Field 1
// v47 = mul v0, v41
// v48 = mul v43, Field 1
// v49 = add v47, v48
// v50 = mul v0, v44
// v51 = mul v43, Field 3
// v52 = add v50, v51
// call println(Field 9, v53)
// call sort(Field 9, v53)
// return v54
// }

Expand Down
10 changes: 5 additions & 5 deletions crates/noirc_evaluator/src/ssa/opt/inlining.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
self.finish(ssa)
}

/// Inlines a function into the current function and returns the translated return values

Check warning on line 134 in crates/noirc_evaluator/src/ssa/opt/inlining.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (Inlines)
/// of the inlined function.
fn inline_function(
&mut self,
Expand Down Expand Up @@ -516,7 +516,7 @@
ir::{
basic_block::BasicBlockId,
function::RuntimeType,
instruction::{BinaryOp, Intrinsic, TerminatorInstruction},
instruction::{BinaryOp, Endian::Little, Intrinsic, TerminatorInstruction},
map::Id,
types::Type,
},
Expand Down Expand Up @@ -721,7 +721,7 @@
// fn main f0 {
// b0(v0: u1):
// v2 = call f1(v0)
// call println(v2)
// call to_le_bits(v2)
// return
// }
// fn inner1 f1 {
Expand All @@ -746,8 +746,8 @@
let inner1_id = Id::test_new(1);
let inner1 = builder.import_function(inner1_id);
let main_v2 = builder.insert_call(inner1, vec![main_cond], vec![Type::field()])[0];
let println = builder.import_intrinsic_id(Intrinsic::Println);
builder.insert_call(println, vec![main_v2], vec![]);
let to_le_bits = builder.import_intrinsic_id(Intrinsic::ToBits(Little));
builder.insert_call(to_le_bits, vec![main_v2], vec![]);
builder.terminate_with_return(vec![]);

builder.new_function("inner1".into(), inner1_id);
Expand Down Expand Up @@ -781,7 +781,7 @@
// b1():
// jmp b3(Field 1)
// b3(v3: Field):
// call println(v3)
// call to_le_bits(v3)
// return
// b2():
// jmp b3(Field 2)
Expand Down
6 changes: 4 additions & 2 deletions crates/noirc_evaluator/src/ssa/opt/mem2reg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@
}

// If no loads or stores have been found in the current block, check the block's predecessors.
// Only check blocks with one predecessor as otherwise a constant value could be propogated

Check warning on line 284 in crates/noirc_evaluator/src/ssa/opt/mem2reg.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (propogated)
// through successor blocks with multiple branches that rely on other simplification passes
// such as loop unrolling or flattening of the CFG.
fn block_has_predecessor(
Expand Down Expand Up @@ -388,7 +388,9 @@
basic_block::BasicBlockId,
dfg::DataFlowGraph,
function::RuntimeType,
instruction::{BinaryOp, Instruction, Intrinsic, TerminatorInstruction},
instruction::{
BinaryOp, Endian::Little, Instruction, Intrinsic, TerminatorInstruction,
},
map::Id,
types::Type,
},
Expand Down Expand Up @@ -455,7 +457,7 @@
let one = builder.field_constant(FieldElement::one());
builder.insert_store(v0, one);
let v1 = builder.insert_load(v0, Type::field());
let f0 = builder.import_intrinsic_id(Intrinsic::Println);
let f0 = builder.import_intrinsic_id(Intrinsic::ToBits(Little));
jfecher marked this conversation as resolved.
Show resolved Hide resolved
builder.insert_call(f0, vec![v0], vec![]);
builder.terminate_with_return(vec![v1]);

Expand Down