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

chore: remove some unused HIR code #7643

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 0 additions & 2 deletions compiler/noirc_frontend/src/elaborator/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,6 @@ fn can_return_without_recursing(interner: &NodeInterner, func_id: FuncId, expr_i
HirExpression::Index(e) => check(e.collection) && check(e.index),
HirExpression::MemberAccess(e) => check(e.lhs),
HirExpression::Call(e) => check(e.func) && e.arguments.iter().cloned().all(check),
HirExpression::MethodCall(e) => check(e.object) && e.arguments.iter().cloned().all(check),
HirExpression::Constrain(e) => check(e.0) && e.2.map(check).unwrap_or(true),
HirExpression::Cast(e) => check(e.lhs),
HirExpression::If(e) => {
Expand All @@ -323,7 +322,6 @@ fn can_return_without_recursing(interner: &NodeInterner, func_id: FuncId, expr_i
| HirExpression::EnumConstructor(_)
| HirExpression::Quote(_)
| HirExpression::Unquote(_)
| HirExpression::Comptime(_)
| HirExpression::Error => true,
}
}
Expand Down
20 changes: 2 additions & 18 deletions compiler/noirc_frontend/src/hir/comptime/hir_to_display_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use crate::ast::{
ArrayLiteral, AssignStatement, BlockExpression, CallExpression, CastExpression, ConstrainKind,
ConstructorExpression, ExpressionKind, ForLoopStatement, ForRange, GenericTypeArgs, Ident,
IfExpression, IndexExpression, InfixExpression, LValue, Lambda, Literal, MatchExpression,
MemberAccessExpression, MethodCallExpression, Path, PathSegment, Pattern, PrefixExpression,
UnresolvedType, UnresolvedTypeData, UnresolvedTypeExpression, UnsafeExpression, WhileStatement,
MemberAccessExpression, Path, PathSegment, Pattern, PrefixExpression, UnresolvedType,
UnresolvedTypeData, UnresolvedTypeExpression, UnsafeExpression, WhileStatement,
};
use crate::ast::{ConstrainExpression, Expression, Statement, StatementKind};
use crate::hir_def::expr::{
Expand Down Expand Up @@ -148,19 +148,6 @@ impl HirExpression {
let is_macro_call = false;
ExpressionKind::Call(Box::new(CallExpression { func, arguments, is_macro_call }))
}
HirExpression::MethodCall(method_call) => {
ExpressionKind::MethodCall(Box::new(MethodCallExpression {
object: method_call.object.to_display_ast(interner),
method_name: method_call.method.clone(),
arguments: vecmap(method_call.arguments.clone(), |arg| {
arg.to_display_ast(interner)
}),
generics: method_call.generics.clone().map(|option| {
option.iter().map(|generic| generic.to_display_ast()).collect()
}),
is_macro_call: false,
}))
}
HirExpression::Constrain(constrain) => {
let expr = constrain.0.to_display_ast(interner);
let mut arguments = vec![expr];
Expand Down Expand Up @@ -198,9 +185,6 @@ impl HirExpression {
ExpressionKind::Lambda(Box::new(Lambda { parameters, return_type, body }))
}
HirExpression::Error => ExpressionKind::Error,
HirExpression::Comptime(block) => {
ExpressionKind::Comptime(block.to_display_ast(interner), location)
}
HirExpression::Unsafe(block) => ExpressionKind::Unsafe(UnsafeExpression {
block: block.to_display_ast(interner),
unsafe_keyword_location: location,
Expand Down
32 changes: 1 addition & 31 deletions compiler/noirc_frontend/src/hir/comptime/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
expr::{
HirArrayLiteral, HirBlockExpression, HirCallExpression, HirCastExpression,
HirConstructorExpression, HirExpression, HirIdent, HirIfExpression, HirIndexExpression,
HirInfixExpression, HirLambda, HirLiteral, HirMemberAccess, HirMethodCallExpression,
HirPrefixExpression,
HirInfixExpression, HirLambda, HirLiteral, HirMemberAccess, HirPrefixExpression,
},
stmt::{
HirAssignStatement, HirForStatement, HirLValue, HirLetStatement, HirPattern,
Expand Down Expand Up @@ -255,7 +254,7 @@
}
} else {
let name = self.elaborator.interner.function_name(&function);
unreachable!("Non-builtin, lowlevel or oracle builtin fn '{name}'")

Check warning on line 257 in compiler/noirc_frontend/src/hir/comptime/interpreter.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (lowlevel)
}
}

Expand Down Expand Up @@ -528,15 +527,13 @@
HirExpression::Constructor(constructor) => self.evaluate_constructor(constructor, id),
HirExpression::MemberAccess(access) => self.evaluate_access(access, id),
HirExpression::Call(call) => self.evaluate_call(call, id),
HirExpression::MethodCall(call) => self.evaluate_method_call(call, id),
HirExpression::Constrain(constrain) => self.evaluate_constrain(constrain),
HirExpression::Cast(cast) => self.evaluate_cast(&cast, id),
HirExpression::If(if_) => self.evaluate_if(if_, id),
HirExpression::Match(match_) => todo!("Evaluate match in comptime code"),
HirExpression::Tuple(tuple) => self.evaluate_tuple(tuple),
HirExpression::Lambda(lambda) => self.evaluate_lambda(lambda, id),
HirExpression::Quote(tokens) => self.evaluate_quote(tokens, id),
HirExpression::Comptime(block) => self.evaluate_block(block),
HirExpression::Unsafe(block) => self.evaluate_block(block),
HirExpression::EnumConstructor(constructor) => {
self.evaluate_enum_constructor(constructor, id)
Expand Down Expand Up @@ -1039,7 +1036,7 @@
}

/// Generate matches for bit shifting, which in Noir only accepts `u8` for RHS.
macro_rules! match_bitshift {

Check warning on line 1039 in compiler/noirc_frontend/src/hir/comptime/interpreter.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (bitshift)
(($lhs_value:ident as $lhs:ident $op:literal $rhs_value:ident as $rhs:ident) => $expr:expr) => {
match_values! {
($lhs_value as $lhs $op $rhs_value as $rhs) {
Expand Down Expand Up @@ -1109,10 +1106,10 @@
BinaryOpKind::Xor => match_bitwise! {
(lhs_value as lhs "^" rhs_value as rhs) => lhs ^ rhs
},
BinaryOpKind::ShiftRight => match_bitshift! {

Check warning on line 1109 in compiler/noirc_frontend/src/hir/comptime/interpreter.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (bitshift)
(lhs_value as lhs ">>" rhs_value as rhs) => lhs.checked_shr(rhs.into())
},
BinaryOpKind::ShiftLeft => match_bitshift! {

Check warning on line 1112 in compiler/noirc_frontend/src/hir/comptime/interpreter.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (bitshift)
(lhs_value as lhs "<<" rhs_value as rhs) => lhs.checked_shl(rhs.into())
},
BinaryOpKind::Modulo => match_integer! {
Expand Down Expand Up @@ -1369,33 +1366,6 @@
});
}

fn evaluate_method_call(
&mut self,
call: HirMethodCallExpression,
id: ExprId,
) -> IResult<Value> {
let object = self.evaluate(call.object)?;
let arguments = try_vecmap(call.arguments, |arg| {
Ok((self.evaluate(arg)?, self.elaborator.interner.expr_location(&arg)))
})?;
let location = self.elaborator.interner.expr_location(&id);

let typ = object.get_type().follow_bindings();
let method_name = &call.method.0.contents;
let check_self_param = true;

let method = self
.elaborator
.lookup_method(&typ, method_name, location, check_self_param)
.and_then(|method| method.func_id(self.elaborator.interner));

if let Some(method) = method {
self.call_function(method, arguments, TypeBindings::new(), location)
} else {
Err(InterpreterError::NoMethodFound { name: method_name.clone(), typ, location })
}
}

fn evaluate_cast(&mut self, cast: &HirCastExpression, id: ExprId) -> IResult<Value> {
let evaluated_lhs = self.evaluate(cast.lhs)?;
let location = self.elaborator.interner.expr_location(&id);
Expand Down
2 changes: 0 additions & 2 deletions compiler/noirc_frontend/src/hir_def/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ pub enum HirExpression {
EnumConstructor(HirEnumConstructorExpression),
MemberAccess(HirMemberAccess),
Call(HirCallExpression),
MethodCall(HirMethodCallExpression),
Constrain(HirConstrainExpression),
Cast(HirCastExpression),
If(HirIfExpression),
Expand All @@ -43,7 +42,6 @@ pub enum HirExpression {
Lambda(HirLambda),
Quote(Tokens),
Unquote(Tokens),
Comptime(HirBlockExpression),
Unsafe(HirBlockExpression),
Error,
}
Expand Down
8 changes: 0 additions & 8 deletions compiler/noirc_frontend/src/monomorphization/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -606,19 +606,11 @@ impl<'interner> Monomorphizer<'interner> {

HirExpression::Lambda(lambda) => self.lambda(lambda, expr)?,

HirExpression::MethodCall(hir_method_call) => {
unreachable!(
"Encountered HirExpression::MethodCall during monomorphization {hir_method_call:?}"
)
}
HirExpression::Error => unreachable!("Encountered Error node during monomorphization"),
HirExpression::Quote(_) => unreachable!("quote expression remaining in runtime code"),
HirExpression::Unquote(_) => {
unreachable!("unquote expression remaining in runtime code")
}
HirExpression::Comptime(_) => {
unreachable!("comptime expression remaining in runtime code")
}
HirExpression::EnumConstructor(constructor) => {
self.enum_constructor(constructor, expr)?
}
Expand Down
Loading