From 9c63fe84d1fac12d7f222d96f92b56390bec926c Mon Sep 17 00:00:00 2001 From: alejandro baranek Date: Fri, 31 May 2024 17:30:43 -0300 Subject: [PATCH 1/3] [refactor] Proposed improved AST variables convention --- crates/concrete_ast/src/expressions.rs | 8 +-- crates/concrete_ast/src/statements.rs | 20 +++--- crates/concrete_check/src/linearity_check.rs | 54 ++++++++--------- crates/concrete_ir/src/lowering.rs | 38 ++++++------ crates/concrete_parser/src/grammar.lalrpop | 64 ++++++++++---------- 5 files changed, 92 insertions(+), 92 deletions(-) diff --git a/crates/concrete_ast/src/expressions.rs b/crates/concrete_ast/src/expressions.rs index 818c666..9cdc0e6 100644 --- a/crates/concrete_ast/src/expressions.rs +++ b/crates/concrete_ast/src/expressions.rs @@ -99,16 +99,16 @@ pub enum BitwiseOp { #[derive(Clone, Debug, Eq, PartialEq)] pub struct MatchExpr { - pub value: Box, + pub match_expr: Box, pub variants: Vec, pub span: Span, } #[derive(Clone, Debug, Eq, PartialEq)] pub struct IfExpr { - pub value: Box, - pub contents: Vec, - pub r#else: Option>, + pub cond: Box, + pub block_stmts: Vec, + pub else_stmts: Option>, pub span: Span, } diff --git a/crates/concrete_ast/src/statements.rs b/crates/concrete_ast/src/statements.rs index f836281..bb1c058 100644 --- a/crates/concrete_ast/src/statements.rs +++ b/crates/concrete_ast/src/statements.rs @@ -18,15 +18,15 @@ pub enum Statement { #[derive(Clone, Debug, Eq, PartialEq)] pub enum LetStmtTarget { - Simple { name: Ident, r#type: TypeSpec }, + Simple { id: Ident, r#type: TypeSpec }, Destructure(Vec), } #[derive(Clone, Debug, Eq, PartialEq)] pub struct LetStmt { pub is_mutable: bool, - pub target: LetStmtTarget, - pub value: Expression, + pub lvalue: LetStmtTarget, + pub rvalue: Expression, pub span: Span, } @@ -38,15 +38,15 @@ pub struct ReturnStmt { #[derive(Clone, Debug, Eq, PartialEq)] pub struct AssignStmt { - pub target: PathOp, + pub lvalue: PathOp, pub derefs: usize, - pub value: Expression, + pub rvalue: Expression, pub span: Span, } #[derive(Clone, Debug, Eq, Hash, PartialEq)] pub struct Binding { - pub name: Ident, + pub id: Ident, pub rename: Option, pub r#type: TypeSpec, } @@ -54,14 +54,14 @@ pub struct Binding { #[derive(Clone, Debug, Eq, PartialEq)] pub struct ForStmt { pub init: Option, - pub condition: Option, + pub cond: Option, pub post: Option, - pub contents: Vec, + pub block_stmts: Vec, pub span: Span, } #[derive(Clone, Debug, Eq, PartialEq)] pub struct WhileStmt { - pub value: Expression, - pub contents: Vec, + pub cond: Expression, + pub block_stmts: Vec, } diff --git a/crates/concrete_check/src/linearity_check.rs b/crates/concrete_check/src/linearity_check.rs index 4098018..f8e24fb 100644 --- a/crates/concrete_check/src/linearity_check.rs +++ b/crates/concrete_check/src/linearity_check.rs @@ -324,14 +324,14 @@ impl LinearityChecker { match statement { Statement::Let(binding) => { // Handle let bindings, possibly involving pattern matching - self.count_in_expression(name, &binding.value) + self.count_in_expression(name, &binding.rvalue) } Statement::If(if_stmt) => { // Process all components of an if expression - let cond_apps = self.count_in_expression(name, &if_stmt.value); - let then_apps = self.count_in_statements(name, &if_stmt.contents); + let cond_apps = self.count_in_expression(name, &if_stmt.cond); + let then_apps = self.count_in_statements(name, &if_stmt.block_stmts); let else_apps; - let else_statements = &if_stmt.r#else; + let else_statements = &if_stmt.else_stmts; if let Some(else_statements) = else_statements { else_apps = self.count_in_statements(name, else_statements); } else { @@ -340,8 +340,8 @@ impl LinearityChecker { cond_apps.merge(&then_apps).merge(&else_apps) } Statement::While(while_expr) => { - let cond = &while_expr.value; - let block = &while_expr.contents; + let cond = &while_expr.cond; + let block = &while_expr.block_stmts; // Handle while loops self.count_in_expression(name, cond) .merge(&self.count_in_statements(name, block)) @@ -350,9 +350,9 @@ impl LinearityChecker { // Handle for loops //init, cond, post, block let init = &for_expr.init; - let cond = &for_expr.condition; + let cond = &for_expr.cond; let post = &for_expr.post; - let block = &for_expr.contents; + let block = &for_expr.block_stmts; let mut apps = Appearances::zero(); if let Some(init) = init { if let Some(cond) = cond { @@ -396,9 +396,9 @@ impl LinearityChecker { fn count_in_assign_statement(&self, name: &str, assign_stmt: &AssignStmt) -> Appearances { let AssignStmt { - target, + lvalue: target, derefs, - value, + rvalue: value, span, } = assign_stmt; // Handle assignments @@ -422,8 +422,8 @@ impl LinearityChecker { fn count_in_let_statements(&self, name: &str, let_stmt: &LetStmt) -> Appearances { let LetStmt { is_mutable, - target, - value, + lvalue: target, + rvalue: value, span, } = let_stmt; self.count_in_expression(name, value) @@ -466,10 +466,10 @@ impl LinearityChecker { Expression::If(if_expr) => { // Process all components of an if expression // TODO review this code. If expressions should be processed counting both branches and comparing them - let cond_apps = self.count_in_expression(name, &if_expr.value); - let then_apps = self.count_in_statements(name, &if_expr.contents); + let cond_apps = self.count_in_expression(name, &if_expr.cond); + let then_apps = self.count_in_statements(name, &if_expr.block_stmts); cond_apps.merge(&then_apps); - if let Some(else_block) = &if_expr.r#else { + if let Some(else_block) = &if_expr.else_stmts { let else_apps = self.count_in_statements(name, else_block); cond_apps.merge(&then_apps).merge(&else_apps); } @@ -524,12 +524,12 @@ impl LinearityChecker { // Handle let bindings, possibly involving pattern matching let LetStmt { is_mutable, - target, - value, + lvalue: target, + rvalue: value, span, } = binding; match target { - LetStmtTarget::Simple { name, r#type } => { + LetStmtTarget::Simple { id: name, r#type } => { match r#type { TypeSpec::Simple { name: variable_type, @@ -702,9 +702,9 @@ impl LinearityChecker { //Statement::If(cond, then_block, else_block) => { Statement::If(if_stmt) => { // Handle conditional statements - state_tbl = self.check_expr(state_tbl, depth, &if_stmt.value, context)?; - state_tbl = self.check_stmts(state_tbl, depth + 1, &if_stmt.contents, context)?; - if let Some(else_block) = &if_stmt.r#else { + state_tbl = self.check_expr(state_tbl, depth, &if_stmt.cond, context)?; + state_tbl = self.check_stmts(state_tbl, depth + 1, &if_stmt.block_stmts, context)?; + if let Some(else_block) = &if_stmt.else_stmts { state_tbl = self.check_stmts(state_tbl, depth + 1, else_block, context)?; } Ok(state_tbl) @@ -712,9 +712,9 @@ impl LinearityChecker { //Statement::While(cond, block) => { Statement::While(while_stmt) => { // Handle while loops - state_tbl = self.check_expr(state_tbl, depth, &while_stmt.value, context)?; + state_tbl = self.check_expr(state_tbl, depth, &while_stmt.cond, context)?; state_tbl = - self.check_stmts(state_tbl, depth + 1, &while_stmt.contents, context)?; + self.check_stmts(state_tbl, depth + 1, &while_stmt.block_stmts, context)?; Ok(state_tbl) } //Statement::For(init, cond, post, block) => { @@ -723,22 +723,22 @@ impl LinearityChecker { if let Some(init) = &for_stmt.init { state_tbl = self.check_stmt_let(state_tbl, depth, init, context)?; } - if let Some(condition) = &for_stmt.condition { + if let Some(condition) = &for_stmt.cond { state_tbl = self.check_expr(state_tbl, depth, condition, context)?; } if let Some(post) = &for_stmt.post { //TODO check assign statement //self.check_stmt_assign(depth, post)?; } - state_tbl = self.check_stmts(state_tbl, depth + 1, &for_stmt.contents, context)?; + state_tbl = self.check_stmts(state_tbl, depth + 1, &for_stmt.block_stmts, context)?; Ok(state_tbl) } Statement::Assign(assign_stmt) => { // Handle assignments let AssignStmt { - target, + lvalue: target, derefs, - value, + rvalue: value, span, } = assign_stmt; tracing::debug!("Checking assignment: {:?}", assign_stmt); diff --git a/crates/concrete_ir/src/lowering.rs b/crates/concrete_ir/src/lowering.rs index 777c5dd..5442a6a 100644 --- a/crates/concrete_ir/src/lowering.rs +++ b/crates/concrete_ir/src/lowering.rs @@ -287,8 +287,8 @@ fn lower_func( // Get all locals for stmt in &func.body { if let statements::Statement::Let(info) = stmt { - match &info.target { - LetStmtTarget::Simple { name, r#type } => { + match &info.lvalue { + LetStmtTarget::Simple { id: name, r#type } => { let ty = lower_type(&builder.ctx, r#type, builder.local_module)?; builder .name_to_local @@ -305,8 +305,8 @@ fn lower_func( } } else if let statements::Statement::For(info) = stmt { if let Some(info) = &info.init { - match &info.target { - LetStmtTarget::Simple { name, r#type } => { + match &info.lvalue { + LetStmtTarget::Simple { id: name, r#type } => { let ty = lower_type(&builder.ctx, r#type, builder.local_module)?; builder .name_to_local @@ -435,7 +435,7 @@ fn lower_while(builder: &mut FnBodyBuilder, info: &WhileStmt) -> Result<(), Lowe }); let (discriminator, discriminator_type, _disc_span) = - lower_expression(builder, &info.value, None)?; + lower_expression(builder, &info.cond, None)?; let local = builder.add_temp_local(TyKind::Bool); let place = Place { @@ -463,7 +463,7 @@ fn lower_while(builder: &mut FnBodyBuilder, info: &WhileStmt) -> Result<(), Lowe // keep idx for switch targets let first_then_block_idx = builder.body.basic_blocks.len(); - for stmt in &info.contents { + for stmt in &info.block_stmts { lower_statement( builder, stmt, @@ -515,7 +515,7 @@ fn lower_for(builder: &mut FnBodyBuilder, info: &ForStmt) -> Result<(), Lowering }), }); - let (discriminator, discriminator_type, _disc_span) = if let Some(condition) = &info.condition { + let (discriminator, discriminator_type, _disc_span) = if let Some(condition) = &info.cond { let (discriminator, discriminator_type, span) = lower_expression(builder, condition, None)?; (discriminator, discriminator_type, Some(span)) @@ -560,7 +560,7 @@ fn lower_for(builder: &mut FnBodyBuilder, info: &ForStmt) -> Result<(), Lowering // keep idx for switch targets let first_then_block_idx = builder.body.basic_blocks.len(); - for stmt in &info.contents { + for stmt in &info.block_stmts { lower_statement( builder, stmt, @@ -602,7 +602,7 @@ fn lower_for(builder: &mut FnBodyBuilder, info: &ForStmt) -> Result<(), Lowering fn lower_if_statement(builder: &mut FnBodyBuilder, info: &IfExpr) -> Result<(), LoweringError> { let (discriminator, discriminator_type, _disc_span) = - lower_expression(builder, &info.value, None)?; + lower_expression(builder, &info.cond, None)?; let local = builder.add_temp_local(TyKind::Bool); let place = Place { @@ -630,7 +630,7 @@ fn lower_if_statement(builder: &mut FnBodyBuilder, info: &IfExpr) -> Result<(), // keep idx for switch targets let first_then_block_idx = builder.body.basic_blocks.len(); - for stmt in &info.contents { + for stmt in &info.block_stmts { lower_statement( builder, stmt, @@ -654,7 +654,7 @@ fn lower_if_statement(builder: &mut FnBodyBuilder, info: &IfExpr) -> Result<(), let first_else_block_idx = builder.body.basic_blocks.len(); - if let Some(contents) = &info.r#else { + if let Some(contents) = &info.else_stmts { for stmt in contents { lower_statement( builder, @@ -697,11 +697,11 @@ fn lower_if_statement(builder: &mut FnBodyBuilder, info: &IfExpr) -> Result<(), } fn lower_let(builder: &mut FnBodyBuilder, info: &LetStmt) -> Result<(), LoweringError> { - match &info.target { - LetStmtTarget::Simple { name, r#type } => { + match &info.lvalue { + LetStmtTarget::Simple { id: name, r#type } => { let ty = lower_type(&builder.ctx, r#type, builder.local_module)?; let (rvalue, rvalue_ty, rvalue_span) = - lower_expression(builder, &info.value, Some(ty.clone()))?; + lower_expression(builder, &info.rvalue, Some(ty.clone()))?; if ty.kind != rvalue_ty.kind { return Err(LoweringError::UnexpectedType { @@ -734,7 +734,7 @@ fn lower_let(builder: &mut FnBodyBuilder, info: &LetStmt) -> Result<(), Lowering } fn lower_assign(builder: &mut FnBodyBuilder, info: &AssignStmt) -> Result<(), LoweringError> { - let (mut place, mut ty, _path_span) = lower_path(builder, &info.target)?; + let (mut place, mut ty, _path_span) = lower_path(builder, &info.lvalue)?; if !builder.body.locals[place.local].is_mutable() { return Err(LoweringError::NotMutable { @@ -749,8 +749,8 @@ fn lower_assign(builder: &mut FnBodyBuilder, info: &AssignStmt) -> Result<(), Lo TyKind::Ref(inner, is_mut) | TyKind::Ptr(inner, is_mut) => { if matches!(is_mut, Mutability::Not) { Err(LoweringError::BorrowNotMutable { - span: info.target.first.span, - name: info.target.first.name.clone(), + span: info.lvalue.first.span, + name: info.lvalue.first.name.clone(), type_span: ty.span, program_id: builder.local_module.program_id, })?; @@ -763,7 +763,7 @@ fn lower_assign(builder: &mut FnBodyBuilder, info: &AssignStmt) -> Result<(), Lo } let (rvalue, rvalue_ty, rvalue_span) = - lower_expression(builder, &info.value, Some(ty.clone()))?; + lower_expression(builder, &info.rvalue, Some(ty.clone()))?; if ty.kind != rvalue_ty.kind { return Err(LoweringError::UnexpectedType { @@ -775,7 +775,7 @@ fn lower_assign(builder: &mut FnBodyBuilder, info: &AssignStmt) -> Result<(), Lo } builder.statements.push(Statement { - span: Some(info.target.first.span), + span: Some(info.lvalue.first.span), kind: StatementKind::Assign(place, rvalue), }); diff --git a/crates/concrete_parser/src/grammar.lalrpop b/crates/concrete_parser/src/grammar.lalrpop index 821d76d..4b47778 100644 --- a/crates/concrete_parser/src/grammar.lalrpop +++ b/crates/concrete_parser/src/grammar.lalrpop @@ -503,21 +503,21 @@ pub(crate) ValueExpr: ast::expressions::ValueExpr = { } pub(crate) IfExpr: ast::expressions::IfExpr = { - "if" "{" "}" + "if" "{" "}" "}")?> => { ast::expressions::IfExpr { - value: Box::new(value), - contents, - r#else: else_stmts, + cond: Box::new(cond), + block_stmts, + else_stmts, span: Span::new(lo, hi) } } } pub(crate) MatchExpr: ast::expressions::MatchExpr = { - "match" "{" > "}" => { + "match" "{" > "}" => { ast::expressions::MatchExpr { - value: Box::new(value), + match_expr: Box::new(match_expr), variants, span: Span::new(lo, hi) } @@ -594,36 +594,36 @@ pub(crate) Statement: ast::statements::Statement = { } pub(crate) LetStmt: ast::statements::LetStmt = { - "let" ":" "=" => ast::statements::LetStmt { + "let" ":" "=" => ast::statements::LetStmt { is_mutable: is_mutable.is_some(), - target: ast::statements::LetStmtTarget::Simple { - name, + lvalue: ast::statements::LetStmtTarget::Simple { + id, r#type: target_type }, - value, + rvalue, span: Span::new(lo, hi), }, - "let" ":" "=" => ast::statements::LetStmt { + "let" ":" "=" => ast::statements::LetStmt { is_mutable: is_mutable.is_some(), - target: ast::statements::LetStmtTarget::Simple { - name, + lvalue: ast::statements::LetStmtTarget::Simple { + id, r#type: target_type }, - value: ast::expressions::Expression::StructInit(value), + rvalue: ast::expressions::Expression::StructInit(rvalue), span: Span::new(lo, hi), }, } pub(crate) AssignStmt: ast::statements::AssignStmt = { - "=" => ast::statements::AssignStmt { - target, - value, + "=" => ast::statements::AssignStmt { + lvalue, + rvalue, derefs: derefs.len(), span: Span::new(lo, hi), }, - "=" => ast::statements::AssignStmt { - target, - value: ast::expressions::Expression::StructInit(value), + "=" => ast::statements::AssignStmt { + lvalue, + rvalue: ast::expressions::Expression::StructInit(rvalue), derefs: derefs.len(), span: Span::new(lo, hi), }, @@ -637,40 +637,40 @@ pub(crate) ReturnStmt: ast::statements::ReturnStmt = { } pub(crate) WhileStmt: ast::statements::WhileStmt = { - "while" "{" "}" => { + "while" "{" "}" => { ast::statements::WhileStmt { - value, - contents, + cond, + block_stmts, } } } pub(crate) ForStmt: ast::statements::ForStmt = { - "for" "(" ";" ";" ")" "{" "}" => { + "for" "(" ";" ";" ")" "{" "}" => { ast::statements::ForStmt { init, - condition, + cond, post, - contents, + block_stmts, span: Span::new(lo, hi) } }, - "for" "(" ")" "{" "}" => { + "for" "(" ")" "{" "}" => { ast::statements::ForStmt { init: None, - condition: Some(condition), + cond: Some(cond), post: None, - contents, + block_stmts, span: Span::new(lo, hi) } }, - "for" "{" "}" => { + "for" "{" "}" => { ast::statements::ForStmt { init: None, - condition: None, + cond: None, post: None, - contents, + block_stmts, span: Span::new(lo, hi) } } From 5a9ff748fba89cd35c6f0c6f343ba3ded507a333 Mon Sep 17 00:00:00 2001 From: alejandro baranek Date: Fri, 31 May 2024 17:33:51 -0300 Subject: [PATCH 2/3] cargo fmt --- crates/concrete_check/src/linearity_check.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/concrete_check/src/linearity_check.rs b/crates/concrete_check/src/linearity_check.rs index f8e24fb..1ff50fa 100644 --- a/crates/concrete_check/src/linearity_check.rs +++ b/crates/concrete_check/src/linearity_check.rs @@ -703,7 +703,8 @@ impl LinearityChecker { Statement::If(if_stmt) => { // Handle conditional statements state_tbl = self.check_expr(state_tbl, depth, &if_stmt.cond, context)?; - state_tbl = self.check_stmts(state_tbl, depth + 1, &if_stmt.block_stmts, context)?; + state_tbl = + self.check_stmts(state_tbl, depth + 1, &if_stmt.block_stmts, context)?; if let Some(else_block) = &if_stmt.else_stmts { state_tbl = self.check_stmts(state_tbl, depth + 1, else_block, context)?; } @@ -730,7 +731,8 @@ impl LinearityChecker { //TODO check assign statement //self.check_stmt_assign(depth, post)?; } - state_tbl = self.check_stmts(state_tbl, depth + 1, &for_stmt.block_stmts, context)?; + state_tbl = + self.check_stmts(state_tbl, depth + 1, &for_stmt.block_stmts, context)?; Ok(state_tbl) } Statement::Assign(assign_stmt) => { From 631f02f345407d34285b0f9f48dc2569e0e4f583 Mon Sep 17 00:00:00 2001 From: alejandro baranek Date: Mon, 3 Jun 2024 14:39:31 -0300 Subject: [PATCH 3/3] Applied suggested reviews --- crates/concrete_ast/src/expressions.rs | 2 +- crates/concrete_ast/src/statements.rs | 8 +++--- crates/concrete_check/src/linearity_check.rs | 18 ++++++------ crates/concrete_ir/src/lowering.rs | 12 ++++---- crates/concrete_parser/src/grammar.lalrpop | 30 ++++++++++---------- 5 files changed, 35 insertions(+), 35 deletions(-) diff --git a/crates/concrete_ast/src/expressions.rs b/crates/concrete_ast/src/expressions.rs index 9cdc0e6..92818e9 100644 --- a/crates/concrete_ast/src/expressions.rs +++ b/crates/concrete_ast/src/expressions.rs @@ -99,7 +99,7 @@ pub enum BitwiseOp { #[derive(Clone, Debug, Eq, PartialEq)] pub struct MatchExpr { - pub match_expr: Box, + pub expr: Box, pub variants: Vec, pub span: Span, } diff --git a/crates/concrete_ast/src/statements.rs b/crates/concrete_ast/src/statements.rs index bb1c058..0d2f348 100644 --- a/crates/concrete_ast/src/statements.rs +++ b/crates/concrete_ast/src/statements.rs @@ -25,8 +25,8 @@ pub enum LetStmtTarget { #[derive(Clone, Debug, Eq, PartialEq)] pub struct LetStmt { pub is_mutable: bool, - pub lvalue: LetStmtTarget, - pub rvalue: Expression, + pub target: LetStmtTarget, + pub value: Expression, pub span: Span, } @@ -54,7 +54,7 @@ pub struct Binding { #[derive(Clone, Debug, Eq, PartialEq)] pub struct ForStmt { pub init: Option, - pub cond: Option, + pub condition: Option, pub post: Option, pub block_stmts: Vec, pub span: Span, @@ -62,6 +62,6 @@ pub struct ForStmt { #[derive(Clone, Debug, Eq, PartialEq)] pub struct WhileStmt { - pub cond: Expression, + pub condition: Expression, pub block_stmts: Vec, } diff --git a/crates/concrete_check/src/linearity_check.rs b/crates/concrete_check/src/linearity_check.rs index 1ff50fa..9d620c9 100644 --- a/crates/concrete_check/src/linearity_check.rs +++ b/crates/concrete_check/src/linearity_check.rs @@ -324,7 +324,7 @@ impl LinearityChecker { match statement { Statement::Let(binding) => { // Handle let bindings, possibly involving pattern matching - self.count_in_expression(name, &binding.rvalue) + self.count_in_expression(name, &binding.value) } Statement::If(if_stmt) => { // Process all components of an if expression @@ -340,7 +340,7 @@ impl LinearityChecker { cond_apps.merge(&then_apps).merge(&else_apps) } Statement::While(while_expr) => { - let cond = &while_expr.cond; + let cond = &while_expr.condition; let block = &while_expr.block_stmts; // Handle while loops self.count_in_expression(name, cond) @@ -350,7 +350,7 @@ impl LinearityChecker { // Handle for loops //init, cond, post, block let init = &for_expr.init; - let cond = &for_expr.cond; + let cond = &for_expr.condition; let post = &for_expr.post; let block = &for_expr.block_stmts; let mut apps = Appearances::zero(); @@ -422,8 +422,8 @@ impl LinearityChecker { fn count_in_let_statements(&self, name: &str, let_stmt: &LetStmt) -> Appearances { let LetStmt { is_mutable, - lvalue: target, - rvalue: value, + target, + value, span, } = let_stmt; self.count_in_expression(name, value) @@ -524,8 +524,8 @@ impl LinearityChecker { // Handle let bindings, possibly involving pattern matching let LetStmt { is_mutable, - lvalue: target, - rvalue: value, + target, + value, span, } = binding; match target { @@ -713,7 +713,7 @@ impl LinearityChecker { //Statement::While(cond, block) => { Statement::While(while_stmt) => { // Handle while loops - state_tbl = self.check_expr(state_tbl, depth, &while_stmt.cond, context)?; + state_tbl = self.check_expr(state_tbl, depth, &while_stmt.condition, context)?; state_tbl = self.check_stmts(state_tbl, depth + 1, &while_stmt.block_stmts, context)?; Ok(state_tbl) @@ -724,7 +724,7 @@ impl LinearityChecker { if let Some(init) = &for_stmt.init { state_tbl = self.check_stmt_let(state_tbl, depth, init, context)?; } - if let Some(condition) = &for_stmt.cond { + if let Some(condition) = &for_stmt.condition { state_tbl = self.check_expr(state_tbl, depth, condition, context)?; } if let Some(post) = &for_stmt.post { diff --git a/crates/concrete_ir/src/lowering.rs b/crates/concrete_ir/src/lowering.rs index 5442a6a..7097744 100644 --- a/crates/concrete_ir/src/lowering.rs +++ b/crates/concrete_ir/src/lowering.rs @@ -287,7 +287,7 @@ fn lower_func( // Get all locals for stmt in &func.body { if let statements::Statement::Let(info) = stmt { - match &info.lvalue { + match &info.target { LetStmtTarget::Simple { id: name, r#type } => { let ty = lower_type(&builder.ctx, r#type, builder.local_module)?; builder @@ -305,7 +305,7 @@ fn lower_func( } } else if let statements::Statement::For(info) = stmt { if let Some(info) = &info.init { - match &info.lvalue { + match &info.target { LetStmtTarget::Simple { id: name, r#type } => { let ty = lower_type(&builder.ctx, r#type, builder.local_module)?; builder @@ -435,7 +435,7 @@ fn lower_while(builder: &mut FnBodyBuilder, info: &WhileStmt) -> Result<(), Lowe }); let (discriminator, discriminator_type, _disc_span) = - lower_expression(builder, &info.cond, None)?; + lower_expression(builder, &info.condition, None)?; let local = builder.add_temp_local(TyKind::Bool); let place = Place { @@ -515,7 +515,7 @@ fn lower_for(builder: &mut FnBodyBuilder, info: &ForStmt) -> Result<(), Lowering }), }); - let (discriminator, discriminator_type, _disc_span) = if let Some(condition) = &info.cond { + let (discriminator, discriminator_type, _disc_span) = if let Some(condition) = &info.condition { let (discriminator, discriminator_type, span) = lower_expression(builder, condition, None)?; (discriminator, discriminator_type, Some(span)) @@ -697,11 +697,11 @@ fn lower_if_statement(builder: &mut FnBodyBuilder, info: &IfExpr) -> Result<(), } fn lower_let(builder: &mut FnBodyBuilder, info: &LetStmt) -> Result<(), LoweringError> { - match &info.lvalue { + match &info.target { LetStmtTarget::Simple { id: name, r#type } => { let ty = lower_type(&builder.ctx, r#type, builder.local_module)?; let (rvalue, rvalue_ty, rvalue_span) = - lower_expression(builder, &info.rvalue, Some(ty.clone()))?; + lower_expression(builder, &info.value, Some(ty.clone()))?; if ty.kind != rvalue_ty.kind { return Err(LoweringError::UnexpectedType { diff --git a/crates/concrete_parser/src/grammar.lalrpop b/crates/concrete_parser/src/grammar.lalrpop index 4b47778..e7a3ed6 100644 --- a/crates/concrete_parser/src/grammar.lalrpop +++ b/crates/concrete_parser/src/grammar.lalrpop @@ -515,9 +515,9 @@ pub(crate) IfExpr: ast::expressions::IfExpr = { } pub(crate) MatchExpr: ast::expressions::MatchExpr = { - "match" "{" > "}" => { + "match" "{" > "}" => { ast::expressions::MatchExpr { - match_expr: Box::new(match_expr), + expr: Box::new(expr), variants, span: Span::new(lo, hi) } @@ -594,22 +594,22 @@ pub(crate) Statement: ast::statements::Statement = { } pub(crate) LetStmt: ast::statements::LetStmt = { - "let" ":" "=" => ast::statements::LetStmt { + "let" ":" "=" => ast::statements::LetStmt { is_mutable: is_mutable.is_some(), - lvalue: ast::statements::LetStmtTarget::Simple { + target: ast::statements::LetStmtTarget::Simple { id, r#type: target_type }, - rvalue, + value, span: Span::new(lo, hi), }, - "let" ":" "=" => ast::statements::LetStmt { + "let" ":" "=" => ast::statements::LetStmt { is_mutable: is_mutable.is_some(), - lvalue: ast::statements::LetStmtTarget::Simple { + target: ast::statements::LetStmtTarget::Simple { id, r#type: target_type }, - rvalue: ast::expressions::Expression::StructInit(rvalue), + value: ast::expressions::Expression::StructInit(value), span: Span::new(lo, hi), }, } @@ -637,9 +637,9 @@ pub(crate) ReturnStmt: ast::statements::ReturnStmt = { } pub(crate) WhileStmt: ast::statements::WhileStmt = { - "while" "{" "}" => { + "while" "{" "}" => { ast::statements::WhileStmt { - cond, + condition, block_stmts, } } @@ -647,19 +647,19 @@ pub(crate) WhileStmt: ast::statements::WhileStmt = { pub(crate) ForStmt: ast::statements::ForStmt = { - "for" "(" ";" ";" ")" "{" "}" => { + "for" "(" ";" ";" ")" "{" "}" => { ast::statements::ForStmt { init, - cond, + condition, post, block_stmts, span: Span::new(lo, hi) } }, - "for" "(" ")" "{" "}" => { + "for" "(" ")" "{" "}" => { ast::statements::ForStmt { init: None, - cond: Some(cond), + condition: Some(condition), post: None, block_stmts, span: Span::new(lo, hi) @@ -668,7 +668,7 @@ pub(crate) ForStmt: ast::statements::ForStmt = { "for" "{" "}" => { ast::statements::ForStmt { init: None, - cond: None, + condition: None, post: None, block_stmts, span: Span::new(lo, hi)