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 1 commit
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
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 @@ -8,7 +8,7 @@
use iter_extended::{try_vecmap, vecmap};
use noirc_errors::Location;
use noirc_frontend::{
monomorphization::ast::{self, Expression, Program},
monomorphization::ast::{self, Expression, Literal, Program},
Visibility,
};

Expand Down Expand Up @@ -470,7 +470,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 473 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 @@ -524,7 +524,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 527 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 @@ -537,7 +537,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 540 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 @@ -700,6 +700,11 @@
return Ok(None)
};

if let ast::Expression::Literal(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
9 changes: 9 additions & 0 deletions compiler/noirc_frontend/src/hir/resolution/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1211,6 +1211,15 @@ impl<'a> Resolver<'a> {
span: Span,
condition: Expression,
) -> Option<ExprId> {
if let Some(
assert_message_expr @ Expression {
kind: ExpressionKind::Literal(Literal::Str(..)), ..
},
) = assert_message_expr
{
return Some(self.resolve_expression(assert_message_expr));
}

let mut assert_msg_call_args = if let Some(assert_message_expr) = assert_message_expr {
vec![assert_message_expr.clone()]
} else {
Expand Down
Loading