Skip to content

Commit 6b6263f

Browse files
committed
feat: Deduplicate instructions across blocks (noir-lang/noir#6499)
chore: move tests for arithmetic generics closer to the code (noir-lang/noir#6497) fix(docs): Fix broken links in oracles doc (noir-lang/noir#6488) fix: Treat all parameters as possible aliases of each other (noir-lang/noir#6477) chore: bump rust dependencies (noir-lang/noir#6482) feat: use a full `BlackBoxFunctionSolver` implementation when execution brillig during acirgen (noir-lang/noir#6481) chore(docs): Update How to Oracles (noir-lang/noir#5675) chore: Release Noir(0.38.0) (noir-lang/noir#6422) fix(ssa): Change array_set to not mutate slices coming from function inputs (noir-lang/noir#6463) chore: update example to show how to split public inputs in bash (noir-lang/noir#6472) fix: Discard optimisation that would change execution ordering or that is related to call outputs (noir-lang/noir#6461) chore: proptest for `canonicalize` on infix type expressions (noir-lang/noir#6269) fix: let formatter respect newlines between comments (noir-lang/noir#6458) fix: check infix expression is valid in program input (noir-lang/noir#6450) fix: don't crash on AsTraitPath with empty path (noir-lang/noir#6454) fix(tests): Prevent EOF error while running test programs (noir-lang/noir#6455) fix(sea): mem2reg to treat block input references as alias (noir-lang/noir#6452) chore: revamp attributes (noir-lang/noir#6424) feat!: Always Check Arithmetic Generics at Monomorphization (noir-lang/noir#6329) chore: split path and import lookups (noir-lang/noir#6430) fix(ssa): Resolve value IDs in terminator before comparing to array (noir-lang/noir#6448) fix: right shift is not a regular division (noir-lang/noir#6400)
2 parents 7639753 + e03d9fc commit 6b6263f

File tree

20 files changed

+499
-396
lines changed

20 files changed

+499
-396
lines changed

.noir-sync-commit

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
aa37cd5be25412919f466a938260ae1a485ee096
1+
b65a63d8d898e46cc686baa500f0b8070e45df14

noir/noir-repo/compiler/noirc_driver/src/abi_gen.rs

+10-16
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use noirc_abi::{
77
Abi, AbiErrorType, AbiParameter, AbiReturnType, AbiType, AbiValue, AbiVisibility, Sign,
88
};
99
use noirc_errors::Span;
10-
use noirc_evaluator::ErrorType;
1110
use noirc_frontend::ast::{Signedness, Visibility};
1211
use noirc_frontend::TypeBinding;
1312
use noirc_frontend::{
@@ -50,22 +49,17 @@ fn get_main_function_span(context: &Context) -> Span {
5049
}
5150
}
5251

53-
fn build_abi_error_type(context: &Context, typ: ErrorType) -> AbiErrorType {
52+
fn build_abi_error_type(context: &Context, typ: &Type) -> AbiErrorType {
5453
match typ {
55-
ErrorType::Dynamic(typ) => {
56-
if let Type::FmtString(len, item_types) = typ {
57-
let length = len
58-
.evaluate_to_u32(get_main_function_span(context))
59-
.expect("Cannot evaluate fmt length");
60-
let Type::Tuple(item_types) = item_types.as_ref() else {
61-
unreachable!("FmtString items must be a tuple")
62-
};
63-
let item_types =
64-
item_types.iter().map(|typ| abi_type_from_hir_type(context, typ)).collect();
65-
AbiErrorType::FmtString { length, item_types }
66-
} else {
67-
AbiErrorType::Custom(abi_type_from_hir_type(context, &typ))
68-
}
54+
Type::FmtString(len, item_types) => {
55+
let span = get_main_function_span(context);
56+
let length = len.evaluate_to_u32(span).expect("Cannot evaluate fmt length");
57+
let Type::Tuple(item_types) = item_types.as_ref() else {
58+
unreachable!("FmtString items must be a tuple")
59+
};
60+
let item_types =
61+
item_types.iter().map(|typ| abi_type_from_hir_type(context, typ)).collect();
62+
AbiErrorType::FmtString { length, item_types }
6963
}
7064
ErrorType::String(string) => AbiErrorType::String { string },
7165
}

noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_ir/artifact.rs

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ use crate::ErrorType;
77

88
use super::procedures::ProcedureId;
99

10+
use super::procedures::ProcedureId;
11+
1012
/// Represents a parameter or a return value of an entry point function.
1113
#[derive(Debug, Clone, Eq, PartialEq, Hash, PartialOrd, Ord)]
1214
pub(crate) enum BrilligParameter {

noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_ir/procedures/mod.rs

+56-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use mem_copy::compile_mem_copy_procedure;
1717
use noirc_errors::debug_info::ProcedureDebugId;
1818
use prepare_vector_insert::compile_prepare_vector_insert_procedure;
1919
use prepare_vector_push::compile_prepare_vector_push_procedure;
20-
use revert_with_string::compile_revert_with_string_procedure;
2120
use serde::{Deserialize, Serialize};
2221
use vector_copy::compile_vector_copy_procedure;
2322
use vector_pop_back::compile_vector_pop_back_procedure;
@@ -35,7 +34,7 @@ use super::{
3534
/// Procedures are a set of complex operations that are common in the noir language.
3635
/// Extracting them to reusable procedures allows us to reduce the size of the generated Brillig.
3736
/// Procedures receive their arguments on scratch space to avoid stack dumping&restoring.
38-
#[derive(Debug, Clone, Eq, PartialEq, Hash, PartialOrd, Ord, Deserialize, Serialize)]
37+
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, PartialOrd, Ord, Deserialize, Serialize)]
3938
pub enum ProcedureId {
4039
ArrayCopy,
4140
ArrayReverse,
@@ -107,11 +106,64 @@ impl std::fmt::Display for ProcedureId {
107106
}
108107
}
109108

109+
impl ProcedureId {
110+
pub(crate) fn to_debug_id(self) -> ProcedureDebugId {
111+
ProcedureDebugId(match self {
112+
ProcedureId::ArrayCopy => 0,
113+
ProcedureId::ArrayReverse => 1,
114+
ProcedureId::VectorCopy => 2,
115+
ProcedureId::MemCopy => 3,
116+
ProcedureId::PrepareVectorPush(true) => 4,
117+
ProcedureId::PrepareVectorPush(false) => 5,
118+
ProcedureId::VectorPopFront => 6,
119+
ProcedureId::VectorPopBack => 7,
120+
ProcedureId::PrepareVectorInsert => 8,
121+
ProcedureId::VectorRemove => 9,
122+
ProcedureId::CheckMaxStackDepth => 10,
123+
})
124+
}
125+
126+
pub fn from_debug_id(debug_id: ProcedureDebugId) -> Self {
127+
let inner = debug_id.0;
128+
match inner {
129+
0 => ProcedureId::ArrayCopy,
130+
1 => ProcedureId::ArrayReverse,
131+
2 => ProcedureId::VectorCopy,
132+
3 => ProcedureId::MemCopy,
133+
4 => ProcedureId::PrepareVectorPush(true),
134+
5 => ProcedureId::PrepareVectorPush(false),
135+
6 => ProcedureId::VectorPopFront,
136+
7 => ProcedureId::VectorPopBack,
137+
8 => ProcedureId::PrepareVectorInsert,
138+
9 => ProcedureId::VectorRemove,
139+
10 => ProcedureId::CheckMaxStackDepth,
140+
_ => panic!("Unsupported procedure debug ID of {inner} was supplied"),
141+
}
142+
}
143+
}
144+
145+
impl std::fmt::Display for ProcedureId {
146+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
147+
match self {
148+
ProcedureId::ArrayCopy => write!(f, "ArrayCopy"),
149+
ProcedureId::ArrayReverse => write!(f, "ArrayReverse"),
150+
ProcedureId::VectorCopy => write!(f, "VectorCopy"),
151+
ProcedureId::MemCopy => write!(f, "MemCopy"),
152+
ProcedureId::PrepareVectorPush(flag) => write!(f, "PrepareVectorPush({flag})"),
153+
ProcedureId::VectorPopFront => write!(f, "VectorPopFront"),
154+
ProcedureId::VectorPopBack => write!(f, "VectorPopBack"),
155+
ProcedureId::PrepareVectorInsert => write!(f, "PrepareVectorInsert"),
156+
ProcedureId::VectorRemove => write!(f, "VectorRemove"),
157+
ProcedureId::CheckMaxStackDepth => write!(f, "CheckMaxStackDepth"),
158+
}
159+
}
160+
}
161+
110162
pub(crate) fn compile_procedure<F: AcirField + DebugToString>(
111163
procedure_id: ProcedureId,
112164
) -> BrilligArtifact<F> {
113-
let mut brillig_context = BrilligContext::new_for_procedure(false, procedure_id.clone());
114-
brillig_context.enter_context(Label::procedure(procedure_id.clone()));
165+
let mut brillig_context = BrilligContext::new_for_procedure(false, procedure_id);
166+
brillig_context.enter_context(Label::procedure(procedure_id));
115167

116168
match procedure_id {
117169
ProcedureId::MemCopy => compile_mem_copy_procedure(&mut brillig_context),

noir/noir-repo/compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1010,13 +1010,13 @@ impl<'a> Context<'a> {
10101010
};
10111011
entry_point.link_with(artifact);
10121012
// Insert the range of opcode locations occupied by a procedure
1013-
if let Some(procedure_id) = &artifact.procedure {
1013+
if let Some(procedure_id) = artifact.procedure {
10141014
let num_opcodes = entry_point.byte_code.len();
10151015
let previous_num_opcodes = entry_point.byte_code.len() - artifact.byte_code.len();
10161016
// We subtract one as to keep the range inclusive on both ends
10171017
entry_point
10181018
.procedure_locations
1019-
.insert(procedure_id.clone(), (previous_num_opcodes, num_opcodes - 1));
1019+
.insert(procedure_id, (previous_num_opcodes, num_opcodes - 1));
10201020
}
10211021
}
10221022
// Generate the final bytecode

0 commit comments

Comments
 (0)