plum

#treesitter#compiler#wasm

git clone https://git.pyrossh.dev/plum

A statically typed, imperative programming language inspired by rust, python


6716f7e — Peter John 2026-11-10T14:49:52+05:30
todo is removed from the language
Files changed (35) hide show
  1. compiler/checker/src/stmt.rs +1 -1
  2. compiler/checker/tests/checker/checker_tests.rs +17 -1
  3. compiler/core/src/ast.rs +0 -2
  4. compiler/core/src/blocks.rs +3 -3
  5. compiler/core/src/builtin_usage.rs +1 -1
  6. compiler/core/src/closure_escape.rs +1 -1
  7. compiler/core/src/drive.rs +1 -1
  8. compiler/core/src/enum_checks.rs +1 -1
  9. compiler/core/src/game_entry.rs +1 -1
  10. compiler/core/src/loader.rs +2 -2
  11. compiler/core/src/parser.rs +3 -4
  12. compiler/core/src/purity.rs +2 -2
  13. compiler/core/src/question.rs +1 -1
  14. compiler/core/src/tail.rs +1 -1
  15. compiler/core/src/trmc.rs +3 -3
  16. compiler/core/src/uniqueness.rs +4 -4
  17. compiler/core/src/visit.rs +2 -2
  18. compiler/core/tests/core/inline_variants_test.rs +2 -2
  19. compiler/core/tests/core/loader_test.rs +4 -4
  20. compiler/core/tests/core/parser_test.rs +1 -1
  21. compiler/lsp/src/completion.rs +0 -1
  22. compiler/tooling/tree-sitter-plum/grammar.js +0 -2
  23. compiler/tooling/tree-sitter-plum/queries/plum/highlights.scm +0 -2
  24. compiler/tooling/tree-sitter-plum/src/grammar.json +0 -0
  25. compiler/tooling/tree-sitter-plum/src/node-types.json +0 -0
  26. compiler/tooling/tree-sitter-plum/src/parser.c +0 -0
  27. compiler/tooling/tree-sitter-plum/test/corpus/function.txt +43 -10
  28. compiler/tooling/vscode-plum/syntaxes/plum.tmLanguage.json +1 -1
  29. compiler/wasm-codegen/src/closures.rs +1 -1
  30. compiler/wasm-codegen/src/fnbody.rs +1 -1
  31. compiler/wasm-codegen/src/stmts.rs +3 -3
  32. compiler/wasm-codegen/tests/wasm_codegen/codegen_tests.rs +12 -19
  33. docs/language.md +1 -1
  34. examples/basics.plum +2 -2
  35. examples/control_flow.plum +0 -3
compiler/checker/src/stmt.rs CHANGED
@@ -560,7 +560,7 @@ pub(crate) fn checkStmtInner(
560
560
  withCheck(|s| { let c = &s.match_tail; *c.borrow_mut() = tail.clone() });
561
561
  errors.append(&mut checkMatch(m, env, declared_ret, fn_name, fn_pos, ctx));
562
562
  }
