Crate leo_passes

source ·
Expand description

§leo-passes

Crates.io Authors License

Re-exports§

Modules§

  • The Dead Code Elimination pass traverses the AST and eliminates unused code, specifically assignment statements, within the boundary of transitions and functions. The pass is run after the Function Inlining pass.
  • The destructuring pass traverses the AST and destructures tuples into individual variables. This pass assumes that tuples have a depth of 1, which is ensured by the type checking pass.
  • The flattening pass traverses the AST after the SSA pass and converts into a sequential code. The pass flattens ConditionalStatements into a sequence of AssignStatements. The pass rewrites ReturnStatements into AssignStatements and consolidates the returned values as a single ReturnStatement at the end of the function. The pass rewrites ternary expressions over composite data types, into ternary expressions over the individual fields of the composite data type, followed by an expression constructing the composite data type. Note that this transformation is only applied to non-finalize code.
  • The Function Inlining pass traverses the AST and inlines function at their call site. See https://en.wikipedia.org/wiki/Inline_expansion for more information. The pass also reorders Functions in a reconstructed ProgramScope so that they are in a post-order of the call graph. In other words, a callee function will appear before a caller function in the order.
  • The Static Single Assignment pass traverses the AST and converts it into SSA form. See https://en.wikipedia.org/wiki/Static_single-assignment_form for more information. The pass also replaces DefinitionStatements with AssignmentStatements. The pass also simplifies complex expressions into a sequence of AssignStatements. For example, (a + b) * c is rewritten into $var$1 = a + b; $var$2 = $var$1 * c.