catala/compiler/surface
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
..
.ocamlformat-ignore Workaround some ocamlformat crashes 2022-05-11 16:21:07 +02:00
ast.ml Make scopes directly callable 2022-10-21 17:17:26 +02:00
desugaring.ml Make scopes directly callable 2022-10-21 17:17:26 +02:00
desugaring.mli Big reformatting 2022-03-08 15:03:14 +01:00
dune Merge branch 'master' into dates_calc_lib 2022-08-06 17:26:55 +02:00
fill_error_tokens.py Big renaming and dir reorg 2021-06-21 11:39:06 +02:00
fill_positions.ml Propagate renaming of Pos.mark* into module Marked 2022-07-11 16:51:54 +02:00
fill_positions.mli Big reformatting 2022-03-08 15:03:14 +01:00
lexer_common.ml Improvements to expiration checking 2022-09-07 17:14:22 +02:00
lexer_common.mli Fix doc generation 2022-04-14 11:18:26 +02:00
lexer_en.cppo.ml Add local 'let in' bindings 2022-08-09 12:17:31 +02:00
lexer_en.mli Big reformatting 2022-03-08 15:03:14 +01:00
lexer_fr.cppo.ml Add local 'let in' bindings 2022-08-09 12:17:31 +02:00
lexer_fr.mli Big reformatting 2022-03-08 15:03:14 +01:00
lexer_pl.cppo.ml Add local 'let in' bindings 2022-08-09 12:17:31 +02:00
lexer_pl.mli Big reformatting 2022-03-08 15:03:14 +01:00
lexer.cppo.ml Remove division durations 2022-08-19 15:21:29 +02:00
name_resolution.ml Make scopes directly callable 2022-10-21 17:17:26 +02:00
name_resolution.mli Make scopes directly callable 2022-10-21 17:17:26 +02:00
parse_utils.ml Big reformatting 2022-03-08 15:03:14 +01:00
parse_utils.mli Big reformatting 2022-03-08 15:03:14 +01:00
parser_driver.ml Propagate renaming of Pos.mark* into module Marked 2022-07-11 16:51:54 +02:00
parser_driver.mli Big reformatting 2022-03-08 15:03:14 +01:00
parser_errors.mli Big reformatting 2022-03-08 15:03:14 +01:00
parser.messages Make scopes directly callable 2022-10-21 17:17:26 +02:00
parser.mly Make scopes directly callable 2022-10-21 17:17:26 +02:00
print.ml Big reformatting 2022-03-08 15:03:14 +01:00
print.mli Big reformatting 2022-03-08 15:03:14 +01:00
surface.mld Documentation pass 2022-01-19 10:54:16 +01:00
tokens.mly Improvements to expiration checking 2022-09-07 17:14:22 +02:00