563
- ast::StmtKind::Todo | ast::StmtKind::Native => {}
563
+ ast::StmtKind::Native => {}
564
564
  ast::StmtKind::Crash(e) => match inferExpr(e, env, ctx) {
565
565
  Ok(t) => {
566
566
  if let Err(msg) = unify(&types::strType(), &t, ctx) {
compiler/checker/tests/checker/checker_tests.rs CHANGED
@@ -719,7 +719,7 @@ struct Bag(n: Int) =
719
719
  Bag(n: v)
720
720
 
721
721
  fun bump(self) -> Unit =
722
- todo
722
+ Unit
723
723
 
724
724
  primitive Util =
725
725
  fun two() -> Int =
@@ -865,3 +865,19 @@ fn unnumberedSourceIsCheckedAsNumberedCopy() {
865
865
  assert!(!info.expr_types.contains_key(&NodeId(0)));
866
866
  assert!(!info.annotated.contains_key(&NodeId(0)));
867
867
  }
868
+
869
+ /// `todo` was a statement; it is now a name like any other: undefined unless declared.
870
+ #[test]
871
+ fn todoIsAnUndefinedName() {
872
+ for src in [
873
+ "fun f() -> Int =\n todo\n",
874
+ "fun f() =\n todo\n",
875
+ "fun f() -> Int = todo\n",
876
+ "fun f(b: Bool) -> Int =\n if b\n 1\n else\n todo\n",
877
+ ] {
878
+ let e = errText(checkSrc(src));
879
+ assert!(e.contains("undefined name 'todo'"), "{src}: {e}");
880
+ }
881
+ checkSrc("fun f(todo: Int) -> Int =\n todo\n").unwrap();
882
+ checkSrc("fun f() -> Int =\n todo := 1\n todo\n").unwrap();
883
+ }
compiler/core/src/ast.rs CHANGED
@@ -75,7 +75,6 @@ impl Stmt {
75
75
  }
76
76
  pub fn Assign(a: Assign) -> Stmt { Stmt::new(StmtKind::Assign(a)) }
77
77
  pub const Native: Stmt = Stmt { id: NodeId(0), span: Span { startLine: 0, startColumn: 0, endLine: 0, endColumn: 0 }, kind: StmtKind::Native };
78
- pub const Todo: Stmt = Stmt { id: NodeId(0), span: Span { startLine: 0, startColumn: 0, endLine: 0, endColumn: 0 }, kind: StmtKind::Todo };
79
78
  pub fn Assert(c: Check) -> Stmt { Stmt::new(StmtKind::Assert(c)) }
80
79
  pub fn While(w: While) -> Stmt { Stmt::new(StmtKind::While(w)) }
81
80
  pub fn If(i: If) -> Stmt { Stmt::new(StmtKind::If(i)) }
@@ -764,7 +763,6 @@ pub enum StmtKind {
764
763
  If(If),
765
764
  Match(Match),
766
765
  Return(Option<Expr>),
767
- Todo,
768
766
  /// `@native`, a function's whole body: the compiler supplies it (`native`).
769
767
  Native,
770
768
  /// `crash expr` — stops the program with the `Str` message `expr`.
compiler/core/src/blocks.rs CHANGED
@@ -7,7 +7,7 @@
7
7
  //!
8
8
  //! * rejects a block whose last line is no value (an `if` used as a value needs an `else`; the
9
9
  //! last line of every branch is a value, a nested `if` / `match`, or ends the path with
10
- //! `return` / `crash` / `todo`), and a block in a constant;
10
+ //! `return` / `crash`), and a block in a constant;
11
11
  //! * gives each name that a block declares and that is declared elsewhere in the same fn
12
12
  //! (a sibling branch, or a later outer name) a fresh name. Locals are fn-wide and typed once in
13
13
  //! the output, so two branches that each declare `t` (of different types) would otherwise
@@ -53,7 +53,7 @@ impl Pass {
53
53
  self.tail(&c.body.stmts, last.span);
54
54
  }
55
55
  }
56
- StmtKind::Return(_) | StmtKind::Crash(_) | StmtKind::Todo | StmtKind::Native => {}
56
+ StmtKind::Return(_) | StmtKind::Crash(_) | StmtKind::Native => {}
57
57
  _ => self.error(last.span, "the last line of a block used as a value must be a value, an 'if' or a 'match'"),
58
58
  }
59
59
  }
@@ -200,7 +200,7 @@ impl Scoper<'_> {
200
200
  }
201
201
  }
202
202
  // A `While` is only ever built by TRMC, after this pass.
203
- StmtKind::While(_) | StmtKind::Todo | StmtKind::Native => {}
203
+ StmtKind::While(_) | StmtKind::Native => {}
204
204
  }
205
205
  }
206
206
 
compiler/core/src/builtin_usage.rs CHANGED
@@ -143,7 +143,7 @@ fn walkStmt(stmt: &Stmt, names: &mut Acc) {
143
143
  }
144
144
  }
145
145
  // A `While` is only ever built by TRMC, after this pass.
146
- StmtKind::While(_) | StmtKind::Todo | StmtKind::Native => {}
146
+ StmtKind::While(_) | StmtKind::Native => {}
147
147
  StmtKind::Crash(e) => walkExpr(e, names),
148
148
  StmtKind::Assert(check) => walkExpr(&check.cond, names),
149
149
  StmtKind::If(i) => {
compiler/core/src/closure_escape.rs CHANGED
@@ -110,7 +110,7 @@ impl<'a> Cx<'a> {
110
110
  AssignTarget::Field(o, _) => self.expr(o, cl),
111
111
  }) || a.values.iter().any(|v| self.expr(v, cl))
112
112
  }
113
- StmtKind::Todo | StmtKind::Native => false,
113
+ StmtKind::Native => false,
114
114
  StmtKind::Assert(c) => self.expr(&c.cond, cl),
115
115
  StmtKind::While(w) => self.expr(&w.condition, cl) || self.block(&w.body, cl),
