22 releases (7 breaking)

Uses new Rust 2024

new 0.8.0-pre.10 Nov 26, 2025
0.8.0-pre.8 Jul 24, 2025
0.4.0 Mar 9, 2025
0.3.1 Dec 29, 2024

#1988 in Web programming


Used in portal-jsc-swc-opt-ssa

MPL-2.0 license

570KB
11K SLoC

Static Single Assignment (SSA) form intermediate representation.

This crate provides an SSA form representation for JavaScript/ECMAScript code, which is a lower-level IR than TAC (Three-Address Code) that enforces stronger invariants for optimization.

Static Single Assignment Form

In SSA form:

  • Each variable is assigned exactly once (static single assignment)
  • Variables are versioned when they would be reassigned in non-SSA form
  • Control flow merges use block parameters instead of φ-functions
  • Enables more powerful dataflow analysis and optimizations

Block Parameters Instead of Phi Nodes

This SSA representation uses block parameters instead of traditional φ-functions. Basic blocks take parameters just like functions, and predecessors pass arguments when jumping to them. This approach:

  • Makes SSA construction and transformation easier to reason about
  • Avoids edge cases that occur with φ-nodes (e.g., critical edges)
  • Provides a cleaner representation for optimization passes
  • Naturally handles multiple values being merged at the same point

For example, instead of:

block:
  x = φ(x1 from pred1, x2 from pred2)

We use:

block(x):        // x is a block parameter
  ...
pred1:
  jump block(x1) // pass x1 as argument
pred2:
  jump block(x2) // pass x2 as argument

Key Types

  • SFunc: A function in SSA form
  • SCfg: The SSA control flow graph
  • SBlock: A basic block with parameters (replacing φ-functions)
  • SValue: An SSA value (operation, parameter, load, store, etc.)
  • SValueW: A wrapper around SValue for arena storage
  • STerm: Block terminator with target blocks and arguments
  • STarget: A jump target (block + arguments for its parameters)

Conversion from TAC

The primary entry point is converting from TAC to SSA form. This involves:

  1. Identifying variables that need versioning
  2. Creating block parameters at control flow merges (instead of φ-functions)
  3. Threading SSA values through the control flow graph
  4. Converting assignments to SSA form
  5. Passing appropriate arguments when jumping to blocks

Modules

  • consts: Constant propagation in SSA form
  • conv: Conversion from TAC to SSA
  • impls: Trait implementations for SSA types
  • opt_stub: Optimization stub/framework
  • [rew]: Rewriting passes
  • simplify: Simplification passes

Dependencies

~20–33MB
~502K SLoC