Skip to content

Add effect declarations and raise expressions, and rejigger typechecking#159

Draft
SpaceManiac wants to merge 26 commits into
mainfrom
tad/effect-decls
Draft

Add effect declarations and raise expressions, and rejigger typechecking#159
SpaceManiac wants to merge 26 commits into
mainfrom
tad/effect-decls

Conversation

@SpaceManiac

Copy link
Copy Markdown
Contributor

Draft because this should probably be split into smaller PRs.

Primarily, 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 (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.

Signed-off-by: Tad Hardesty <[email protected]>
Signed-off-by: Tad Hardesty <[email protected]>
Signed-off-by: Tad Hardesty <[email protected]>
Signed-off-by: Tad Hardesty <[email protected]>
@SpaceManiac

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                                                                |   25 +-
 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                                                  |   16 +-
 starstream-compiler/src/typecheck/errors.rs                                                    |   81 ++++--
 starstream-compiler/src/typecheck/exhaustiveness.rs                                            |  181 ++++++------
 starstream-compiler/src/typecheck/infer.rs                                                     | 2139 +++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------------------------------------------
 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                                                                  |  458 ++++++++++++++++--------------
 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                                                                  |  100 ++++---
 tree-sitter-starstream/grammar.js                                                              |  189 ++++---------
 tree-sitter-starstream/queries/highlights.scm                                                  |   19 +-
 zed-starstream/languages/starstream/highlights.scm                                             |   19 +-
 36 files changed, 2043 insertions(+), 2553 deletions(-)

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.

1 participant