116
116
  StmtKind::If(i) => {
compiler/core/src/drive.rs CHANGED
@@ -2233,7 +2233,7 @@ impl Driver {
2233
2233
  fn quietStmt(&self, s: &Stmt) -> bool {
2234
2234
  match &s.kind {
2235
2235
  StmtKind::Assign(a) if a.targets.iter().any(|t| matches!(t, AssignTarget::Field(..))) => false,
2236
- StmtKind::Todo | StmtKind::Native => false,
2236
+ StmtKind::Native => false,
2237
2237
  _ => {
2238
2238
  stmtBlockRefs(s).into_iter().all(|b| b.stmts.iter().all(|s| self.quietStmt(s)))
2239
2239
  && stmtExprRefs(s).into_iter().all(|e| {
compiler/core/src/enum_checks.rs CHANGED
@@ -259,7 +259,7 @@ impl TypeWalk<'_> {
259
259
  }
260
260
  a.values.iter().for_each(|v| self.expr(v));
261
261
  }
262
- StmtKind::Todo | StmtKind::Native => {}
262
+ StmtKind::Native => {}
263
263
  StmtKind::Crash(e) => self.expr(e),
264
264
  StmtKind::Assert(c) => self.expr(&c.cond),
265
265
  StmtKind::While(w) => {
compiler/core/src/game_entry.rs CHANGED
@@ -121,7 +121,7 @@ mod tests {
121
121
 
122
122
  /// A stand-in for std/game/Game's `Game[S, M]` and a `main` returning `ret`.
123
123
  fn game(ret: &str) -> Source {
124
- parse(&format!("struct Game[S, M](n: Int)\n\nfun main(io: Io) -> {ret} =\n todo\n"))
124
+ parse(&format!("struct Game[S, M](n: Int)\n\nfun main(io: Io) -> {ret} =\n crash \"unused\"\n"))
125
125
  }
126
126
 
127
127
  /// The old shape: a type of its own with `update` and `draw`.
compiler/core/src/loader.rs CHANGED
@@ -483,8 +483,8 @@ impl SyntaxError {
483
483
  let mut msg = format!("unexpected '{}'", tok);
484
484
  if tok == "()" {
485
485
  msg.push_str(
486
- "\n hint: `()` is not a value in Plum; use `todo` \
486
+ "\n hint: `()` is not a value in Plum; the value of a body \
487
- for a body that is not written yet",
487
+ that returns nothing is `Unit`",
488
488
  );
489
489
  }
490
490
  msg
compiler/core/src/parser.rs CHANGED
@@ -821,11 +821,11 @@ impl<'a> AstParser<'a> {
821
821
  "assign" => Stmt::Assign(self.parseAssign(node)),
822
822
  "break" => {
823
823
  self.removed(node, "`break` is gone: a loop has no early exit; use `fold`, `find`, `repeatUntil` or a recursive function");
824
- Stmt::Todo
824
+ Stmt::Return(None)
825
825
  }
826
826
  "continue" => {
827
827
  self.removed(node, "`continue` is gone: skip an element with an `if` around the body");
828
- Stmt::Todo
828
+ Stmt::Return(None)
829
829
  }
830
830
  "return" => {
831
831
  self.removed(node, "`return` is gone: the last expression of a body is its value; end every path with a value (use `if`/`match` instead of an early exit)");
@@ -835,7 +835,6 @@ impl<'a> AstParser<'a> {
835
835
  });
836
836
  Stmt::Return(expr)
837
837
  }
838
- "todo" => Stmt::Todo,
839
838
  "crash" => Stmt::Crash(
840
839
  node.named_child(0)
841
840
  .map(|n| {
@@ -1203,7 +1202,7 @@ impl<'a> AstParser<'a> {
1203
1202
  .all(|b| Self::valueTail(&b.stmts))
1204
1203
  }
1205
1204
  Some(StmtKind::Match(m)) => m.cases.iter().all(|c| Self::valueTail(&c.body.stmts)),
1206
- Some(StmtKind::Return(_) | StmtKind::Crash(_) | StmtKind::Todo | StmtKind::Native) => true,
1205
+ Some(StmtKind::Return(_) | StmtKind::Crash(_) | StmtKind::Native) => true,
1207
1206
  _ => false,
1208
1207
  }
1209
1208
  }
compiler/core/src/purity.rs CHANGED
@@ -1,5 +1,5 @@
1
1
  //! Purity analysis. A fn is pure when running it can only compute a value: no extern
2
- //! call, no `crash`/`!`/`todo`/`assert` (all may stop the program), no write to a
2
+ //! call, no `crash`/`!`/`assert` (all may stop the program), no write to a
3
3
  //! field of anything but a fresh local (a local only ever bound to a record
4
4
  //! construction), and every callee it can reach is pure. Closure literal bodies count
5
5
  //! towards the enclosing fn. Calls are resolved by name only; an unknown callee
@@ -382,7 +382,7 @@ impl<'a> Walker<'a> {
382
382
  self.expr(v);
383
383
  }
384
384
  }
385
- StmtKind::Todo | StmtKind::Native => {
385
+ StmtKind::Native => {
386
386
  self.impure = true;
387
387
  self.mutates = true;
388
388
  }
compiler/core/src/question.rs CHANGED
@@ -251,7 +251,7 @@ impl Pass {
251
251
  };
252
252
  self.extractSeq(stmtExprs(&mut s), condFrom, &mut pre);
253
253
  // Nested blocks.
254
- let kind = std::mem::replace(&mut s.kind, StmtKind::Todo);
254
+ let kind = std::mem::replace(&mut s.kind, StmtKind::Return(None));
255
255
  s.kind = match kind {
256
256
  StmtKind::If(mut i) => {
257
257
  self.branches(isLast, mode, vec![&mut i.body]);
compiler/core/src/tail.rs CHANGED
@@ -82,7 +82,7 @@ fn stmt(cx: &mut Ctx, s: &mut Stmt, tail: bool, ret: bool) {
82
82
  expr(cx, v, false);
83
83
  }
84
84
  }
85
- StmtKind::Todo | StmtKind::Native => {}
85
+ StmtKind::Native => {}
86
86
  StmtKind::Assert(c) => expr(cx, &mut c.cond, false),
87
87
  StmtKind::While(w) => {
88
88
  expr(cx, &mut w.condition, false);
compiler/core/src/trmc.rs CHANGED
@@ -182,18 +182,18 @@ fn rewriteExprBody(f: &Fn, enums: &[Enum], ret: Type, nullary: String) -> Option
182
182
  cx.finish(Block { stmts })
183
183
  }
184
184
 
185
- /// Constructs the rewrite does not handle: `?`/`!`/catch, closures, `return`, `todo`, `crash`.
185
+ /// Constructs the rewrite does not handle: `?`/`!`/catch, closures, `return`, `@native`, `crash`.
186
186
  fn bannedExpr(e: &Expr) -> bool {
187
187
  crate::visit::anyExpr(e, &mut |x| match &x.kind {
188
188
  ExprKind::Question(_) | ExprKind::Bang(_) | ExprKind::Closure(_) => true,
189
- // `return` / `crash` / `todo` inside a block value.
189
+ // `return` / `crash` inside a block value.
190
190
  ExprKind::Block(b) => bannedBlock(b),
191
191
  _ => false,
192
192
  })
193
193
  }
194
194
 
195
195
  fn bannedStmt(s: &Stmt) -> bool {
196
- matches!(&s.kind, StmtKind::Return(_) | StmtKind::Todo | StmtKind::Native | StmtKind::Crash(_))
196
+ matches!(&s.kind, StmtKind::Return(_) | StmtKind::Native | StmtKind::Crash(_))
197
197
  || crate::visit::stmtExprRefs(s).into_iter().any(bannedExpr)
198
198
  || crate::visit::stmtBlockRefs(s).into_iter().any(bannedBlock)
199
199
  }
compiler/core/src/uniqueness.rs CHANGED
@@ -130,7 +130,7 @@ pub(crate) fn walkStmt<'a>(s: &'a Stmt, f: Visit<'a, '_>) {
130
130
  }
131
131
  }
132
132
  StmtKind::Return(Some(e)) | StmtKind::Crash(e) | StmtKind::Expr(e, _, _) => walkExpr(e, f),
133
- StmtKind::Return(None) | StmtKind::Todo | StmtKind::Native => {}
133
+ StmtKind::Return(None) | StmtKind::Native => {}
134
134
  }
135
135
  }
136
136
 
@@ -253,7 +253,7 @@ fn mutStmt(s: &mut Stmt, f: &mut dyn FnMut(&mut Expr)) {
253
253
  }
254
254
  }
255
255
  StmtKind::Return(Some(e)) | StmtKind::Crash(e) | StmtKind::Expr(e, _, _) => mutExpr(e, f),
256
- StmtKind::Return(None) | StmtKind::Todo | StmtKind::Native => {}
256
+ StmtKind::Return(None) | StmtKind::Native => {}
257
257
  }
258
258
  }
259
259
 
@@ -1086,7 +1086,7 @@ impl<'a> Scan<'a> {
1086
1086
  || m.cases.iter().any(|c| c.guard.as_ref().is_some_and(|g| self.mentions(g)) || self.mentionsStmts(&c.body.stmts))
1087
1087
  }
1088
1088
  StmtKind::Return(Some(e)) | StmtKind::Crash(e) | StmtKind::Expr(e, _, _) => self.mentions(e),
1089
- StmtKind::Return(None) | StmtKind::Todo | StmtKind::Native => false,
1089
+ StmtKind::Return(None) | StmtKind::Native => false,
1090
1090
  };
1091
1091
  self.mentioned.borrow_mut().insert(key, m);
1092
1092
  m
@@ -1301,7 +1301,7 @@ impl<'a> Scan<'a> {
1301
1301
  self.block(&c.body, tail, live, depth + 1);
1302
1302
  }
1303
1303
  }
1304
- StmtKind::Return(None) | StmtKind::Todo | StmtKind::Native => {}
1304
+ StmtKind::Return(None) | StmtKind::Native => {}
1305
1305
  }
