Skip to content

Commit 790b52e

Browse files
committed
ast: Remove variable assignment and use Assignment instead
This commit renames the VarAssign nodes to Assignments instead. Before, these nodes were used for both field assignments and var assignemnts, but removing mutability from the language means variable assignments are no longer necessary.
1 parent 0798716 commit 790b52e

File tree

4 files changed

+20
-37
lines changed

4 files changed

+20
-37
lines changed

ast/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ pub enum Node {
192192
to_declare: Symbol,
193193
value: Box<Ast>,
194194
},
195-
VarAssign {
195+
Assignment {
196196
to_assign: Symbol,
197197
value: Box<Ast>,
198198
},
@@ -429,7 +429,7 @@ pub trait Visitor {
429429

430430
Ok(Ast {
431431
location,
432-
node: Node::VarAssign { to_assign, value },
432+
node: Node::Assignment { to_assign, value },
433433
})
434434
}
435435

@@ -500,7 +500,7 @@ pub trait Visitor {
500500
Node::VarDeclaration { to_declare, value } => {
501501
self.visit_var_declaration(ast.location, to_declare, value)
502502
}
503-
Node::VarAssign { to_assign, value } => {
503+
Node::Assignment { to_assign, value } => {
504504
self.visit_var_assign(ast.location, to_assign, value)
505505
}
506506
Node::VarOrEmptyType(name) => self.visit_var_or_empty_type(ast.location, name),

flatten/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ impl<'ast> AstInfo<'ast> {
225225
..
226226
}
227227
| AstNode::VarOrEmptyType(sym)
228-
| AstNode::VarAssign { to_assign: sym, .. }
228+
| AstNode::Assignment { to_assign: sym, .. }
229229
| AstNode::VarDeclaration {
230230
to_declare: sym, ..
231231
} => Some(sym),
@@ -826,7 +826,7 @@ impl<'ast> Ctx<'ast> {
826826
}
827827

828828
fn handle_field_instantiation(self, instantiation: &'ast Ast) -> (Ctx<'ast>, RefIdx) {
829-
let AstNode::VarAssign { value, .. } = &instantiation.node else {
829+
let AstNode::Assignment { value, .. } = &instantiation.node else {
830830
// FIXME: Ugly?
831831
unreachable!(
832832
"invalid AST: non var-assign in field instantiation, in type instantiation"
@@ -902,7 +902,7 @@ impl<'ast> Ctx<'ast> {
902902
AstNode::VarDeclaration { to_declare, value } => {
903903
self.visit_var_declaration(node, to_declare, value)
904904
}
905-
AstNode::VarAssign { to_assign, value } => {
905+
AstNode::Assignment { to_assign, value } => {
906906
self.visit_var_assign(node, to_assign, value)
907907
}
908908
AstNode::VarOrEmptyType(_) => self.visit_var_or_empty_type(node),

typecheck/src/lib.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,12 @@ mod tests {
286286
let ast = ast! {
287287
type Marker0;
288288

289-
where mut a = Marker0;
290-
a = Marker0;
289+
func f(a: Marker0) {}
291290

292-
where mut b = Marker0;
293-
b = a;
291+
f(Marker0);
292+
293+
where b = Marker0;
294+
f(b);
294295
};
295296
let fir = fir!(ast).type_check();
296297

@@ -303,8 +304,10 @@ mod tests {
303304
type Marker0;
304305
type Marker1;
305306

306-
where mut a = Marker0;
307-
a = Marker1;
307+
func f(a: Marker0) {}
308+
309+
f(Marker0);
310+
f(Marker1);
308311
};
309312
let fir = fir!(ast).type_check();
310313

xparser/src/constructs.rs

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -876,21 +876,8 @@ fn func_type_or_var(
876876
generic_func_or_type_inst_args(next(input), id, start_loc)
877877
} else if let Ok((input, _)) = tokens::left_parenthesis(input) {
878878
func_or_type_inst_args(next(input), id, vec![], start_loc)
879-
} else if let Ok((input, _)) = tokens::equal(input) {
880-
let (input, value) = expr(input)?;
881-
let (input, end_loc) = position(input)?;
882-
let var_assign = Node::VarAssign {
883-
to_assign: Symbol::from(id),
884-
value: Box::new(value),
885-
};
886-
Ok((
887-
input,
888-
Ast {
889-
location: pos_to_loc(input, start_loc, end_loc),
890-
node: var_assign,
891-
},
892-
))
893879
} else {
880+
// TODO: Is this correct? we need to do some error handling here and warn if there are unexpected tokens probably?
894881
let (input, end_loc) = position(input)?;
895882
let var_or_et = Node::VarOrEmptyType(Symbol::from(id));
896883
Ok((
@@ -926,7 +913,7 @@ fn func_or_type_inst_args(
926913
0,
927914
Ast {
928915
location: pos_to_loc(input, first_attr_start_loc, first_attr_end_loc),
929-
node: Node::VarAssign {
916+
node: Node::Assignment {
930917
to_assign: Symbol::from(first_attr),
931918
value: Box::new(first_attr_val),
932919
},
@@ -1040,7 +1027,7 @@ fn type_inst_arg(input: ParseInput) -> ParseResult<ParseInput, Ast> {
10401027
let input = next(input);
10411028

10421029
let location = pos_to_loc(input, start_loc, end_loc);
1043-
let node = Node::VarAssign {
1030+
let node = Node::Assignment {
10441031
to_assign: Symbol::from(id),
10451032
value: Box::new(value),
10461033
};
@@ -2267,15 +2254,8 @@ mod tests {
22672254
}
22682255

22692256
#[test]
2270-
fn mutable_declaration() {
2271-
let input = span!("where mut x = 14");
2272-
2273-
assert!(expr(input).is_ok());
2274-
}
2275-
2276-
#[test]
2277-
fn mutable_declaration_complex() {
2278-
let input = span!("where mut x = if value { 14 } else { 15 }");
2257+
fn immutable_declaration_complex() {
2258+
let input = span!("where x = if value { 14 } else { 15 }");
22792259

22802260
assert!(expr(input).is_ok());
22812261
}

0 commit comments

Comments
 (0)