catala/compiler/shared_ast
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
..
definitions.ml Make scopes directly callable 2022-10-21 17:17:26 +02:00
dune Simplify some type aliases 2022-08-22 19:28:27 +02:00
expr.ml Make scopes directly callable 2022-10-21 17:17:26 +02:00
expr.mli Make scopes directly callable 2022-10-21 17:17:26 +02:00
print.ml Make scopes directly callable 2022-10-21 17:17:26 +02:00
print.mli Printer: add debug version that doesn't require a context 2022-10-04 14:50:37 +02:00
program.ml Make all supertypes use ('a, 't) gexpr as parameter instead of naked_gexpr 2022-08-29 11:29:24 +02:00
program.mli Swap boxing and annotations in expressions 2022-10-07 18:00:23 +02:00
scope.ml Rename Expr.Box.inj to Expr.Box.lift 2022-10-21 15:35:49 +02:00
scope.mli Swap boxing and annotations in expressions 2022-10-07 18:00:23 +02:00
shared_ast.ml Generalise the typer 2022-10-04 14:50:37 +02:00
shared_ast.mld Rename marked_expr -> expr, expr -> naked_expr throughout 2022-08-29 11:29:23 +02:00
typing.ml Make scopes directly callable 2022-10-21 17:17:26 +02:00
typing.mli Make scopes directly callable 2022-10-21 17:17:26 +02:00
var.ml Make all supertypes use ('a, 't) gexpr as parameter instead of naked_gexpr 2022-08-29 11:29:24 +02:00
var.mli Make all supertypes use ('a, 't) gexpr as parameter instead of naked_gexpr 2022-08-29 11:29:24 +02:00