Commit graph

754 commits

Author SHA1 Message Date
Luke Boswell
cce33c03d6
desugar ValueDef::Expect suffixed nodes 2024-09-23 17:57:25 +10:00
Sam Mohr
2ea6a5d79c
Merge branch 'main' into remove-old-record-builder 2024-09-21 04:54:03 -07:00
Sam Mohr
2da08be8ef
Remove old record builder syntax 2024-09-21 04:44:44 -07:00
Agus Zubiaga
5054c9990e
Desugar module param patterns before canonicalizing 2024-09-20 16:35:18 -03:00
Agus Zubiaga
3f9e957c9c
Extract record destructure desugaring into its own fn 2024-09-20 16:30:59 -03:00
Agus Zubiaga
3eadc03e28
Add failing test for multiline params 2024-09-20 16:19:56 -03:00
snobee
e82dd43465
Merge remote-tracking branch 'upstream/MAIN' into early-return-if-else 2024-09-06 17:11:28 -07:00
snobee
139f6ae82c
update tests for new Expr::If struct 2024-09-06 16:28:14 -07:00
Elias Mulhall
85aad0d000
Move comment explaining use of line_info field into can::Env struct definition 2024-09-05 20:13:54 -04:00
Elias Mulhall
25af18daaa
Cleanup unused function param 2024-09-05 20:13:54 -04:00
Elias Mulhall
19931ecd43
Support passing values into dbg with the pipe operator
In order to desugar `dbg` in a pipeline we need to allow a bare `dbg`
node in desugaring and only report it as an error if the bare node
survives to the next step of canonicalization. This means we move the
error code out of `desugar_expr` and into `canonicalize_expr`. This is
much simpler to do now that these functions use the same `env` struct,
since previously we would have had to pass down extra args to
`canonicalize_expr`. Sharing the `env` struct means that we also don't
have to worry about calculating `line_info` more than once.
2024-09-05 20:13:54 -04:00
Elias Mulhall
b515bfa77e
Use a shared env for desugaring and the rest of canonicalization
This refactor simplifies the desugar pass by reducing the number of
arguments threaded through each recursive function call.

- Add the module src string to `Env`.
- Add `line_info` to `Env` as a lazy-evaled function.
- Refactor desugar functions to take the `can::Env` struct in place of a
  number of params. This is mostly a find-and-replace, but in a few
  places `Vec::from_iter_in` was changed to `Vec::with_capacity_in`
  followed by a `for` loop in order to avoid lifetime issues.
- Remove unnecessary linter annotations for `clippy::too_many_arguments`
2024-09-05 20:13:48 -04:00
snobee
a7afac7ac7
Add boolean flag to Expr::If for indented else statement 2024-09-05 16:28:44 -07:00
Elias Mulhall
82d0566041
Use module scope instead of var store to generate idents in dbg desugar
Fix a bug in `dbg` expression desugaring by using the module scope to
generate unique identifiers instead of the variable store.

In the initial implementation of `dbg` expressions we used the
`VarStore` to generate unique identifiers for new variables created
during desugaring. We should have instead used the current module's
`Scope`, which handles identifiers within the module. Each scope has its
own incrementing variable count which is independent of the shared
variable store. The scope is used to generate new identifiers at other
points in canonicalization, such as when assigning a global identifier
to closures and `expect`s. It's possible that the identifier generated
for `dbg` could conflict with an identifier generated by the scope,
resulting in a confusing error.
2024-09-03 14:00:39 -04:00
Anton-4
02cf61f985
Merge pull request #7038 from mulias/expr-dbg
Support `dbg` in expressions
2024-09-02 13:30:32 +02:00
Anton-4
3c679f6338
Merge branch 'main' into lower-module-params 2024-08-30 16:29:46 +02:00
Elias Mulhall
56c5b790a7 Refactor dbg expression parsing to work more like function application
Instead of parsing dbg with an expression block, parse the dbg keyword
with no additional arguments. This way the parser treats dbg just like a
variable in function application. We desugar by pattern matching on
`Apply(Dbg, args, called_via)` nodes. This changes the output of syntax
tests since the initial AST is different, but does not change the output
of can or mono.

Add two new errors for dbg in expression position with either no args or
too many args. This is similar to the error behavior of `crash`.

