catala/compiler
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
..
dcalc Swap boxing and annotations in expressions 2022-10-07 18:00:23 +02:00
desugared Make scopes directly callable 2022-10-21 17:17:26 +02:00
lcalc Rename Expr.Box.inj to Expr.Box.lift 2022-10-21 15:35:49 +02:00
literate Fix all lines too long problems & update assets 2022-08-29 15:46:06 +02:00
plugins Make all supertypes use ('a, 't) gexpr as parameter instead of naked_gexpr 2022-08-29 11:29:24 +02:00
scalc Make all supertypes use ('a, 't) gexpr as parameter instead of naked_gexpr 2022-08-29 11:29:24 +02:00
scopelang Make scopes directly callable 2022-10-21 17:17:26 +02:00
shared_ast Make scopes directly callable 2022-10-21 17:17:26 +02:00
surface Make scopes directly callable 2022-10-21 17:17:26 +02:00
utils Used shared_ast for scopelang expressions 2022-08-26 11:31:14 +02:00
verification Swap boxing and annotations in expressions 2022-10-07 18:00:23 +02:00
catala_web_interpreter.ml Cli: allow standard option --color=always|never|auto to control styling 2022-07-27 10:42:35 +02:00
catala.ml reformat (sync with master) 2022-03-09 10:43:17 +01:00
driver.ml Make scopes directly callable 2022-10-21 17:17:26 +02:00
driver.mli Add support for backend plugins using dynlink 2022-05-19 10:40:02 +02:00
dune Switch from calendarlib to in-house dates_calc 2022-08-06 17:07:01 +02:00
index.mld refactor(runtimes): add runtime_ocaml and runtime_jsoo in the catala package 2022-07-22 16:52:56 +02:00
plugin.ml Leverage the shared AST: big cleanup (part I) 2022-08-22 19:28:21 +02:00
plugin.mli Leverage the shared AST: big cleanup (part I) 2022-08-22 19:28:21 +02:00