From a72cc96e7535f3b85db005f2b09014488933b4df Mon Sep 17 00:00:00 2001 From: jfecher Date: Mon, 7 Aug 2023 14:01:54 -0500 Subject: [PATCH] fix: Set location before cast instructions in SSA (#2202) Fix compiler panic before cast --- crates/noirc_evaluator/src/errors.rs | 2 +- crates/noirc_evaluator/src/ssa/ssa_gen/mod.rs | 1 + crates/noirc_frontend/src/monomorphization/ast.rs | 1 + crates/noirc_frontend/src/monomorphization/mod.rs | 1 + 4 files changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/noirc_evaluator/src/errors.rs b/crates/noirc_evaluator/src/errors.rs index 27a87ccce36..038210f86e1 100644 --- a/crates/noirc_evaluator/src/errors.rs +++ b/crates/noirc_evaluator/src/errors.rs @@ -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 }, - #[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 }, #[error("Expected array index to fit into a u64")] TypeConversion { from: String, into: String, location: Option }, diff --git a/crates/noirc_evaluator/src/ssa/ssa_gen/mod.rs b/crates/noirc_evaluator/src/ssa/ssa_gen/mod.rs index 0c0dd35211b..65129f1f933 100644 --- a/crates/noirc_evaluator/src/ssa/ssa_gen/mod.rs +++ b/crates/noirc_evaluator/src/ssa/ssa_gen/mod.rs @@ -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() } diff --git a/crates/noirc_frontend/src/monomorphization/ast.rs b/crates/noirc_frontend/src/monomorphization/ast.rs index 33c3bbebff4..e748cc74d13 100644 --- a/crates/noirc_frontend/src/monomorphization/ast.rs +++ b/crates/noirc_frontend/src/monomorphization/ast.rs @@ -120,6 +120,7 @@ pub struct If { pub struct Cast { pub lhs: Box, pub r#type: Type, + pub location: Location, } #[derive(Debug, Clone)] diff --git a/crates/noirc_frontend/src/monomorphization/mod.rs b/crates/noirc_frontend/src/monomorphization/mod.rs index 6c9724de6ce..78d540f398e 100644 --- a/crates/noirc_frontend/src/monomorphization/mod.rs +++ b/crates/noirc_frontend/src/monomorphization/mod.rs @@ -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) => {