1306
1306
  }
1307
1307
 
compiler/core/src/visit.rs CHANGED
@@ -131,7 +131,7 @@ pub fn stmtExprs(s: &mut Stmt) -> Vec<&mut Expr> {
131
131
  v.extend(m.cases.iter_mut().filter_map(|c| c.guard.as_mut()));
132
132
  v
133
133
  }
134
- StmtKind::Todo | StmtKind::Native => vec![],
134
+ StmtKind::Native => vec![],
135
135
  }
136
136
  }
137
137
 
@@ -229,7 +229,7 @@ pub fn stmtExprRefs(s: &Stmt) -> Vec<&Expr> {
229
229
  v.extend(m.cases.iter().filter_map(|c| c.guard.as_ref()));
230
230
  v
231
231
  }
232
- StmtKind::Todo | StmtKind::Native => vec![],
232
+ StmtKind::Native => vec![],
233
233
  }
234
234
  }
235
235
 
compiler/core/tests/core/inline_variants_test.rs CHANGED
@@ -60,11 +60,11 @@ fn type_position_errors() {
60
60
  let msg = vec!["Cons is a variant of Link, not a type; use Link[...]".to_string()];
61
61
  for src in [
62
62
  "fun fa(cc: Cons[Int]) -> Int = 1\n",
63
- "fun fa() -> Cons[Int] = todo\n",
63
+ "fun fa() -> Cons[Int] = Nil\n",
64
64
  "struct Box(cc: Cons[Int])\n",
65
65
  "fun fa(cc: Slice[Cons[Int]]) -> Int = 1\n",
66
66
  "fun fa(gg: fn(Cons[Int]) -> Int) -> Int = 1\n",
67
- "fun fa() -> Int =\n cc: Cons[Int] := todo\n 1\n",
67
+ "fun fa() -> Int =\n cc: Cons[Int] := Nil\n 1\n",
68
68
  ] {
69
69
  let s = plum_test_support::parseRawSource(&format!("enum Link[T] = Nil | Cons(head: T)\n{src}"));
70
70
  assert_eq!(inlineVariantTypeErrors(&s), msg, "{src}");
compiler/core/tests/core/loader_test.rs CHANGED
@@ -291,7 +291,7 @@ fn removedSyntaxIsAParseError() {
291
291
  "fun f(u: Unit) -> Unit??\n u\n",
292
292
  "fun f(u: Unit) -> Unit? =\n u\n",
293
293
  "fun f(u: Unit) -> Unit? ! [X] =\n u\n",
294
- "extend Foo =\n fun f() -> Unit =\n todo\n",
294
+ "extend Foo =\n fun f() -> Unit =\n Unit\n",
295
295
  ] {
296
296
  let dir = TempDir::new().unwrap();
297
297
  let entry = dir.path().join("main.plum");
@@ -318,7 +318,7 @@ fn parseErrorBlamesTheTokenNotTheWholeFunction() {
318
318
  "{err}"
319
319
  );
320
320
  assert!(
321
- err.contains("hint:") && err.contains("`todo`"),
321
+ err.contains("hint:") && err.contains("`Unit`"),
322
322
  "{err}"
323
323
  );
324
324
  assert!(!err.contains("export fun"), "{err}");
@@ -429,7 +429,7 @@ fn primitive_builtin_std_only() {
429
429
  let ns = dir.path().join("ns.plum");
430
430
  fs::write(
431
431
  &ns,
432
- "primitive Util =\n Enabled = true\n fun f() -> Unit =\n todo\n",
432
+ "primitive Util =\n Enabled = true\n fun f() -> Unit =\n Unit\n",
433
433
  )
434
434
  .unwrap();
435
435
  let err = errText(loadAndMergeDiag(&ns, dir.path()).unwrap_err());
@@ -439,7 +439,7 @@ fn primitive_builtin_std_only() {
439
439
  let err = errText(loadAndMergeDiag(&consts, dir.path()).unwrap_err());
440
440
  assert!(err.contains("primitive Config is only allowed in std"), "{err}");
441
441
  let plain = dir.path().join("plain.plum");
442
- fs::write(&plain, "Retries = true\n\nfun f() -> Unit =\n todo\n").unwrap();
442
+ fs::write(&plain, "Retries = true\n\nfun f() -> Unit =\n Unit\n").unwrap();
443
443
  assert!(loadAndMergeDiag(&plain, dir.path()).is_ok());
444
444
  // Inside std, a built-in: fine.
445
445
  let std = dir.path().join("std");
compiler/core/tests/core/parser_test.rs CHANGED
@@ -52,7 +52,7 @@ enum Cat =
52
52
  self.name
53
53
 
54
54
  fun setName(self, n: Str) =
55
- todo
55
+ Unit
56
56
  ";
57
57
  let source = parse(src);
58
58
  assert_eq!(
compiler/lsp/src/completion.rs CHANGED
@@ -47,7 +47,6 @@ const KEYWORDS: &[&str] = &[
47
47
  "range",
48
48
  "match",
49
49
  "when",
50
- "todo",
51
50
  "assert",
52
51
  "test",
53
52
  "self",
compiler/tooling/tree-sitter-plum/grammar.js CHANGED
@@ -290,7 +290,6 @@ module.exports = grammar({
290
290
  $.for,
291
291
  $.while,
292
292
  $.return,
293
- $.todo,
294
293
  $.crash,
295
294
  $.expression
296
295
  ),
@@ -353,7 +352,6 @@ module.exports = grammar({
353
352
  return: ($) => prec.right(2, seq("return", optional($.expression))),
354
353
  break: (_) => prec.left("break"),
355
354
  continue: (_) => prec.left("continue"),
356
- todo: (_) => prec.left("todo"),
357
355
  // `crash "msg"` — stops the program with a message.
358
356
  crash: ($) => prec.right(2, seq("crash", $.expression)),
359
357
 
compiler/tooling/tree-sitter-plum/queries/plum/highlights.scm CHANGED
@@ -129,8 +129,6 @@
129
129
  "assert"
130
130
  ] @keyword.control.return
131
131
 
132
- (todo) @keyword.control.exception
133
-
134
132
  (native) @keyword
135
133
 
136
134
  (builtin_call
compiler/tooling/tree-sitter-plum/src/grammar.json CHANGED
Binary file
compiler/tooling/tree-sitter-plum/src/node-types.json CHANGED
Binary file
compiler/tooling/tree-sitter-plum/src/parser.c CHANGED
Binary file
compiler/tooling/tree-sitter-plum/test/corpus/function.txt CHANGED
@@ -3,7 +3,7 @@ function - no return
3
3
  ================================================================================
4
4
 
5
5
  fun sum(a: Int, b: Int) =
6
- todo
6
+ 1
7
7
 
8
8
  --------------------------------------------------------------------------------
9
9
 
@@ -19,14 +19,16 @@ fun sum(a: Int, b: Int) =
19
19
  (type
20
20
  (type_identifier)))
21
21
  (body
22
+ (expression
23
+ (primary_expression
22
- (todo))))
24
+ (integer))))))
23
25
 
24
26
  ================================================================================
25
27
  function - return
26
28
  ================================================================================
27
29
 
28
30
  fun sum(a: Int, b: Int) -> Int =
29
- todo
31
+ 1
30
32
 
31
33
  --------------------------------------------------------------------------------
32
34
 
@@ -44,14 +46,16 @@ fun sum(a: Int, b: Int) -> Int =
44
46
  (type
45
47
  (type_identifier))
46
48
  (body
49
+ (expression
50
+ (primary_expression
47
- (todo))))
51
+ (integer))))))
48
52
 
