Here put what you want to share with ligo developpers. It'll not be part of the changelog.
Assignation have been added to the core of ligo and purification of assignation has been moved to self_ast_pass.
For and While loop are transformed using a recursive function while
for_each is transformed to a List.iter (using a recursive function would lead to not using ITER in michelson).
The purification of assignation is done by detecting and transforming effects into monadic value (
(value,effects)). The transformation requires strong hypothesis on the disjonction of pure fonctionnal syntaxes (cameligo) and imperative style syntax (pascaligo, jsligo). Description of the algorithm and those hypotheses can be found directly in the sources files.
In the context of this MR, an effect is something that make the code impure (opposite to pure. ie. "a function produce the same output given the same input" - doesn't really explain the write effect though).
Their is currently two effect currently in ligo link to mutble variable (the failwith being a third but kind of build-in in michelson)
- The write effect or assignation -> when you assign a new value to a variable the variable change its value not only in the local scope (which happen with shadowing in OCaml for example) but propagate the "effect" of changing the value outside of the scope.
- The read effect -> when a function is executed and read the value of a variable, it draw the value of the variable at the time of the function execution, not at the time of the function declaration. If the variable change value between two execution of said function, the behavior of the function with change accordingly, which is not what happen when you shadow the variable itself. The mutable variable act as "an hidden parameter". I see it refered as a state in the litterature.
In order to "emulate" those effects, the algorithm in this MR modify code that emit write effect by returning an extra parameter in order to propagate the new value to the top-level scope. And modify function with read effect by adding an extra parameters to functions containing all the mutable variables used by the function (stop hiddin it) and replace call to these function to pass the new extra parameters.
The transpilation has been worsen du to the non purification of assignation in the front-end.
Here put what you want to share with ligo users through changelog. Markdown formatted (### for title).
Redesign the handling of imperative construct such as loop and assignation to fix bugs and improve performances