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

fix: simplify constant assert messages into ConstrainError::Static #4287

Merged
merged 6 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
6 changes: 6 additions & 0 deletions compiler/noirc_evaluator/src/ssa/ssa_gen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@
let typ = Self::convert_non_tuple_type(&cast.r#type);

Ok(self.insert_safe_cast(lhs, typ, cast.location).into())
}

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

View workflow job for this annotation

GitHub Actions / Code

Unknown word (brif)

/// Codegens a for loop, creating three new blocks in the process.
/// The return value of a for loop is always a unit literal.
Expand Down Expand Up @@ -512,7 +512,7 @@
self.define(for_expr.index_variable, loop_index.into());
self.codegen_expression(&for_expr.block)?;
let new_loop_index = self.make_offset(loop_index, 1);
self.builder.terminate_with_jmp(loop_entry, vec![new_loop_index]);

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

View workflow job for this annotation

GitHub Actions / Code

Unknown word (brif)

// Finish by switching back to the end of the loop
self.builder.switch_to_block(loop_end);
Expand All @@ -525,7 +525,7 @@
///
/// v0 = ... codegen cond ...
/// brif v0, then: then_block, else: else_block
/// then_block():

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

View workflow job for this annotation

GitHub Actions / Code

Unknown word (brif)
/// v1 = ... codegen a ...
/// br end_if(v1)
/// else_block():
Expand Down Expand Up @@ -700,6 +700,12 @@
return Ok(None)
};

if let ast::Expression::Literal(ast::Literal::Str(assert_message)) =
assert_message_expr.as_ref()
{
return Ok(Some(Box::new(ConstrainError::Static(assert_message.to_string()))));
}

let ast::Expression::Call(call) = assert_message_expr.as_ref() else {
return Err(InternalError::Unexpected {
expected: "Expected a call expression".to_owned(),
Expand Down
12 changes: 6 additions & 6 deletions compiler/noirc_frontend/src/hir/resolution/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1211,12 +1211,11 @@ impl<'a> Resolver<'a> {
span: Span,
condition: Expression,
) -> Option<ExprId> {
let mut assert_msg_call_args = if let Some(assert_message_expr) = assert_message_expr {
vec![assert_message_expr.clone()]
} else {
return None;
};
assert_msg_call_args.push(condition);
let assert_message_expr = assert_message_expr?;

if matches!(assert_message_expr, Expression {kind: ExpressionKind::Literal(Literal::Str(..)), ..}){
return Some(self.resolve_expression(assert_message_expr));
}

let is_in_stdlib = self.path_resolver.module_id().krate.is_stdlib();
let assert_msg_call_path = if is_in_stdlib {
Expand All @@ -1232,6 +1231,7 @@ impl<'a> Resolver<'a> {
span,
})
};
let assert_msg_call_args = vec![assert_message_expr.clone(), condition];
let assert_msg_call_expr = Expression::call(
Expression { kind: assert_msg_call_path, span },
assert_msg_call_args,
Expand Down
4 changes: 2 additions & 2 deletions tooling/debugger/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ mod tests {
let initial_witness = BTreeMap::from([(Witness(1), fe_1)]).into();

let foreign_call_executor =
Box::new(DefaultDebugForeignCallExecutor::from_artifact(true, &debug_artifact));
Box::new(DefaultDebugForeignCallExecutor::from_artifact(true, debug_artifact));
let mut context = DebugContext::new(
&StubbedBlackBoxSolver,
circuit,
Expand Down Expand Up @@ -624,7 +624,7 @@ mod tests {
let initial_witness = BTreeMap::from([(Witness(1), fe_1), (Witness(2), fe_1)]).into();

let foreign_call_executor =
Box::new(DefaultDebugForeignCallExecutor::from_artifact(true, &debug_artifact));
Box::new(DefaultDebugForeignCallExecutor::from_artifact(true, debug_artifact));
let mut context = DebugContext::new(
&StubbedBlackBoxSolver,
circuit,
Expand Down
Loading