Skip to content

Clean up :: syntax, add effect declarations and raise expressions#159

Merged
rvcas merged 28 commits into
mainfrom
tad/effect-decls
Jul 12, 2026
Merged

Clean up :: syntax, add effect declarations and raise expressions#159
rvcas merged 28 commits into
mainfrom
tad/effect-decls

Conversation

@SpaceManiac

@SpaceManiac SpaceManiac commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Firstly, this adds effect declaration syntax, and raise.

However, the grammar, parsing, and typechecking for events in particular and for function calls in general was pretty messy, so also clean them up:

  • A::B is no longer an enum constructor that might be followed by a unit, struct, or tuple variant, but a scoped name that might be a bare identifier, followed by a struct constructor, or followed by a function call.
  • Patterns are also adjusted such that :: does not necessarily mean enum.
  • The typechecker tracks nested namespaces and uses those when resolving A::B lookups.
  • Events (and thus effects) are not in a separate zone, instead being part of the value zone with functions (Namespace::constants).
  • Enum unit variants and tuple variants also go into the value zone, while struct variants go into the struct constructor zone.
  • emit, raise, and runtime syntaxes now match each other and the call expression. To the typechecker, they are simply alternate forms of the call expression that make a different assertion about the function's keyword kind. To codegen, all four are equivalent.

Also, for codegen, functions types are optionally tagged with an identity, currently their name as a string, but it could be an integer ID in the future. This identity is used to make let bar = foo; bar(); work.

This is a net simplification of the grammar and of type inference.

Future work:

  • Syntax for catching & resuming effects
  • Codegen & plan for runtime support for catching & resuming effects
  • Possible further inference data structure improvements (to avoid cloning heavyweight Types so much)

Signed-off-by: Tad Hardesty <tad.hardesty@midnight.foundation>
Signed-off-by: Tad Hardesty <tad.hardesty@midnight.foundation>
Signed-off-by: Tad Hardesty <tad.hardesty@midnight.foundation>
Signed-off-by: Tad Hardesty <tad.hardesty@midnight.foundation>
Signed-off-by: Tad Hardesty <tad.hardesty@midnight.foundation>
Signed-off-by: Tad Hardesty <tad.hardesty@midnight.foundation>
Signed-off-by: Tad Hardesty <tad.hardesty@midnight.foundation>
Signed-off-by: Tad Hardesty <tad.hardesty@midnight.foundation>
Signed-off-by: Tad Hardesty <tad.hardesty@midnight.foundation>
Signed-off-by: Tad Hardesty <tad.hardesty@midnight.foundation>
Signed-off-by: Tad Hardesty <tad.hardesty@midnight.foundation>
Signed-off-by: Tad Hardesty <tad.hardesty@midnight.foundation>
Signed-off-by: Tad Hardesty <tad.hardesty@midnight.foundation>
Signed-off-by: Tad Hardesty <tad.hardesty@midnight.foundation>
Signed-off-by: Tad Hardesty <tad.hardesty@midnight.foundation>
Signed-off-by: Tad Hardesty <tad.hardesty@midnight.foundation>
Signed-off-by: Tad Hardesty <tad.hardesty@midnight.foundation>
Signed-off-by: Tad Hardesty <tad.hardesty@midnight.foundation>
Signed-off-by: Tad Hardesty <tad.hardesty@midnight.foundation>
Signed-off-by: Tad Hardesty <tad.hardesty@midnight.foundation>
Signed-off-by: Tad Hardesty <tad.hardesty@midnight.foundation>
Signed-off-by: Tad Hardesty <tad.hardesty@midnight.foundation>
Signed-off-by: Tad Hardesty <tad.hardesty@midnight.foundation>
Signed-off-by: Tad Hardesty <tad.hardesty@midnight.foundation>
Signed-off-by: Tad Hardesty <tad.hardesty@midnight.foundation>
Signed-off-by: Tad Hardesty <tad.hardesty@midnight.foundation>
@SpaceManiac