Continue to parse dbg statements with an expression block, as before.
2024-08-29 15:36:48 -04:00
Elias Mulhall
fefb4a3115 Don't use debug formatting to convert Variable into string 2024-08-28 12:51:02 -04:00
Elias Mulhall
7a07f13f31 Test dbg expr desugaring 2024-08-28 12:16:22 -04:00
Elias Mulhall
4cf214869e Extract helper functions for desugaring dbg statements and expressions
This reduces code duplication because `desugar_dbg_expr` calls
`desugar_dbg_stmt`. We will also reuse these functions for desugaring
dbg in pipelines.
2024-08-28 11:53:44 -04:00
Elias Mulhall
9dae102603 Allow dbg expression inside string interpolation 2024-08-28 11:53:44 -04:00
Elias Mulhall
220bb55048 Desugar dbg expression into a dbg statement
Use a temporary variable to print and then return the body of the dbg
expression.
2024-08-28 11:53:44 -04:00
Elias Mulhall
335265e15c Parse dbg in expression position
Add dbg parsing logic everywhere we parse normal expressions. Add
special case to statement parsing to handle a series of statements
ending in a `dbg` in expression position.

Rename existing `dbg_help` function to `dbg_stmt_help`, similarly rename
syntax snapshot test files to specify which ones are for dbg statements.
2024-08-28 11:53:44 -04:00
Elias Mulhall
43d932df3b Update parser AST to support dbg as both a statment and expression
Make `Expr::Dbg` node specific to dbg expressions, add `Expr::DbgStmt`
for dbg statements. Debug expressions don't have a continuation branch.
Support formatting both kinds of `Dbg` nodes.
2024-08-28 11:53:44 -04:00
Elias Mulhall
a16f757164 Pass var_store into desugar_expr so that desugaring may generate fresh vars 2024-08-28 11:53:44 -04:00
Agus Zubiaga
287a8fa2e7
Merge branch 'main' into lower-module-params 2024-08-28 08:50:40 -03:00
Agus Zubiaga
49a6b1bfba
Capture whole params record when needed 2024-08-27 11:20:59 -03:00
Agus Zubiaga
80770fae11
Handle aliases at call instead 2024-08-27 02:51:23 -03:00
Agus Zubiaga
36df43fadc
Handle simple aliased fn in params value def 2024-08-27 01:27:54 -03:00
Agus Zubiaga
b667753a32
Capture import params def 2024-08-26 23:31:42 -03:00
Agus Zubiaga
2f4e80b696
Gather arities while building can declarations 2024-08-26 22:39:35 -03:00
Sam Mohr
12df3a04de
Merge attempt 2024-08-19 23:34:05 -07:00
Sam Mohr
7c7485bb04
Merge pull request #7005 from smores56/deprecate-backpassing
Deprecate backpassing to prepare for eventual removal
2024-08-18 08:08:29 -04:00
Agus Zubiaga
50887e6265
Capture params in nested defs 2024-08-17 16:13:44 -03:00
Agus Zubiaga
519ff56a85
Create can::module::ModuleParams for convenience 2024-08-17 13:10:37 -03:00
Agus Zubiaga
e80e3e5b2d
Convert top-level value def to fn taking params 2024-08-17 11:21:21 -03:00
Sam Mohr
50f6e11423
Deprecate backpassing to prepare for eventual removal 2024-08-16 22:36:04 -07:00
Agus Zubiaga
7a8b9f7d6d
Add variable to ParamsVar 2024-08-16 20:54:16 -03:00
Sam Mohr
209d78f72c
Minor formatting fix 2024-08-16 01:52:56 -07:00
Sam Mohr
b1a972ab21
Implement &foo record updater syntax sugar 2024-08-16 01:41:59 -07:00
Sam Mohr
0fd0cc11aa
Format code 2024-08-14 22:26:32 -07:00
Sam Mohr
3bc5c1dc12
Combine ! and ? into single TrySuffix AST node 2024-08-14 22:14:08 -07:00
Sam Mohr
7e72541a79 Merge branch 'main' into builtin-task 2024-08-12 23:12:38 -07:00
Agus Zubiaga
762799052e
Merge branch 'main' into typecheck-module-params 2024-08-07 18:55:33 -03:00
Sam Mohr
00bc699642
Add syntax tests for record builder 2024-08-06 22:49:35 -07:00
Sam Mohr
cb8040f629
Ignore underscore-prefixed fields in record builders 2024-08-06 22:49:35 -07:00
Sam Mohr
66cf946965 Fix PR comments 2024-08-03 04:37:31 -07:00
Sam Mohr
8288af3156
Merge branch 'main' into builtin-task 2024-07-31 13:36:32 -07:00
Aidan
4bf5154610 remove spaces_middle from crates/compiler/can/src/desugar.rs 2024-07-29 13:11:57 -04:00
Aidan
ddb58a2cd5 spaces_middle -> lines_between 2024-07-29 13:06:48 -04:00