Skip to content
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

Fix: force the evaluation of all boolean expression clauses #282

Open
EmileRolley opened this issue Jun 22, 2022 · 2 comments
Open

Fix: force the evaluation of all boolean expression clauses #282

EmileRolley opened this issue Jun 22, 2022 · 2 comments
Assignees
Labels
🔚 backends Backend runtime or code generation ❌ bug Something isn't working 🔧 compiler Issue concerns the compiler 👌 good first issue Good for newcomers

Comments

@EmileRolley
Copy link
Collaborator

EmileRolley commented Jun 22, 2022

While refactoring the log event structure in #280, I found that generated raw log events by compiled catala programs differ from the interpreter log trace.

It appears that it comes from the laziness of the and and or operators in OCaml, resulting that when evaluating the expression x and f y if x == false then the whole expression is evaluated to false without calling f with y.

Example on tests_allocations_familiales.catala_fr with the scope Test1

Example of raw events retrieved from the OCaml program:

[161/528] Parsing event: VariableDefinition([ AllocationsFamiliales, droit_ouvert_forfaitaire, input ], _)
[162/528] Parsing event: BeginCall([ AllocationsFamiliales, droit_ouvert_forfaitaire ])
[163/528] Parsing event: DecisionTaken(_)
[164/528] Parsing event: VariableDefinition([ AllocationsFamiliales, droit_ouvert_forfaitaire, output ], _)
[165/528] Parsing event: EndCall([ AllocationsFamiliales, droit_ouvert_forfaitaire ])

The corresponding log events from the interpreter -- the call to PrestationsFamiliales.conditions_hors_âge is missing in the OCaml program log trace.

[LOG]     →  AllocationsFamiliales.droit_ouvert_forfaitaire
[LOG]       ≔  AllocationsFamiliales.droit_ouvert_forfaitaire.input: Enfant {"identifiant"= 1; "obligation_scolaire"= Pendant (); "rémuneration_mensuelle"= 0.00 €; "date_de_naissance"= 2007-01-01; "âge"= 13; "prise_en_charge"= EffectiveEtPermanente (); "a_déjà_ouvert_droit_aux_allocations_familiales"= true; "bénéficie_titre_personnel_aide_personnelle_logement"= false}
[LOG]       →  PrestationsFamiliales.conditions_hors_âge
[LOG]         ≔  PrestationsFamiliales.conditions_hors_âge.input: Enfant {"identifiant"= 1; "obligation_scolaire"= Pendant (); "rémuneration_mensuelle"= 0.00 €; "date_de_naissance"= 2007-01-01; "âge"= 13; "prise_en_charge"= EffectiveEtPermanente (); "a_déjà_ouvert_droit_aux_allocations_familiales"= true; "bénéficie_titre_personnel_aide_personnelle_logement"= false}
[LOG]         ☛ Definition applied:
[LOG]         ≔  PrestationsFamiliales.conditions_hors_âge.output: true
[LOG]       ←  PrestationsFamiliales.conditions_hors_âge
[LOG]       ☛ Definition applied:
[LOG]       ≔  AllocationsFamiliales.droit_ouvert_forfaitaire.output: false
[LOG]     ←  AllocationsFamiliales.droit_ouvert_forfaitaire

Solutions

In order to keep the same behavior between all targeted languages, we should force the evaluation of all clauses. To do this there are two main ways:

  1. Using let-bindings.
  2. Overiding and and or operators.
@EmileRolley EmileRolley added ❌ bug Something isn't working 🔧 compiler Issue concerns the compiler 🔚 backends Backend runtime or code generation labels Jun 22, 2022
@denismerigoux
Copy link
Contributor

Decision : we provide two different compilation mode for boolean operators. By default and with the --trace mode activated, boolean operators are eager and all their arguments need to be evaluated. This behavior should be propagated to all backends with let-encapsulated arguments to the lazy operators in the backends.If --trace mode is deactivated (with or without -O), then the semantics of the boolean operators is lazy.

The rationale is that we only care about side-effects for the tracing mode.

@denismerigoux
Copy link
Contributor

@AltGr this will be important for the work around improving the trace

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔚 backends Backend runtime or code generation ❌ bug Something isn't working 🔧 compiler Issue concerns the compiler 👌 good first issue Good for newcomers
Projects
Status: Todo
Development

No branches or pull requests

3 participants