Skip to content

Commit

Permalink
feat: Sync from aztec-packages (#5883)
Browse files Browse the repository at this point in the history
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
(AztecProtocol/aztec-packages#8315)
feat: Sync from noir
(AztecProtocol/aztec-packages#8314)
END_COMMIT_OVERRIDE
  • Loading branch information
AztecBot authored Sep 2, 2024
1 parent d59c708 commit 4144152
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .aztec-sync-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
cf5b667c9566019853a5dc2a7f16ed024ab9182b
f5bbb89b489bc85f286bcc5ed45c30f38032810c
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand All @@ -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 => {
Expand Down
4 changes: 2 additions & 2 deletions compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
22 changes: 10 additions & 12 deletions compiler/noirc_evaluator/src/ssa/ir/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
});
Expand Down Expand Up @@ -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<ValueId>),
// 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<ValueId>),
}

impl From<String> for ConstrainError {
fn from(value: String) -> Self {
ConstrainError::Intrinsic(value)
ConstrainError::StaticString(value)
}
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/noirc_evaluator/src/ssa/ir/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
7 changes: 6 additions & 1 deletion compiler/noirc_evaluator/src/ssa/ssa_gen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,11 @@ impl<'a> FunctionContext<'a> {
assert_message: &Option<Box<(Expression, HirType)>>,
) -> Result<Option<ConstrainError>, 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);
Expand All @@ -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<Values, RuntimeError> {
Expand Down

0 comments on commit 4144152

Please sign in to comment.