From 7d85c9c805c558b8fe6faefdc6d68fdcbda8b823 Mon Sep 17 00:00:00 2001 From: Ary Borenszweig Date: Thu, 3 Jul 2025 16:28:38 -0300 Subject: [PATCH 1/2] chore: remove redundant associated constant lookup --- .../noirc_frontend/src/elaborator/patterns.rs | 30 +------------------ 1 file changed, 1 insertion(+), 29 deletions(-) diff --git a/compiler/noirc_frontend/src/elaborator/patterns.rs b/compiler/noirc_frontend/src/elaborator/patterns.rs index 6f455179cc8..3fbec71a27c 100644 --- a/compiler/noirc_frontend/src/elaborator/patterns.rs +++ b/compiler/noirc_frontend/src/elaborator/patterns.rs @@ -18,14 +18,13 @@ use crate::{ type_check::{Source, TypeCheckError}, }, hir_def::{ - expr::{HirExpression, HirIdent, HirLiteral, HirMethodReference, ImplKind, TraitItem}, + expr::{HirExpression, HirIdent, HirMethodReference, ImplKind, TraitItem}, stmt::HirPattern, }, node_interner::{ DefinitionId, DefinitionInfo, DefinitionKind, ExprId, FuncId, GlobalId, TraitImplKind, TypeAliasId, TypeId, }, - signed_field::SignedField, }; use super::{ @@ -681,20 +680,6 @@ impl Elaborator<'_> { let location = variable.location; let name = variable.segments[1].ident.as_str(); - // Check the `Self::AssociatedConstant` case when inside a trait - if let Some(trait_id) = &self.current_trait { - let trait_ = self.interner.get_trait(*trait_id); - if let Some(associated_type) = trait_.get_associated_type(name) { - if let Kind::Numeric(numeric_type) = associated_type.kind() { - // We can produce any value here because this trait method is never going to - // produce code (only trait impl methods do) - let numeric_type: Type = *numeric_type.clone(); - let value = SignedField::zero(); - return Some(self.constant_integer(numeric_type, value, location)); - } - } - } - let Some(self_type) = &self.self_type else { return None; }; @@ -753,19 +738,6 @@ impl Elaborator<'_> { TypedPathSegment { ident: segment.ident, generics, location: segment.location } } - fn constant_integer( - &mut self, - numeric_type: Type, - value: SignedField, - location: Location, - ) -> (ExprId, Type) { - let hir_expr = HirExpression::Literal(HirLiteral::Integer(value)); - let id = self.interner.push_expr(hir_expr); - self.interner.push_expr_location(id, location); - self.interner.push_expr_type(id, numeric_type.clone()); - (id, numeric_type) - } - /// Solve any generics that are part of the path before the function, for example: /// /// ```noir From cb55c871fbfa3b0fb78f1a454b931e3fc6a5db6c Mon Sep 17 00:00:00 2001 From: Ary Borenszweig Date: Thu, 3 Jul 2025 16:29:34 -0300 Subject: [PATCH 2/2] Use `?` --- compiler/noirc_frontend/src/elaborator/patterns.rs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/compiler/noirc_frontend/src/elaborator/patterns.rs b/compiler/noirc_frontend/src/elaborator/patterns.rs index 3fbec71a27c..158038cc236 100644 --- a/compiler/noirc_frontend/src/elaborator/patterns.rs +++ b/compiler/noirc_frontend/src/elaborator/patterns.rs @@ -679,14 +679,8 @@ impl Elaborator<'_> { let location = variable.location; let name = variable.segments[1].ident.as_str(); - - let Some(self_type) = &self.self_type else { - return None; - }; - - let Some(trait_impl_id) = &self.current_trait_impl else { - return None; - }; + let self_type = self.self_type.as_ref()?; + let trait_impl_id = &self.current_trait_impl?; // Check the `Self::AssociatedConstant` case when inside a trait impl if let Some((definition_id, numeric_type)) =