Skip to content

Commit

Permalink
feat: Bring back restriction on printing slices and add one on mutabl…
Browse files Browse the repository at this point in the history
…e refs

Even though the printing support is there, neither of them can be passed from
ACIR into Brillig. So the restriction is for consistency and to be able to
provide a better error message to users.
  • Loading branch information
ggiraldez committed Jan 18, 2024
1 parent 823e833 commit 2732c79
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 20 deletions.
10 changes: 10 additions & 0 deletions compiler/noirc_frontend/src/monomorphization/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,16 @@ impl<'interner> Monomorphizer<'interner> {
}

fn append_printable_type_info_inner(typ: &Type, arguments: &mut Vec<ast::Expression>) {
// Disallow printing slices and mutable references for consistency,
// since they cannot be passed from ACIR into Brillig
if let HirType::Array(size, _) = typ {
if let HirType::NotConstant = **size {
unreachable!("println does not support slices. Convert the slice to an array before passing it to println");
}
} else if matches!(typ, HirType::MutableReference(_)) {
unreachable!("println does not support mutable references.");
}

let printable_type: PrintableType = typ.into();
let abi_as_string = serde_json::to_string(&printable_type)
.expect("ICE: expected PrintableType to serialize");
Expand Down
20 changes: 0 additions & 20 deletions test_programs/execution_success/debug_logs/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ fn main(x: Field, y: pub Field) {
let closured_lambda = |x| x + one;
std::println(f"closured_lambda: {closured_lambda}, sentinel: {sentinel}");
std::println(closured_lambda);

types_printable_in_brillig_only();
}

fn string_identity(string: fmtstr<14, (Field, Field)>) -> fmtstr<14, (Field, Field)> {
Expand Down Expand Up @@ -101,21 +99,3 @@ fn regression_2906() {
dep::std::println(f"array_five_vals: {array_five_vals}, label_five_vals: {label_five_vals}");
}

unconstrained fn types_printable_in_brillig_only() {
let mut a_tuple = (1,2,3);
let mut tuple_mut_ref = &mut a_tuple;
let sentinel: u32 = 8888;
std::println(f"tuple_mut_ref: {tuple_mut_ref}, sentinel: {sentinel}");
std::println(tuple_mut_ref);

let mut a_vector: Vec<Field> = Vec::new();
a_vector.push(10);
a_vector.push(20);
a_vector.push(30);
std::println(f"a_vector: {a_vector}, sentinel: {sentinel}");
std::println(a_vector);

let vec_slice = a_vector.slice;
std::println(f"vec_slice: {vec_slice}, sentinel: {sentinel}");
std::println(vec_slice);
}

0 comments on commit 2732c79

Please sign in to comment.