SpaceManiac commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

Current diff stat except *.snap and tree-sitter-starstream/src

 docs/errors/E0001.md                                                                           |    4 +-
 docs/errors/E0017.md                                                                           |    8 +-
 docs/errors/E0038.md                                                                           |   14 +-
 docs/errors/E0039.md                                                                           |   15 +-
 docs/errors/E0040.md                                                                           |   24 +-
 docs/errors/E0041.md                                                                           |   15 -
 docs/language-spec.md                                                                          |   64 ++--
 starstream-compiler/src/docs.rs                                                                |   31 +-
 starstream-compiler/src/formatter.rs                                                           |  234 ++++++--------
 starstream-compiler/src/parser/definition/abi.rs                                               |   38 ++-
 starstream-compiler/src/parser/expression/postfix.rs                                           |   24 +-
 starstream-compiler/src/parser/expression/primary/emit.rs                                      |   44 ---
 starstream-compiler/src/parser/expression/primary/emit_raise_runtime.rs                        |   92 ++++++
 starstream-compiler/src/parser/expression/primary/enum_constructor.rs                          |   53 ----
 starstream-compiler/src/parser/expression/primary/literal.rs                                   |    4 -
 starstream-compiler/src/parser/expression/primary/mod.rs                                       |   39 ++-
 starstream-compiler/src/parser/expression/primary/raise.rs                                     |   29 --
 starstream-compiler/src/parser/expression/primary/runtime.rs                                   |   29 --
 starstream-compiler/src/parser/expression/primary/{struct_literal.rs => struct_constructor.rs} |   14 +-
 starstream-compiler/src/parser/pattern.rs                                                      |   50 +--
 starstream-compiler/src/parser/primitives.rs                                                   |   32 +-
 starstream-compiler/src/typecheck/builtins.rs                                                  |   20 +-
 starstream-compiler/src/typecheck/env.rs                                                       |    4 +-
 starstream-compiler/src/typecheck/errors.rs                                                    |   81 +++--
 starstream-compiler/src/typecheck/exhaustiveness.rs                                            |  181 ++++++-----
 starstream-compiler/src/typecheck/infer.rs                                                     | 2388 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------------------------------------------------------
 starstream-compiler/src/typecheck/tests.rs                                                     |   11 -
 starstream-interpreter/src/lib.rs                                                              |   17 +-
 starstream-language-server/src/document.rs                                                     |  201 ++++++------
 starstream-to-wasm/src/lib.rs                                                                  |  443 ++++++++++++++------------
 starstream-to-wasm/tests/inputs/effect_raise.star                                              |    7 +
 starstream-types/src/ast.rs                                                                    |  168 ++++++----
 starstream-types/src/typed_ast.rs                                                              |  139 +++++----
 starstream-types/src/types.rs                                                                  |  117 ++++---
 tree-sitter-starstream/grammar.js                                                              |  189 ++++--------
 tree-sitter-starstream/queries/highlights.scm                                                  |   19 +-
 zed-starstream/languages/starstream/highlights.scm                                             |   19 +-
 37 files changed, 2176 insertions(+), 2685 deletions(-)

Signed-off-by: Tad Hardesty <tad.hardesty@midnight.foundation>
Signed-off-by: Tad Hardesty <tad.hardesty@midnight.foundation>
@SpaceManiac SpaceManiac changed the title Add effect declarations and raise expressions, and rejigger typechecking Clean up :: syntax, add effect declarations and raise expressions Jul 10, 2026
@SpaceManiac SpaceManiac marked this pull request as ready for review July 10, 2026 23:14
@SpaceManiac SpaceManiac requested a review from rvcas July 10, 2026 23:15
@rvcas rvcas merged commit b27ed62 into main Jul 12, 2026
5 checks passed
@rvcas rvcas deleted the tad/effect-decls branch July 12, 2026 23:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants