MoonVeil-Docs/content/docs/options/flatten-control-flow.md
2025-06-09 19:15:12 -05:00

1.2 KiB

weight title description icon date lastmod
100 Flatten control flow Control flow flattener article 2025-05-01T18:47:58-05:00 2025-05-01T18:47:58-05:00

This option enables Control Flow Flattening (CFF), restructuring code a dispatch-like state machine. The flattener prioritizes correctness; if flattening a block could cause side effects, it either skips that block or partially flattens it. Failed blocks are re-evaluated recursively, allowing their sub-blocks to be flattened individually.

The control flow flattener supports the following branching syntaxes:

  • if statements
  • while and repeat loops
  • numeric for loops
  • break and continue statements
  • for-in loops and even support for Luau's generalized iteration

The following child options are available:

  • Expression Decomposition: Breaks apart expressions into CFF blocks and temporaries, can kill performance.
  • Wrap CFF blocks: Will move compatible CFF blocks into their own closure in a lookup table. Can speed up larger flattening targets.
  • Hoist locals: Will move local storage into a lookup table. Useful to cut down on the number of used locals.