catala/compiler/desugared
Louis Gesbert 41d6d3cbe9 Make scopes directly callable
Quite a few changes are included here, some of which have some extra
implications visible in the language:

- adds the `Scope of { -- input_v: value; ... }` construct in the language

- handle it down the pipeline:
  * `ScopeCall` in the surface AST
  * `EScopeCall` in desugared and scopelang
  * expressions are now traversed to detect dependencies between scopes
  * transformed into a normal function call in dcalc

- defining a scope now implicitely defines a structure with the same name, with
  the output variables of the scope defined as fields. This allows us to type
  the return value from a scope call and access its fields easily.
  * the implications are mostly in surface/name_resolution.ml code-wise
  * the `Scope_out` struct that was defined in scope_to_dcalc is no longer
    needed/used and the fields are no longer renamed (changes some outputs; the
    explicit suffix for variables with multiple states is ignored as well)
  * one benefit is that disambiguation works just like for structures when there
    are conflicts on field names
  * however, it's now a conflict if a scope and a structure have the same
    name (side-note: issues with conflicting enum / struct names or scope
    variables / subscope names were silent and are now properly reported)

- you can consequently use scope names as types for variables as well. Writing
  literals is not allowed though, they can only be obtained by calling the
  scope.

Remaining TODOs:

- context variables are not handled properly at the moment

- error handling on invalid calls

- tests show a small error message regression; lots of examples will need
  tweaking to avoid scope/struct name or struct fields / output variable
  conflicts

- add a `->` syntax to make struct field access distinct from scope output var
  access, enforced with typing. This is expected to reduce confusion of users
  and add a little typing precision.

- document the new syntax & implications (tutorial, cheat-sheet)

- a consequence of the changes is that subscope variables also can now be typed.
  A possible future evolution / simplification would be to rewrite subscopes as
  explicit scope calls early in the pipeline. That could also allow to manipulate
  them as expressions (bind them in let-ins, return them...)
2022-10-21 17:17:26 +02:00
..
ast.ml Rename Expr.Box.inj to Expr.Box.lift 2022-10-21 15:35:49 +02:00
ast.mli Swap boxing and annotations in expressions 2022-10-07 18:00:23 +02:00
dependency.ml Implement typing of desugared/scopelang and lcalc terms 2022-10-04 14:50:37 +02:00
dependency.mli Used shared_ast for scopelang expressions 2022-08-26 11:31:14 +02:00
desugared_to_scope.ml Make scopes directly callable 2022-10-21 17:17:26 +02:00
desugared_to_scope.mli Generalise the types to allow scopelang ASTs to be typed 2022-10-04 14:50:37 +02:00
desugared.mld Used shared_ast for scopelang expressions 2022-08-26 11:31:14 +02:00
dune Big renaming and dir reorg 2021-06-21 11:39:06 +02:00