-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: scope context variables decorators (input, output, internal) #112
Comments
Thanks Denis for summarizing the proposal! Here's a few suggestions to simplify, or at least have a first simplified design that can be refined incrementally.
What do you think? |
These are all good suggestions, I updated the design post above accordingly. |
I don't really get the differences between the |
You read correctly, because there is none :) I propose we remove the
|
For me the keyword |
Having no keyword for the
with
It is more obvious in the second version that something is missing to qualify
rather than
All of these observations lead me to refine my proposal. I propose that we allow both (no keyword) and |
Okey, I agree with you. Do you think I can handle the implementation? |
This is definitely more ambitious than the wildcard issue, since you have to go down the entire compilation stack. The general architecture is presented here https://catala-lang.org/ocaml_docs/catala/index.html, and the formalization is here https://hal.inria.fr/hal-03159939. I guess you can take a look a those, and we can schedule a call next week to sync up before you start. Is that good for you ? |
Yes, thanks. I guess I can start to look at it and write down some questions. |
Cleaning up scopelang encoding and adding some default optimizations (beginning of #112)
The problem
Scopes in Catala can have many context variables. But as the number of context variables grows, it is more and more difficult to figure out which of these variables are output, which are input and which ones are intermediate variables that are not relevant from outside the scope. Catala users have already started using comments to annotate scope context variable declarations with this classification.
While it is the essence of Catala that context variables are neither input nor outputs by default, since they can be redefined by a calling scope, we could benefit from user annotations to enable helper lints and better code generation in the different backends.
Specification of the decorations
A regular context variable declaration looks like this:
This proposal would allow replacing the
context
with the following keywords:input
: this scope variable be defined by the caller, cannot be defined in the scopeoutput
: this scope variable cannot be defined by the caller, has to be defined in the scopeinternal
: this scope variable cannot be defined by the caller, has to be defined in the scope, and does not appear in the outputsoutput
: this scope variable can defined by the caller, can be defined in the scope, and appears in the outputsThe classifications
internal
/input
/context
on the one hand, andinternal
/output
on the other hand, form two independent classifications for respectively the input and output behavior of a scope variables. From this independent combinations of two choices between respectively 3 and 2 options are yielded 6 different possibilities for fully qualifying the input/output behavior of a scope variable:This specification defines informally two permissiveness lattices between the kinds of scope variables. Here it is, the most permissive being at the top:
Linting
If we have these four keywords, we can enforce their specification in three different ways.
Foo
, we can ensure that all the variables ofFoo
redefined in the caller are eithercontext
orinput
, but notinternal
.Foo
, we can ensure that all the variables ofFoo
used (as outputs) in defining variables of the caller areoutput
, but notinternal
context
orinternal
output
orinternal
have at least one definition.Code generation
The decorations can also help us generate code that has easier signatures than the current compilation scheme that exposes all
context
variables in both the output and input structs of the scope. More specifically:input
variables, but not theinternal
oroutput
variablesoutput
variables, but not theinternal
orinput
variablesImplementation
The implementation of this feature will impact quite a lot of areas of the compiler:
surface
,desugared
andscopelang
intermediate representations with the kind for each scope variablescopelang
intermediate representationdcalc
andlcalc
translations using the variable kind information according to the specification aboveThe text was updated successfully, but these errors were encountered: