Skip to content

Commit

Permalink
Merge branch 'master' into gd/u128_add
Browse files Browse the repository at this point in the history
* master:
  feat: Implement Operator Overloading (#3931)
  chore: fix casing on `InternalError::Unexpected` (#3937)
  chore: add test case for brillig array equality assertion (#3936)
  feat(lsp): goto struct member inside Impl method (#3918)
  • Loading branch information
TomAFrench committed Jan 3, 2024
2 parents ed97153 + 4b16090 commit 4cd200b
Show file tree
Hide file tree
Showing 35 changed files with 1,246 additions and 362 deletions.
4 changes: 2 additions & 2 deletions compiler/noirc_evaluator/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ pub enum InternalError {
#[error("ICE: Undeclared AcirVar")]
UndeclaredAcirVar { call_stack: CallStack },
#[error("ICE: Expected {expected:?}, found {found:?}")]
UnExpected { expected: String, found: String, call_stack: CallStack },
Unexpected { expected: String, found: String, call_stack: CallStack },
}

impl RuntimeError {
Expand All @@ -119,7 +119,7 @@ impl RuntimeError {
| InternalError::MissingArg { call_stack, .. }
| InternalError::NotAConstant { call_stack, .. }
| InternalError::UndeclaredAcirVar { call_stack }
| InternalError::UnExpected { call_stack, .. },
| InternalError::Unexpected { call_stack, .. },
)
| RuntimeError::FailedConstraint { call_stack, .. }
| RuntimeError::IndexOutOfBounds { call_stack, .. }
Expand Down
20 changes: 10 additions & 10 deletions compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ impl Context {
let len = if matches!(typ, Type::Array(_, _)) {
typ.flattened_size()
} else {
return Err(InternalError::UnExpected {
return Err(InternalError::Unexpected {
expected: "Block params should be an array".to_owned(),
found: format!("Instead got {:?}", typ),
call_stack: self.acir_context.get_call_stack(),
Expand Down Expand Up @@ -640,7 +640,7 @@ impl Context {
Instruction::ArrayGet { array, index } => (array, index, None),
Instruction::ArraySet { array, index, value, .. } => (array, index, Some(value)),
_ => {
return Err(InternalError::UnExpected {
return Err(InternalError::Unexpected {
expected: "Instruction should be an ArrayGet or ArraySet".to_owned(),
found: format!("Instead got {:?}", dfg[instruction]),
call_stack: self.acir_context.get_call_stack(),
Expand Down Expand Up @@ -697,7 +697,7 @@ impl Context {

match self.convert_value(array, dfg) {
AcirValue::Var(acir_var, _) => {
return Err(RuntimeError::InternalError(InternalError::UnExpected {
return Err(RuntimeError::InternalError(InternalError::Unexpected {
expected: "an array value".to_string(),
found: format!("{acir_var:?}"),
call_stack: self.acir_context.get_call_stack(),
Expand Down Expand Up @@ -788,7 +788,7 @@ impl Context {
let slice_sizes = if store_type.contains_slice_element() {
self.compute_slice_sizes(store, None, dfg);
self.slice_sizes.get(&store).cloned().ok_or_else(|| {
InternalError::UnExpected {
InternalError::Unexpected {
expected: "Store value should have slice sizes computed".to_owned(),
found: "Missing key in slice sizes map".to_owned(),
call_stack: self.acir_context.get_call_stack(),
Expand Down Expand Up @@ -1013,7 +1013,7 @@ impl Context {
let array = match dfg[instruction] {
Instruction::ArraySet { array, .. } => array,
_ => {
return Err(InternalError::UnExpected {
return Err(InternalError::Unexpected {
expected: "Instruction should be an ArraySet".to_owned(),
found: format!("Instead got {:?}", dfg[instruction]),
call_stack: self.acir_context.get_call_stack(),
Expand Down Expand Up @@ -1235,7 +1235,7 @@ impl Context {
}
}
_ => {
return Err(InternalError::UnExpected {
return Err(InternalError::Unexpected {
expected: "AcirValue::DynamicArray or AcirValue::Array"
.to_owned(),
found: format!("{:?}", array_acir_value),
Expand All @@ -1246,7 +1246,7 @@ impl Context {
}
}
_ => {
return Err(InternalError::UnExpected {
return Err(InternalError::Unexpected {
expected: "array or instruction".to_owned(),
found: format!("{:?}", &dfg[array_id]),
call_stack: self.acir_context.get_call_stack(),
Expand All @@ -1256,7 +1256,7 @@ impl Context {
};
}
_ => {
return Err(InternalError::UnExpected {
return Err(InternalError::Unexpected {
expected: "array or slice".to_owned(),
found: array_typ.to_string(),
call_stack: self.acir_context.get_call_stack(),
Expand Down Expand Up @@ -1513,12 +1513,12 @@ impl Context {
) -> Result<AcirVar, InternalError> {
match self.convert_value(value_id, dfg) {
AcirValue::Var(acir_var, _) => Ok(acir_var),
AcirValue::Array(array) => Err(InternalError::UnExpected {
AcirValue::Array(array) => Err(InternalError::Unexpected {
expected: "a numeric value".to_string(),
found: format!("{array:?}"),
call_stack: self.acir_context.get_call_stack(),
}),
AcirValue::DynamicArray(_) => Err(InternalError::UnExpected {
AcirValue::DynamicArray(_) => Err(InternalError::Unexpected {
expected: "a numeric value".to_string(),
found: "an array".to_string(),
call_stack: self.acir_context.get_call_stack(),
Expand Down
8 changes: 6 additions & 2 deletions compiler/noirc_frontend/src/hir/resolution/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1253,8 +1253,10 @@ impl<'a> Resolver<'a> {
if let Some((hir_expr, object_type)) = self.resolve_trait_generic_path(&path) {
let expr_id = self.interner.push_expr(hir_expr);
self.interner.push_expr_location(expr_id, expr.span, self.file);
self.interner
.select_impl_for_ident(expr_id, TraitImplKind::Assumed { object_type });
self.interner.select_impl_for_expression(
expr_id,
TraitImplKind::Assumed { object_type },
);
return expr_id;
} else {
// If the Path is being used as an Expression, then it is referring to a global from a separate module
Expand Down Expand Up @@ -1313,10 +1315,12 @@ impl<'a> Resolver<'a> {
ExpressionKind::Infix(infix) => {
let lhs = self.resolve_expression(infix.lhs);
let rhs = self.resolve_expression(infix.rhs);
let trait_id = self.interner.get_operator_trait_method(infix.operator.contents);

HirExpression::Infix(HirInfixExpression {
lhs,
operator: HirBinaryOp::new(infix.operator, self.file),
trait_method_id: trait_id,
rhs,
})
}
Expand Down
7 changes: 7 additions & 0 deletions compiler/noirc_frontend/src/hir/resolution/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ pub(crate) fn resolve_traits(
context.def_interner.update_trait(trait_id, |trait_def| {
trait_def.set_methods(methods);
});

// This check needs to be after the trait's methods are set since
// the interner may set `interner.ordering_type` based on the result type
// of the Cmp trait, if this is it.
if crate_id.is_stdlib() {
context.def_interner.try_add_operator_trait(trait_id);
}
}
res
}
Expand Down
Loading

0 comments on commit 4cd200b

Please sign in to comment.