49
53
  ================================================================================
50
54
  function - default value
51
55
  ================================================================================
52
56
 
53
57
  fun random(a: Int = 10) =
54
- todo
58
+ 1
55
59
 
56
60
  --------------------------------------------------------------------------------
57
61
 
@@ -66,14 +70,16 @@ fun random(a: Int = 10) =
66
70
  (primary_expression
67
71
  (integer))))
68
72
  (body
73
+ (expression
74
+ (primary_expression
69
- (todo))))
75
+ (integer))))))
70
76
 
71
77
  ================================================================================
72
78
  function - generics
73
79
  ================================================================================
74
80
 
75
81
  fun add(param: T, param2: List[U]) -> List[U] =
76
- todo
82
+ 1
77
83
 
78
84
  --------------------------------------------------------------------------------
79
85
 
@@ -95,14 +101,16 @@ fun add(param: T, param2: List[U]) -> List[U] =
95
101
  (type
96
102
  (type_identifier)))
97
103
  (body
104
+ (expression
105
+ (primary_expression
98
- (todo))))
106
+ (integer))))))
99
107
 
100
108
  ================================================================================
101
109
  function - bare self param (top-level, not a method receiver annotation)
102
110
  ================================================================================
103
111
 
104
112
  fun remove(self, v: T) =
105
- todo
113
+ 1
106
114
 
107
115
  --------------------------------------------------------------------------------
108
116
 
@@ -115,7 +123,9 @@ fun remove(self, v: T) =
115
123
  (type
116
124
  (type_identifier)))
117
125
  (body
126
+ (expression
127
+ (primary_expression
118
- (todo))))
128
+ (integer))))))
119
129
 
120
130
  ================================================================================
121
131
  function - variant construction call (positional args on a capitalized name)
@@ -588,3 +598,26 @@ fun sqrt(x: Float) -> Float =
588
598
  (expression
589
599
  (primary_expression
590
600
  (native))))))
601
+
602
+ ==================
603
+ function - todo is an ordinary name
604
+ ==================
605
+
606
+ fun f(todo: Int) -> Int =
607
+ todo
608
+
609
+ ---
610
+
611
+ (source
612
+ (fn
613
+ (fn_identifier)
614
+ (param
615
+ (var_identifier)
616
+ (type
617
+ (type_identifier)))
618
+ (type
619
+ (type_identifier))
620
+ (body
621
+ (expression
622
+ (primary_expression
623
+ (var_identifier))))))
compiler/tooling/vscode-plum/syntaxes/plum.tmLanguage.json CHANGED
@@ -52,7 +52,7 @@
52
52
  },
53
53
  {
54
54
  "name": "keyword.control.plum",
55
- "match": "\\b(import|return|continue|break|match|when|if|then|else|while|for|range|assert|todo|crash|is|as)\\b"
55
+ "match": "\\b(import|return|continue|break|match|when|if|then|else|while|for|range|assert|crash|is|as)\\b"
56
56
  },
57
57
  {
58
58
  "name": "keyword.operator.splat.plum",
compiler/wasm-codegen/src/closures.rs CHANGED
@@ -171,7 +171,7 @@ impl<'a, 't> ClosureWalker<'a, 't> {
171
171
  self.walkBlock(&case.body);
172
172
  }
173
173
  }
174
- ast::Stmt { kind: ast::StmtKind::Todo | ast::StmtKind::Native, .. } => {}
174
+ ast::Stmt { kind: ast::StmtKind::Native, .. } => {}
175
175
  ast::Stmt { kind: ast::StmtKind::Crash(e), .. } => self.walkExpr(e),
176
176
  }
177
177
  }
compiler/wasm-codegen/src/fnbody.rs CHANGED
@@ -168,7 +168,7 @@ impl<'a> Collector<'a> {
168
168
  self.walkBlock(&case.body);
169
169
  }
170
170
  }
171
- ast::Stmt { kind: ast::StmtKind::Todo | ast::StmtKind::Native, .. } => {}
171
+ ast::Stmt { kind: ast::StmtKind::Native, .. } => {}
172
172
  ast::Stmt { kind: ast::StmtKind::Crash(e), .. } => self.walkExpr(e),
173
173
  }
174
174
  }
compiler/wasm-codegen/src/stmts.rs CHANGED
@@ -50,7 +50,7 @@ pub(crate) fn compileBlockInValuePosition(
50
50
  }
51
51
 
52
52
  /// Compiles a single statement in value position: a bare expression is left on the stack
53
- /// (not dropped); `return`/`todo` compile normally (both are stack-polymorphic in wasm —
53
+ /// (not dropped); `return`/`@native` compile normally (both are stack-polymorphic in wasm —
54
54
  /// control never falls through past them, so no value is needed on this path); `if`/`match`
55
55
  /// recurse so every arm/branch resolves the same way. Any other statement kind can't
56
56
  /// produce a value, so this returns a clear error instead of ever emitting wasm that
