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 types and functions in the AST #7339

Merged
merged 1 commit into from
Feb 11, 2025
Merged
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
45 changes: 1 addition & 44 deletions compiler/noirc_frontend/src/ast/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use acvm::{acir::AcirField, FieldElement};
use iter_extended::vecmap;
use noirc_errors::{Span, Spanned};

use super::{AsTraitPath, TypePath, UnaryRhsMemberAccess};
use super::{AsTraitPath, TypePath};

#[derive(Debug, PartialEq, Eq, Clone)]
pub enum ExpressionKind {
Expand Down Expand Up @@ -245,49 +245,6 @@ impl Expression {
pub fn new(kind: ExpressionKind, span: Span) -> Expression {
Expression { kind, span }
}

pub fn member_access_or_method_call(
lhs: Expression,
rhs: UnaryRhsMemberAccess,
span: Span,
) -> Expression {
let kind = match rhs.method_call {
None => {
let rhs = rhs.method_or_field;
ExpressionKind::MemberAccess(Box::new(MemberAccessExpression { lhs, rhs }))
}
Some(method_call) => ExpressionKind::MethodCall(Box::new(MethodCallExpression {
object: lhs,
method_name: rhs.method_or_field,
generics: method_call.turbofish,
arguments: method_call.args,
is_macro_call: method_call.macro_call,
})),
};
Expression::new(kind, span)
}

pub fn index(collection: Expression, index: Expression, span: Span) -> Expression {
let kind = ExpressionKind::Index(Box::new(IndexExpression { collection, index }));
Expression::new(kind, span)
}

pub fn cast(lhs: Expression, r#type: UnresolvedType, span: Span) -> Expression {
let kind = ExpressionKind::Cast(Box::new(CastExpression { lhs, r#type }));
Expression::new(kind, span)
}

pub fn call(
lhs: Expression,
is_macro_call: bool,
arguments: Vec<Expression>,
span: Span,
) -> Expression {
let func = Box::new(lhs);
let kind =
ExpressionKind::Call(Box::new(CallExpression { func, is_macro_call, arguments }));
Expression::new(kind, span)
}
}

pub type BinaryOp = Spanned<BinaryOpKind>;
Expand Down
12 changes: 0 additions & 12 deletions compiler/noirc_frontend/src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,18 +225,6 @@
}
}

/// Type wrapper for a member access
pub struct UnaryRhsMemberAccess {
pub method_or_field: Ident,
pub method_call: Option<UnaryRhsMethodCall>,
}

pub struct UnaryRhsMethodCall {
pub turbofish: Option<Vec<UnresolvedType>>,
pub macro_call: bool,
pub args: Vec<Expression>,
}

/// The precursor to TypeExpression, this is the type that the parser allows
/// to be used in the length position of an array type. Only constant integers, variables,
/// and numeric binary operators are allowed here.
Expand Down Expand Up @@ -597,7 +585,7 @@
Self::Public => write!(f, "pub"),
Self::Private => write!(f, "priv"),
Self::CallData(id) => write!(f, "calldata{id}"),
Self::ReturnData => write!(f, "returndata"),

Check warning on line 588 in compiler/noirc_frontend/src/ast/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (returndata)
}
}
}
24 changes: 0 additions & 24 deletions compiler/noirc_frontend/src/ast/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,30 +154,6 @@ impl StatementKind {
attributes,
})
}

/// Create a Statement::Assign value, desugaring any combined operators like += if needed.
pub fn assign(
lvalue: LValue,
operator: Token,
mut expression: Expression,
span: Span,
) -> StatementKind {
// Desugar `a <op>= b` to `a = a <op> b`. This relies on the evaluation of `a` having no side effects,
// which is currently enforced by the restricted syntax of LValues.
if operator != Token::Assign {
let lvalue_expr = lvalue.as_expression();
let error_msg = "Token passed to Statement::assign is not a binary operator";

let infix = crate::ast::InfixExpression {
lhs: lvalue_expr,
operator: operator.try_into_binary_op(span).expect(error_msg),
rhs: expression,
};
expression = Expression::new(ExpressionKind::Infix(Box::new(infix)), span);
}

StatementKind::Assign(AssignStatement { lvalue, expression })
}
}

#[derive(Eq, Debug, Clone, Default)]
Expand Down
12 changes: 0 additions & 12 deletions compiler/noirc_frontend/src/ast/type_alias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,6 @@ pub struct NoirTypeAlias {
pub span: Span,
}

impl NoirTypeAlias {
pub fn new(
name: Ident,
generics: UnresolvedGenerics,
typ: UnresolvedType,
visibility: ItemVisibility,
span: Span,
) -> NoirTypeAlias {
NoirTypeAlias { name, generics, typ, visibility, span }
}
}

impl Display for NoirTypeAlias {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let generics = vecmap(&self.generics, |generic| generic.to_string());
Expand Down
Loading