From 41441527700d7c0fe59769803048a3b285badd77 Mon Sep 17 00:00:00 2001 From: Aztec Bot <49558828+AztecBot@users.noreply.github.com> Date: Mon, 2 Sep 2024 12:54:25 -0400 Subject: [PATCH] feat: Sync from aztec-packages (#5883) Automated pull of Noir development from [aztec-packages](https://github.com/AztecProtocol/aztec-packages). BEGIN_COMMIT_OVERRIDE feat!: Do not encode assertion strings in the programs (https://github.com/AztecProtocol/aztec-packages/pull/8315) feat: Sync from noir (https://github.com/AztecProtocol/aztec-packages/pull/8314) END_COMMIT_OVERRIDE --- .aztec-sync-commit | 2 +- .../src/brillig/brillig_gen/brillig_block.rs | 4 ++-- .../noirc_evaluator/src/ssa/acir_gen/mod.rs | 4 ++-- .../noirc_evaluator/src/ssa/ir/instruction.rs | 22 +++++++++---------- .../noirc_evaluator/src/ssa/ir/printer.rs | 4 ++-- .../noirc_evaluator/src/ssa/ssa_gen/mod.rs | 7 +++++- 6 files changed, 23 insertions(+), 20 deletions(-) diff --git a/.aztec-sync-commit b/.aztec-sync-commit index 03f9d78d780..49baefec2c3 100644 --- a/.aztec-sync-commit +++ b/.aztec-sync-commit @@ -1 +1 @@ -cf5b667c9566019853a5dc2a7f16ed024ab9182b +f5bbb89b489bc85f286bcc5ed45c30f38032810c diff --git a/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_block.rs b/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_block.rs index faa1c4d43da..d3d0e2231ad 100644 --- a/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_block.rs +++ b/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_block.rs @@ -266,7 +266,7 @@ impl<'block> BrilligBlock<'block> { condition, ); match assert_message { - Some(ConstrainError::UserDefined(selector, values)) => { + Some(ConstrainError::Dynamic(selector, values)) => { let payload_values = vecmap(values, |value| self.convert_ssa_value(*value, dfg)); let payload_as_params = vecmap(values, |value| { @@ -280,7 +280,7 @@ impl<'block> BrilligBlock<'block> { selector.as_u64(), ); } - Some(ConstrainError::Intrinsic(message)) => { + Some(ConstrainError::StaticString(message)) => { self.brillig_context.codegen_constrain(condition, Some(message.clone())); } None => { diff --git a/compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs b/compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs index b0fd976206b..a2b9e46a15a 100644 --- a/compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs +++ b/compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs @@ -647,10 +647,10 @@ impl<'a> Context<'a> { let assert_payload = if let Some(error) = assert_message { match error { - ConstrainError::Intrinsic(string) => { + ConstrainError::StaticString(string) => { Some(AssertionPayload::StaticString(string.clone())) } - ConstrainError::UserDefined(error_selector, values) => { + ConstrainError::Dynamic(error_selector, values) => { if let Some(constant_string) = try_to_extract_string_from_error_payload( *error_selector, values, diff --git a/compiler/noirc_evaluator/src/ssa/ir/instruction.rs b/compiler/noirc_evaluator/src/ssa/ir/instruction.rs index 36069f17933..e30707effed 100644 --- a/compiler/noirc_evaluator/src/ssa/ir/instruction.rs +++ b/compiler/noirc_evaluator/src/ssa/ir/instruction.rs @@ -468,12 +468,10 @@ impl Instruction { let lhs = f(*lhs); let rhs = f(*rhs); let assert_message = assert_message.as_ref().map(|error| match error { - ConstrainError::UserDefined(selector, payload_values) => { - ConstrainError::UserDefined( - *selector, - payload_values.iter().map(|&value| f(value)).collect(), - ) - } + ConstrainError::Dynamic(selector, payload_values) => ConstrainError::Dynamic( + *selector, + payload_values.iter().map(|&value| f(value)).collect(), + ), _ => error.clone(), }); Instruction::Constrain(lhs, rhs, assert_message) @@ -541,7 +539,7 @@ impl Instruction { Instruction::Constrain(lhs, rhs, assert_error) => { f(*lhs); f(*rhs); - if let Some(ConstrainError::UserDefined(_, values)) = assert_error.as_ref() { + if let Some(ConstrainError::Dynamic(_, values)) = assert_error.as_ref() { values.iter().for_each(|&val| { f(val); }); @@ -836,15 +834,15 @@ pub(crate) fn error_selector_from_type(typ: &ErrorType) -> ErrorSelector { #[derive(Debug, PartialEq, Eq, Hash, Clone, Serialize, Deserialize)] pub(crate) enum ConstrainError { - // These are errors which have been hardcoded during SSA gen - Intrinsic(String), - // These are errors issued by the user - UserDefined(ErrorSelector, Vec), + // Static string errors are not handled inside the program as data for efficiency reasons. + StaticString(String), + // These errors are handled by the program as data. + Dynamic(ErrorSelector, Vec), } impl From for ConstrainError { fn from(value: String) -> Self { - ConstrainError::Intrinsic(value) + ConstrainError::StaticString(value) } } diff --git a/compiler/noirc_evaluator/src/ssa/ir/printer.rs b/compiler/noirc_evaluator/src/ssa/ir/printer.rs index e8c9d01988e..2b564c14aa7 100644 --- a/compiler/noirc_evaluator/src/ssa/ir/printer.rs +++ b/compiler/noirc_evaluator/src/ssa/ir/printer.rs @@ -245,10 +245,10 @@ fn display_constrain_error( f: &mut Formatter, ) -> Result { match error { - ConstrainError::Intrinsic(assert_message_string) => { + ConstrainError::StaticString(assert_message_string) => { writeln!(f, " '{assert_message_string:?}'") } - ConstrainError::UserDefined(selector, values) => { + ConstrainError::Dynamic(selector, values) => { if let Some(constant_string) = try_to_extract_string_from_error_payload(*selector, values, &function.dfg) { diff --git a/compiler/noirc_evaluator/src/ssa/ssa_gen/mod.rs b/compiler/noirc_evaluator/src/ssa/ssa_gen/mod.rs index 6b19aff2674..2318fea8960 100644 --- a/compiler/noirc_evaluator/src/ssa/ssa_gen/mod.rs +++ b/compiler/noirc_evaluator/src/ssa/ssa_gen/mod.rs @@ -701,6 +701,11 @@ impl<'a> FunctionContext<'a> { assert_message: &Option>, ) -> Result, RuntimeError> { let Some(assert_message_payload) = assert_message else { return Ok(None) }; + + if let Expression::Literal(ast::Literal::Str(static_string)) = &assert_message_payload.0 { + return Ok(Some(ConstrainError::StaticString(static_string.clone()))); + } + let (assert_message_expression, assert_message_typ) = assert_message_payload.as_ref(); let values = self.codegen_expression(assert_message_expression)?.into_value_list(self); @@ -713,7 +718,7 @@ impl<'a> FunctionContext<'a> { self.builder.record_error_type(error_type_id, assert_message_typ.clone()); } }; - Ok(Some(ConstrainError::UserDefined(error_type_id, values))) + Ok(Some(ConstrainError::Dynamic(error_type_id, values))) } fn codegen_assign(&mut self, assign: &ast::Assign) -> Result {