-
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
Add experimental lazy interpreter as a plugin #453
Conversation
previously only lcalc and scalc where available
To try it (without installing Catala): ```shell-session $ make plugins $ export CATALA_PLUGINS=_build/default/compiler/plugins $ dune exec -- catala lazy examples/aides_logement/tests/tests_calcul_apl_locatif.catala_fr -s Exemple2 ``` Keep in mind that this is a work-in-progress prototype :)
Example output (very redundant since this is with lazy evaluation actually turned off and re-played each time): EDIT: note that this was obtained by commenting out the effect on this line. |
I had marked this as draft, but while this correctly describes the state of the interpreter, it's a plugin so it may be OK to merge as-is so that everyone can experiment with it. The changes to the main tree are minimal:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm okay with merging this! This is so cool, I hope you'll have time to get back to this and comment your code to show why it works from a more theoretical perspective.
module Env = struct | ||
type 'm t = | ||
| Env of | ||
((dcalc, 'm mark) gexpr, ((dcalc, 'm mark) gexpr * 'm t) ref) Var.Map.t |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious, could you put a comment describing what you're putting in the Env.t
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will! Until then: an env
maps a variable to an expression and the corresponding captured env.
I don't want to think about how much more complicated that would have been in an imperative setting :D
The ref
part is only used for laziness: the raw expression is first added to the environment, then we can replace it once computed. We don't use lazy
because we want more control (in particular, we can reduce the same expression several times with different levels)
let e, env1 = !v_env in | ||
let r, env1 = lazy_eval ctx env1 llevel e in | ||
if not (Expr.equal e r) then ( | ||
log "@[<hv 2>{{%a =@ [%a]@ ==> [%a]}}@]" Print.var_debug v |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When will this log
be shown? With the -d
flag?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now you have to replace the ifprintf
with fprintf
in the definition above 😁
Of course it won't stay like that ; the issue with depending upon -d
is that that would also change the value output, making it more verbose, we definitely need specific debug flags.
To try it (without installing Catala):
Keep in mind that this is a work-in-progress prototype :)