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

feat: handwritten parser #6180

Merged
merged 235 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
235 commits
Select commit Hold shift + click to select a range
c9aedf8
Manual parser: use trees
asterite Sep 24, 2024
a8be03a
WIP: remove TODOs
asterite Sep 24, 2024
f447f46
Move some TODOs to the parser itself, and clean up code
asterite Sep 25, 2024
a028c16
No need to have TopLevelStatement
asterite Sep 25, 2024
f171369
parse_top_level_items -> parse_items
asterite Sep 25, 2024
e9dc76d
Some fixes
asterite Sep 25, 2024
363dce7
Parse item visibility
asterite Sep 25, 2024
e7fc2cf
Parse modules
asterite Sep 25, 2024
2f3c28d
Fix item visibility parsing issue
asterite Sep 25, 2024
b6247ff
Parse struct with generics
asterite Sep 25, 2024
7d95360
Parse struct fields
asterite Sep 25, 2024
5720460
Fix some bugs
asterite Sep 25, 2024
583a462
Parse globals
asterite Sep 25, 2024
93d0c22
Handle struct without name in document symbol
asterite Sep 25, 2024
768b4fb
Add pending error
asterite Sep 25, 2024
26a7a61
Some clippy
asterite Sep 25, 2024
df84945
Tiny refactor
asterite Sep 25, 2024
f38b202
Parse type alias
asterite Sep 25, 2024
e70d532
Parse a bit of functions
asterite Sep 25, 2024
99a5503
Add some more tests
asterite Sep 26, 2024
4ad2372
Refactor
asterite Sep 26, 2024
4ce8576
More patterns
asterite Sep 26, 2024
ca320ce
Some Path parsing
asterite Sep 26, 2024
fbd2451
Start parsing struct patterns
asterite Sep 26, 2024
8f5dd2f
Finish parsing patterns, and add some TODOs
asterite Sep 26, 2024
74a60e2
typo
asterite Sep 26, 2024
9acd5b3
Parse function return type
asterite Sep 26, 2024
0da3c3e
Parse function return visibility
asterite Sep 26, 2024
ca00a2f
TODO for parsing where clause
asterite Sep 26, 2024
d72f35d
Refactor type parsing
asterite Sep 26, 2024
5e3c894
Adjustments
asterite Sep 26, 2024
4671572
Some type parsing
asterite Sep 26, 2024
41ed799
Parse some more expressions
asterite Sep 26, 2024
19ea2c6
Fix FunctionDefinition::to_string() duplicating `fn` keyword
asterite Sep 26, 2024
5754dca
Parse bool literals
asterite Sep 26, 2024
f38f2c2
Parse empty impls
asterite Sep 26, 2024
7089c35
Parse impls
asterite Sep 26, 2024
47d7b52
Avoid looping forever
asterite Sep 26, 2024
e9510f4
Start producing and testing errors
asterite Sep 26, 2024
4e0cf28
Produce a couple more errors
asterite Sep 26, 2024
50455b4
A couple more errors
asterite Sep 26, 2024
587a533
Move error up
asterite Sep 26, 2024
c4fe05f
Don't fail document symbol on empty function name
asterite Sep 26, 2024
e069b90
Some more error handling
asterite Sep 26, 2024
434ac88
Parse self pattern
asterite Sep 26, 2024
60316b1
Parse empty trait impl
asterite Sep 26, 2024
78a430c
Parse trait impl method
asterite Sep 26, 2024
18910a9
Clippy
asterite Sep 26, 2024
11d2e70
Parse turbofish in Path
asterite Sep 27, 2024
dab7104
Parse generic type args
asterite Sep 27, 2024
d37d13c
Parse trait impl type
asterite Sep 27, 2024
ed82959
Parse where clause
asterite Sep 27, 2024
4f09b09
Handle more empty cases in document symbol
asterite Sep 27, 2024
7010576
Clippy
asterite Sep 27, 2024
f013d50
Adjust some spans
asterite Sep 27, 2024
4c90f43
Parse empty traits
asterite Sep 27, 2024
1020735
Parse trait type
asterite Sep 27, 2024
4cb842b
Parse trait constant
asterite Sep 27, 2024
75c5fb3
Parse trait functions
asterite Sep 27, 2024
bcf1539
Refactor to parse function modifiers in a single place/way
asterite Sep 27, 2024
19e5cd5
Parse trait impl constants
asterite Sep 27, 2024
aa0a058
Fix some spans
asterite Sep 27, 2024
4236b2e
Always check errors
asterite Sep 27, 2024
2a177fe
Some helpers to test errors and their spans
asterite Sep 27, 2024
0607a9f
Errors for item visibility
asterite Sep 27, 2024
9084e7c
Some errors
asterite Sep 27, 2024
4f02169
Parse slice and array type
asterite Sep 27, 2024
b65d53e
Parse string literals
asterite Sep 27, 2024
f20bafb
Handle one more error
asterite Sep 27, 2024
913f62f
Parse array literals
asterite Sep 27, 2024
cf9e709
Parse slices
asterite Sep 27, 2024
22baad5
About to start parsing statements
asterite Sep 27, 2024
1677124
Parse let statement
asterite Sep 27, 2024
6219dce
Parse break and continue
asterite Sep 27, 2024
17f4074
Parse interned statements
asterite Sep 27, 2024
f3f389f
Parse multiple statements in block
asterite Sep 27, 2024
66b0d21
Parse assert and assert_eq
asterite Sep 27, 2024
a1a1931
Parse constrain
asterite Sep 27, 2024
f5c448c
Parse variable
asterite Sep 27, 2024
f185750
Parse mutable reference
asterite Sep 27, 2024
6262040
Parse unsafe expression
asterite Sep 27, 2024
b407ad6
Parse quote
asterite Sep 27, 2024
b01d0a6
Start parsing expressions the correct way, and introduce look-ahead
asterite Sep 27, 2024
6952452
Parse all prefix expressions
asterite Sep 27, 2024
407e84e
Parse macro calls too
asterite Sep 27, 2024
b3d6355
Parse member access
asterite Sep 27, 2024
5cd0057
Parse method calls
asterite Sep 27, 2024
611e5ee
Parse turbofish
asterite Sep 27, 2024
3ebbec2
Fix bug parsing turbofish
asterite Sep 27, 2024
48a15a9
Some adjustments
asterite Sep 27, 2024
f042540
Parse constructors
asterite Sep 27, 2024
f51b5cc
Apparently `struct Foo;` is valid syntax
asterite Sep 27, 2024
29e8137
Parse type expression in generic type args
asterite Sep 27, 2024
e888d5a
Parse some primitive types
asterite Sep 28, 2024
1c4592e
Parse interned and resolved types
asterite Sep 28, 2024
028a6db
Refactor
asterite Sep 28, 2024
7668331
Parse if expression
asterite Sep 28, 2024
7e658dd
Parse comptime block statement
asterite Sep 28, 2024
90cd320
Parse comptime let
asterite Sep 28, 2024
1cd28c1
Parse cast
asterite Sep 28, 2024
57b38bf
Handle missing type after `as`
asterite Sep 28, 2024
2c687e1
Better way to parse types
asterite Sep 28, 2024
490dc67
Better way to parse expressions
asterite Sep 28, 2024
ff703e7
Better way to parse statements
asterite Sep 28, 2024
9852c96
Parse index expression
asterite Sep 28, 2024
c2b1f92
Parse type expressions in a better way
asterite Sep 28, 2024
4aac1c9
Refactor
asterite Sep 28, 2024
ad58443
Interned and resolved exprs
asterite Sep 28, 2024
4ba8429
Parse lambdas
asterite Sep 28, 2024
0a2e7d5
Parse for
asterite Sep 28, 2024
cf5d20f
Parse comptime for
asterite Sep 28, 2024
f8db9fa
Have two look-ahead tokens
asterite Sep 28, 2024
7cb910d
Prepare to parse assignments
asterite Sep 28, 2024
e40c204
Parse assignments
asterite Sep 28, 2024
0115c28
Parse op assign
asterite Sep 28, 2024
b114fc0
One look-ahead token is enough
asterite Sep 28, 2024
7ff2940
Some refactors
asterite Sep 28, 2024
e6ebd5b
Parse function type
asterite Sep 28, 2024
6315eeb
Function type fixes
asterite Sep 28, 2024
32f1f6b
Parse trait as type
asterite Sep 28, 2024
5d63cdc
Parse AsTraitPath
asterite Sep 28, 2024
1a9f62a
Fix parsing of negative literals
asterite Sep 28, 2024
c71c86d
Parse format string type
asterite Sep 29, 2024
d0827b8
Parse comptime expr
asterite Sep 29, 2024
ea39d9d
Parse type path
asterite Sep 29, 2024
6037200
Parse unquote expr
asterite Sep 29, 2024
96b6cf3
Fix path with turbofish parsing
asterite Sep 29, 2024
2f3d022
Use correct error message
asterite Sep 29, 2024
3189527
Semicolon after type alias
asterite Sep 29, 2024
997de9c
Make sure we parse expressions until end of string
asterite Sep 29, 2024
b7fac93
Parse attributes on impl method
asterite Sep 29, 2024
7d47012
Also parse attributes on trait impl function
asterite Sep 29, 2024
904011f
Recover from parsing non-item token
asterite Sep 29, 2024
176fa02
Fix impl self type in method followed by colon type
asterite Sep 29, 2024
edd7da3
Parse if and block statements
asterite Sep 29, 2024
5a40809
Parse return statement
asterite Sep 29, 2024
b7c1283
More fixes
asterite Sep 29, 2024
6cf0423
Parse path stop before trailing double colon
asterite Sep 29, 2024
f6226d5
More fixes
asterite Sep 29, 2024
de5106f
More type expressions
asterite Sep 29, 2024
4f6286f
Don't parse `()` in parenthesized expression
asterite Sep 29, 2024
7cac16a
Will implement parse_type_or_type_expression next
asterite Sep 29, 2024
db40e9b
Parse type or type expression
asterite Sep 29, 2024
f74a1d2
Better way to parse path
asterite Sep 29, 2024
8ac98cc
LValue for parentheses
asterite Sep 29, 2024
a3b68ff
Some error handling
asterite Sep 30, 2024
23a3afd
A bit more
asterite Sep 30, 2024
4ca22f1
Sometimes allow trailing colons in path
asterite Sep 30, 2024
e1b242a
Fix LSP test
asterite Sep 30, 2024
62b6673
Simplify function body parsing
asterite Sep 30, 2024
7d597b2
Adjust statement span to include the semicolon
asterite Sep 30, 2024
7b9558a
Fix span of `mut self` and `&mut self` patterns
asterite Sep 30, 2024
b6871ac
Some span fixes
asterite Sep 30, 2024
fb0dac9
Fix unsafe span
asterite Sep 30, 2024
81edc43
All nargo fmt tests now pass
asterite Sep 30, 2024
4cd0397
Fix document symbol test
asterite Sep 30, 2024
65d71db
More fixes
asterite Sep 30, 2024
51cda47
Don't rely on spans for parsing
asterite Sep 30, 2024
0996a29
Parser type or type expression tuple of size 1
asterite Sep 30, 2024
a6030c3
Handle a few more errors
asterite Sep 30, 2024
7e1445a
Merge branch 'master' into ab/parser
asterite Sep 30, 2024
bf5a856
Fix attributes parsing
asterite Sep 30, 2024
a788408
Use parsing rule label
asterite Sep 30, 2024
86976ce
More errors
asterite Sep 30, 2024
9ed0113
Remove TODO
asterite Sep 30, 2024
7cde89e
More errors
asterite Sep 30, 2024
ba74236
Clippy
asterite Sep 30, 2024
557bc27
Fix parser test
asterite Sep 30, 2024
552da43
Fix formatting of `self: Self`
asterite Sep 30, 2024
f6eeafa
clippy
asterite Sep 30, 2024
9ab6d2a
Fix the formatter bug for real
asterite Sep 30, 2024
f2d3e0f
Correct way to detect SelfPattern
asterite Oct 1, 2024
1544848
Take care of the remaining error cases
asterite Oct 1, 2024
900a3f9
Merge branch 'master' into ab/parser
TomAFrench Oct 1, 2024
b7651f4
Some recovery for items and structs
asterite Oct 1, 2024
4854662
Recover on unknown impl item
asterite Oct 1, 2024
d13487d
Recover un known trait impl item
asterite Oct 1, 2024
46c55be
Statement recovery
asterite Oct 1, 2024
1afbafb
`mod` parsing recovery
asterite Oct 1, 2024
95d2647
Fix missing error
asterite Oct 1, 2024
e5e735d
Errors clean up
asterite Oct 1, 2024
c94fbd6
Clean up more errors
asterite Oct 1, 2024
96fd3bd
Bring back `ExpectedFieldName`
asterite Oct 1, 2024
37bbdef
Bring back ExpectedPatternButFoundType
asterite Oct 1, 2024
021ead8
Apparently function pattern recovery was already done
asterite Oct 1, 2024
4941905
Some more recovery
asterite Oct 1, 2024
54ec3e5
Merge branch 'master' into ab/parser
asterite Oct 1, 2024
83448f3
cargo fmt
asterite Oct 1, 2024
8a76f2f
Let `crate::`, etc., error and return no Path
asterite Oct 1, 2024
4ad85dd
Add some comments
asterite Oct 1, 2024
ad89c0a
Make it more readable
asterite Oct 1, 2024
fcc6291
Test that crate isn't allowed in sub-trees in use
asterite Oct 1, 2024
2e0c1fb
Simplify parse_atom_or_unary_right
asterite Oct 2, 2024
411a970
parse_block_expression -> parse_block
asterite Oct 2, 2024
5d4b464
Document the grammar of expressions
asterite Oct 2, 2024
6b33cdd
Document attributes and arguments grammar
asterite Oct 2, 2024
5671c66
A bit more grammar
asterite Oct 2, 2024
78d28cc
More grammar
asterite Oct 2, 2024
d02a531
More grammar
asterite Oct 2, 2024
b0c6750
A bit more grammar
asterite Oct 2, 2024
45ad222
A bit more
asterite Oct 2, 2024
bcc6663
Finalize the grammar
asterite Oct 2, 2024
c44854b
Merge branch 'master' into ab/parser
asterite Oct 2, 2024
97c2ba0
Small fix to grammar
asterite Oct 2, 2024
2884e3e
Improve a bit the grammar
asterite Oct 2, 2024
01d921e
Improve the grammar a bit more
asterite Oct 2, 2024
109bed6
Add a few more comments
asterite Oct 2, 2024
3322f81
Refactor and introduce CallArguments
asterite Oct 3, 2024
6bbf964
Reduce duplication when parsing infix expressions
asterite Oct 3, 2024
1652b6e
Merge branch 'master' into ab/parser
asterite Oct 3, 2024
1b1fbad
Merge branch 'master' into ab/parser
asterite Oct 4, 2024
b57c371
Introduce `parse_many` to reduce code duplication
asterite Oct 4, 2024
d98b3ca
Let error take Token, and one more use of `parse_many`
asterite Oct 4, 2024
8631a0c
parse_many without separator
asterite Oct 4, 2024
601f3a7
parse_item_in_list
asterite Oct 4, 2024
888abbd
Rename variable for clarity
asterite Oct 4, 2024
7122549
Check double colon after path kind in one place
asterite Oct 5, 2024
9978131
A bit more grammar
asterite Oct 5, 2024
728f3ad
Make sure file is formatted by test
asterite Oct 7, 2024
7337d88
Better test for checking operator precedence
asterite Oct 7, 2024
ebd9ff2
Remove Default from Token and Spanned
asterite Oct 7, 2024
3f712d0
next_token -> bump
asterite Oct 7, 2024
5d035f3
Remove `tokens_follow`
asterite Oct 7, 2024
c50fad4
Update compiler/noirc_frontend/src/parser/parser/generics.rs
asterite Oct 7, 2024
00fdb18
Update compiler/noirc_frontend/src/parser/parser/generics.rs
asterite Oct 7, 2024
458dae1
Update compiler/noirc_frontend/src/parser/parser/generics.rs
asterite Oct 7, 2024
26d0c85
Update compiler/noirc_frontend/src/parser/parser/generics.rs
asterite Oct 7, 2024
b1857b0
Don't use default span in one place
asterite Oct 7, 2024
f7fcbfa
Add a comment about using `pop`
asterite Oct 7, 2024
46aa738
Clarify comment
asterite Oct 7, 2024
256294e
Use parse_many in three more places
asterite Oct 7, 2024
3effe9f
Remove a lot of code duplication from tests
asterite Oct 7, 2024
2fb31a4
Apply suggestions from code review
asterite Oct 7, 2024
cb3d321
Introduce `parse_option` and make it and `parse_result` Parser methods
asterite Oct 7, 2024
279c8d2
Remove `parse_modifier`
asterite Oct 7, 2024
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
35 changes: 2 additions & 33 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,6 @@ clap = { version = "4.3.19", features = ["derive", "env"] }
codespan = { version = "0.11.1", features = ["serialization"] }
codespan-lsp = "0.11.1"
codespan-reporting = "0.11.1"
chumsky = { git = "https://github.com/jfecher/chumsky", rev = "ad9d312", default-features = false, features = [
"ahash",
"std",
] }

# Benchmarking
criterion = "0.5.0"
Expand Down
1 change: 0 additions & 1 deletion compiler/noirc_errors/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ acvm.workspace = true
codespan-reporting.workspace = true
codespan.workspace = true
fm.workspace = true
chumsky.workspace = true
noirc_printable_type.workspace = true
serde.workspace = true
serde_with = "3.2.0"
Expand Down
22 changes: 1 addition & 21 deletions compiler/noirc_errors/src/position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{

pub type Position = u32;

#[derive(PartialOrd, Eq, Ord, Debug, Clone)]
#[derive(PartialOrd, Eq, Ord, Debug, Clone, Default)]
pub struct Spanned<T> {
pub contents: T,
span: Span,
Expand Down Expand Up @@ -121,26 +121,6 @@ impl From<Range<u32>> for Span {
}
}

impl chumsky::Span for Span {
type Context = ();

type Offset = u32;

fn new(_context: Self::Context, range: Range<Self::Offset>) -> Self {
Span(ByteSpan::from(range))
}

fn context(&self) -> Self::Context {}

fn start(&self) -> Self::Offset {
self.start()
}

fn end(&self) -> Self::Offset {
self.end()
}
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Deserialize, Serialize)]
pub struct Location {
pub span: Span,
Expand Down
1 change: 0 additions & 1 deletion compiler/noirc_frontend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ noirc_errors.workspace = true
noirc_printable_type.workspace = true
fm.workspace = true
iter-extended.workspace = true
chumsky.workspace = true
thiserror.workspace = true
smol_str.workspace = true
im.workspace = true
Expand Down
3 changes: 2 additions & 1 deletion compiler/noirc_frontend/src/ast/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ impl Expression {
pub type BinaryOp = Spanned<BinaryOpKind>;

#[derive(PartialEq, PartialOrd, Eq, Ord, Hash, Debug, Copy, Clone)]
#[cfg_attr(test, derive(strum_macros::EnumIter))]
pub enum BinaryOpKind {
Add,
Subtract,
Expand Down Expand Up @@ -873,7 +874,7 @@ impl FunctionDefinition {
impl Display for FunctionDefinition {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
writeln!(f, "{:?}", self.attributes)?;
write!(f, "fn {} {}", self.signature(), self.body)
write!(f, "{} {}", self.signature(), self.body)
}
}

Expand Down
57 changes: 27 additions & 30 deletions compiler/noirc_frontend/src/ast/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ impl StatementKind {
}
}

#[derive(Eq, Debug, Clone)]
#[derive(Eq, Debug, Clone, Default)]
pub struct Ident(pub Spanned<String>);

impl Ident {
Expand Down Expand Up @@ -333,12 +333,12 @@ impl Display for UseTree {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.prefix)?;

if !self.prefix.segments.is_empty() {
write!(f, "::")?;
}

match &self.kind {
UseTreeKind::Path(name, alias) => {
if !(self.prefix.segments.is_empty() && self.prefix.kind == PathKind::Plain) {
write!(f, "::")?;
}

write!(f, "{name}")?;

if let Some(alias) = alias {
Expand All @@ -348,7 +348,7 @@ impl Display for UseTree {
Ok(())
}
UseTreeKind::List(trees) => {
write!(f, "::{{")?;
write!(f, "{{")?;
let tree = vecmap(trees, ToString::to_string).join(", ");
write!(f, "{tree}}}")
}
Expand Down Expand Up @@ -467,7 +467,9 @@ impl Path {
}

pub fn is_ident(&self) -> bool {
self.segments.len() == 1 && self.kind == PathKind::Plain
self.kind == PathKind::Plain
&& self.segments.len() == 1
&& self.segments.first().unwrap().generics.is_none()
}

pub fn as_ident(&self) -> Option<&Ident> {
Expand All @@ -484,6 +486,10 @@ impl Path {
self.segments.first().cloned().map(|segment| segment.ident)
}

pub fn is_empty(&self) -> bool {
self.segments.is_empty() && self.kind == PathKind::Plain
}

pub fn as_string(&self) -> String {
let mut string = String::new();

Expand Down Expand Up @@ -650,14 +656,6 @@ impl Pattern {
}
}

pub(crate) fn into_ident(self) -> Ident {
match self {
Pattern::Identifier(ident) => ident,
Pattern::Mutable(pattern, _, _) => pattern.into_ident(),
other => panic!("Pattern::into_ident called on {other} pattern with no identifier"),
}
}

pub(crate) fn try_as_expression(&self, interner: &NodeInterner) -> Option<Expression> {
match self {
Pattern::Identifier(ident) => Some(Expression {
Expand Down Expand Up @@ -726,37 +724,36 @@ impl LValue {
Expression::new(kind, span)
}

pub fn from_expression(expr: Expression) -> LValue {
pub fn from_expression(expr: Expression) -> Option<LValue> {
LValue::from_expression_kind(expr.kind, expr.span)
}

pub fn from_expression_kind(expr: ExpressionKind, span: Span) -> LValue {
pub fn from_expression_kind(expr: ExpressionKind, span: Span) -> Option<LValue> {
match expr {
ExpressionKind::Variable(path) => LValue::Ident(path.as_ident().unwrap().clone()),
ExpressionKind::MemberAccess(member_access) => LValue::MemberAccess {
object: Box::new(LValue::from_expression(member_access.lhs)),
ExpressionKind::Variable(path) => Some(LValue::Ident(path.as_ident().unwrap().clone())),
ExpressionKind::MemberAccess(member_access) => Some(LValue::MemberAccess {
object: Box::new(LValue::from_expression(member_access.lhs)?),
field_name: member_access.rhs,
span,
},
ExpressionKind::Index(index) => LValue::Index {
array: Box::new(LValue::from_expression(index.collection)),
}),
ExpressionKind::Index(index) => Some(LValue::Index {
array: Box::new(LValue::from_expression(index.collection)?),
index: index.index,
span,
},
}),
ExpressionKind::Prefix(prefix) => {
if matches!(
prefix.operator,
crate::ast::UnaryOp::Dereference { implicitly_added: false }
) {
LValue::Dereference(Box::new(LValue::from_expression(prefix.rhs)), span)
Some(LValue::Dereference(Box::new(LValue::from_expression(prefix.rhs)?), span))
} else {
panic!("Called LValue::from_expression with an invalid prefix operator")
None
}
}
ExpressionKind::Interned(id) => LValue::Interned(id, span),
_ => {
panic!("Called LValue::from_expression with an invalid expression")
}
ExpressionKind::Parenthesized(expr) => LValue::from_expression(*expr),
ExpressionKind::Interned(id) => Some(LValue::Interned(id, span)),
_ => None,
}
}

Expand Down
19 changes: 18 additions & 1 deletion compiler/noirc_frontend/src/ast/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,24 @@ impl Display for TraitBound {

impl Display for NoirTraitImpl {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
writeln!(f, "impl {}{} for {} {{", self.trait_name, self.trait_generics, self.object_type)?;
write!(f, "impl")?;
if !self.impl_generics.is_empty() {
write!(
f,
"<{}>",
self.impl_generics.iter().map(ToString::to_string).collect::<Vec<_>>().join(", ")
)?;
}

write!(f, " {}{} for {}", self.trait_name, self.trait_generics, self.object_type)?;
if !self.where_clause.is_empty() {
write!(
f,
" where {}",
self.where_clause.iter().map(ToString::to_string).collect::<Vec<_>>().join(", ")
)?;
}
writeln!(f, "{{")?;

for item in self.items.iter() {
let item = item.to_string();
Expand Down
3 changes: 2 additions & 1 deletion compiler/noirc_frontend/src/debug/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::ast::PathSegment;
use crate::parser::{parse_program, ParsedModule};
use crate::parse_program;
use crate::parser::ParsedModule;
use crate::{
ast,
ast::{Path, PathKind},
Expand Down Expand Up @@ -288,7 +289,7 @@
}
ast::LValue::Dereference(_lv, span) => {
// TODO: this is a dummy statement for now, but we should
// somehow track the derefence and update the pointed to

Check warning on line 292 in compiler/noirc_frontend/src/debug/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (derefence)
// variable
ast::Statement {
kind: ast::StatementKind::Expression(uint_expr(0, *span)),
Expand Down Expand Up @@ -674,9 +675,9 @@
ast::Pattern::Tuple(patterns, _) => {
stack.extend(patterns.iter().map(|pattern| (pattern, false)));
}
ast::Pattern::Struct(_, pids, _) => {

Check warning on line 678 in compiler/noirc_frontend/src/debug/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (pids)
stack.extend(pids.iter().map(|(_, pattern)| (pattern, is_mut)));

Check warning on line 679 in compiler/noirc_frontend/src/debug/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (pids)
vars.extend(pids.iter().map(|(id, _)| (id.clone(), false)));

Check warning on line 680 in compiler/noirc_frontend/src/debug/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (pids)
}
ast::Pattern::Interned(_, _) => (),
}
Expand All @@ -687,7 +688,7 @@
fn pattern_to_string(pattern: &ast::Pattern) -> String {
match pattern {
ast::Pattern::Identifier(id) => id.0.contents.clone(),
ast::Pattern::Mutable(mpat, _, _) => format!("mut {}", pattern_to_string(mpat.as_ref())),

Check warning on line 691 in compiler/noirc_frontend/src/debug/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (mpat)

Check warning on line 691 in compiler/noirc_frontend/src/debug/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (mpat)
ast::Pattern::Tuple(elements, _) => format!(
"({})",
elements.iter().map(pattern_to_string).collect::<Vec<String>>().join(", ")
Expand Down
Loading
Loading