@@ -65,7 +65,7 @@ pub(crate) fn compileStmtInValuePosition(
65
65
  match stmt {
66
66
  ast::Stmt { kind: ast::StmtKind::Expr(e, ..), .. } => compileExpr(e, body, ctx, state),
67
67
  ast::Stmt { kind: ast::StmtKind::Return(_), .. }
68
- | ast::Stmt { kind: ast::StmtKind::Todo | ast::StmtKind::Native, .. }
68
+ | ast::Stmt { kind: ast::StmtKind::Native, .. }
69
69
  | ast::Stmt { kind: ast::StmtKind::Crash(_), .. } => {
70
70
  compileStmt(stmt, body, ctx, state)
71
71
  }
@@ -465,7 +465,7 @@ fn compileStmtNode(
465
465
  Instruction::Call(crash_idx).encode(body);
466
466
  Instruction::Unreachable.encode(body);
467
467
  }
468
- ast::Stmt { kind: ast::StmtKind::Todo | ast::StmtKind::Native, .. } => {
468
+ ast::Stmt { kind: ast::StmtKind::Native, .. } => {
469
469
  // Marks an unimplemented body — trap rather than silently continuing.
470
470
  Instruction::Unreachable.encode(body);
471
471
  }
compiler/wasm-codegen/tests/wasm_codegen/codegen_tests.rs CHANGED
@@ -319,32 +319,25 @@ fun main() -> Int =
319
319
  );
320
320
  }
321
321
 
322
+ /// `todo` is no longer a statement: it is a name like any other, undefined unless the
323
+ /// program defines it, so a body left as `todo` no longer compiles (it used to trap).
322
324
  #[test]
323
- fn todoTrapsAtRuntime() {
325
+ fn todoIsAnOrdinaryName() {
324
- // `todo` marks an unimplemented body — it must trap, not silently do nothing.
325
- let src = "\
326
+ let undefined = "\
326
327
  fun notDoneYet() -> Int =
327
328
  todo
328
329
 
329
330
  fun main() -> Int =
330
331
  notDoneYet()
331
332
  ";
332
- let source = parse(src);
333
- let bytes = compileSource(&source).expect("compile failed");
333
+ let text = compileSource(&parse(undefined)).expect_err("`todo` is undefined");
334
- let engine = gcEngine();
335
- let module = wasmtime::Module::new(&engine, &bytes).unwrap();
336
- let mut store = wasmtime::Store::new(&engine, ());
337
- let instance = wasmtime::Instance::new(&mut store, &module, &[]).unwrap();
334
+ assert!(text.contains("undefined name 'todo'"), "{text}");
338
- let main = instance
335
+ let defined = "\
339
- .get_typed_func::<(), i64>(&mut store, "main")
340
- .unwrap();
341
- let err = main.call(&mut store, ()).expect_err("todo should trap");
342
- assert_eq!(
343
- err.downcast_ref::<wasmtime::Trap>(),
344
- Some(&wasmtime::Trap::UnreachableCodeReached),
345
- "got: {}",
336
+ fun main() -> Int =
337
+ todo := 41
346
- err
338
+ todo + 1
347
- );
339
+ ";
340
+ assert_eq!(runInt(defined), 42);
348
341
  }
349
342
 
350
343
  #[test]
docs/language.md CHANGED
@@ -146,7 +146,7 @@ fun halve(start: Int) -> Int =
146
146
 
147
147
  To carry a value from step to step, use `fold`, `find` or recursion (see [Loops](#loops)).
148
148
 
149
- `assert n > 0` stops the program if the condition is false. `todo` marks a body you haven't written yet, and stops the program if it is reached.
149
+ `assert n > 0` stops the program if the condition is false.
150
150
 
151
151
  ## Structs
152
152
 
examples/basics.plum CHANGED
@@ -62,8 +62,8 @@ fun isEven(n: Int) -> Bool =
62
62
  fun addInts(a: Int, b: Int) -> Int =
63
63
  a + b
64
64
 
65
- fun greet() =
65
+ fun greet() -> Str =
66
- todo
66
+ "{Greeting}, world"
67
67
 
68
68
  fun withDefault(a: Int, step: Int = 1) -> Int =
69
69
  a + step
examples/control_flow.plum CHANGED
@@ -50,9 +50,6 @@ fun sumDigits(n: Int, total: Int) -> Int =
50
50
  else
51
51
  sumDigits(n / 10, total + n % 10)
52
52
 
53
- fun placeholder() =
54
- todo
55
-
56
53
  fun checkPositive(n: Int) =
57
54
  assert n > 0
58
55