Skip to content

Commit

Permalink
fix: Set location before cast instructions in SSA (#2202)
Browse files Browse the repository at this point in the history
Fix compiler panic before cast
  • Loading branch information
jfecher authored Aug 7, 2023
1 parent 4a5d2de commit a72cc96
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion crates/noirc_evaluator/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub enum RuntimeError {
InternalError(#[from] InternalError),
#[error("Index out of bounds, array has size {index:?}, but index was {array_size:?}")]
IndexOutOfBounds { index: usize, array_size: usize, location: Option<Location> },
#[error("All Witnesses are by default u{num_bits:?} Applying this type does not apply any constraints.\n We also currently do not allow integers of size more than {num_bits:?}, this will be handled by BigIntegers.")]
#[error("Range constraint of {num_bits} bits is too large for the Field size")]
InvalidRangeConstraint { num_bits: u32, location: Option<Location> },
#[error("Expected array index to fit into a u64")]
TypeConversion { from: String, into: String, location: Option<Location> },
Expand Down
1 change: 1 addition & 0 deletions crates/noirc_evaluator/src/ssa/ssa_gen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ impl<'a> FunctionContext<'a> {
fn codegen_cast(&mut self, cast: &ast::Cast) -> Values {
let lhs = self.codegen_non_tuple_expression(&cast.lhs);
let typ = Self::convert_non_tuple_type(&cast.r#type);
self.builder.set_location(cast.location);
self.builder.insert_cast(lhs, typ).into()
}

Expand Down
1 change: 1 addition & 0 deletions crates/noirc_frontend/src/monomorphization/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ pub struct If {
pub struct Cast {
pub lhs: Box<Expression>,
pub r#type: Type,
pub location: Location,
}

#[derive(Debug, Clone)]
Expand Down
1 change: 1 addition & 0 deletions crates/noirc_frontend/src/monomorphization/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ impl<'interner> Monomorphizer<'interner> {
HirExpression::Cast(cast) => ast::Expression::Cast(ast::Cast {
lhs: Box::new(self.expr(cast.lhs)),
r#type: Self::convert_type(&cast.r#type),
location: self.interner.expr_location(&expr),
}),

HirExpression::For(for_expr) => {
Expand Down

0 comments on commit a72cc96

Please sign in to comment.