Solves the issue by adding a new step in the build pipeline: the tact optimization phase immediately after typechecking (i.e., immediately after precompile).
Currently, the optimization phase only carries out expression simplification in the AST by running the interpreter over all expressions in the AST (later, this will be replaced by the partial evaluator). I did this in preparation for other optimization techniques that will be added in the future (for example, constant propagation will be moved to the optimization phase later).
The PR adds two CLI compiler options:
skipTactOptimizationPhase: Default is false. If true, skips the tact optimization phase. Skipping the phase is useful, for example, to carry out tests in which you want to deactivate the interpreter so that you work with the raw program. Simply add the option in your project's json:
dumpOptimizedTactCode: Default is false. If true, it will produce two files: one with the program before the optimization phase, and another one after the optimization phase, so that you can make a diff on both files and see what the optimization phase did to the program. Note that this option is ignored if the optimization phase was skipped.
NOTE: This PR does not modify the calls to the interpreter that are currently done in the FunC generator code. This means that the Tact interpreter is unnecessarily called twice. These second calls to the interpreter will be removed later in a separate issue.
NOTE 2: This PR does not modify the AST one gets from calling getRawAST on the context object ctx. I did a quick check and the FunC generation part seems to make use of the functions getAllTypes, getAllStaticFunctions and the like. This PR DOES modify the ASTs produced by those functions. The FunC generator part seems to use only the "sources" from getRawAST, but I still do not understand that part of the code.
Checklist
[ ] I have updated CHANGELOG.md
[ ] I have added tests to demonstrate the contribution is correctly implemented: this usually includes both positive and negative tests, showing the happy path(s) and featuring intentionally broken cases
[ ] I have run all the tests locally and no test failure was reported
[ ] I have run the linter, formatter and spellchecker
[ ] I did not do unrelated and/or undiscussed refactorings
Issue
Closes #970.
Solves the issue by adding a new step in the build pipeline: the tact optimization phase immediately after typechecking (i.e., immediately after
precompile
).Currently, the optimization phase only carries out expression simplification in the AST by running the interpreter over all expressions in the AST (later, this will be replaced by the partial evaluator). I did this in preparation for other optimization techniques that will be added in the future (for example, constant propagation will be moved to the optimization phase later).
The PR adds two CLI compiler options:
skipTactOptimizationPhase: Default is false. If true, skips the tact optimization phase. Skipping the phase is useful, for example, to carry out tests in which you want to deactivate the interpreter so that you work with the raw program. Simply add the option in your project's json:
dumpOptimizedTactCode: Default is false. If true, it will produce two files: one with the program before the optimization phase, and another one after the optimization phase, so that you can make a diff on both files and see what the optimization phase did to the program. Note that this option is ignored if the optimization phase was skipped.
NOTE: This PR does not modify the calls to the interpreter that are currently done in the FunC generator code. This means that the Tact interpreter is unnecessarily called twice. These second calls to the interpreter will be removed later in a separate issue.
NOTE 2: This PR does not modify the AST one gets from calling
getRawAST
on the context objectctx
. I did a quick check and the FunC generation part seems to make use of the functionsgetAllTypes
,getAllStaticFunctions
and the like. This PR DOES modify the ASTs produced by those functions. The FunC generator part seems to use only the "sources" fromgetRawAST
, but I still do not understand that part of the code.Checklist