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

feat: Sync from aztec-packages #5883

Merged
merged 1 commit into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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: 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 @@ -471,7 +471,7 @@
/// br loop_entry(v0)
/// loop_entry(i: Field):
/// v2 = lt i v1
/// brif v2, then: loop_body, else: loop_end

Check warning on line 474 in compiler/noirc_evaluator/src/ssa/ssa_gen/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (brif)
/// loop_body():
/// v3 = ... codegen body ...
/// v4 = add 1, i
Expand Down Expand Up @@ -530,7 +530,7 @@
/// For example, the expression `if cond { a } else { b }` is codegen'd as:
///
/// v0 = ... codegen cond ...
/// brif v0, then: then_block, else: else_block

Check warning on line 533 in compiler/noirc_evaluator/src/ssa/ssa_gen/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (brif)
/// then_block():
/// v1 = ... codegen a ...
/// br end_if(v1)
Expand All @@ -543,7 +543,7 @@
/// As another example, the expression `if cond { a }` is codegen'd as:
///
/// v0 = ... codegen cond ...
/// brif v0, then: then_block, else: end_block

Check warning on line 546 in compiler/noirc_evaluator/src/ssa/ssa_gen/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (brif)
/// then_block:
/// v1 = ... codegen a ...
/// br end_if()
Expand Down Expand Up @@ -701,6 +701,11 @@
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 @@
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
Loading