tact-lang / tact

Tact compiler main repository
https://tact-lang.org
MIT License
394 stars 111 forks source link

fix: Issue #970: interpreter called only when contract present #1047

Open jeshecdom opened 1 week ago

jeshecdom commented 1 week ago

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:

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