scalus.uplc.transform.Inliner
See theInliner companion object
Optimizer that performs function inlining, beta-reduction, and dead code elimination.
The Inliner performs several transformations:
- '''Beta-reduction''': Replaces function application with direct substitution when safe
- '''Identity function inlining''': Eliminates identity functions like
λx.x - '''Dead code elimination''': Removes unused lambda parameters when the argument is pure
- '''Small value inlining''': Inlines variables, small constants, and builtins
- '''Force/Delay elimination''': Simplifies
Force(Delay(t))tot - '''Partial evaluation''': Evaluates closed subexpressions at compile time via the CEK machine (e.g.,
addInteger 2 3→5,(λx. addInteger x 1) 2→3)
==Inlining Strategy==
The inliner uses occurrence counting and purity analysis to decide what is safe to inline:
- Variables, builtins, and small constants (≤64 bits) can be duplicated safely
- Larger values are only inlined if used once
- Pure unused arguments are eliminated entirely
==Example==
// Input: (λx. λy. x) 42 100
// After inlining identity and dead code elimination:
// Output: 42
val inliner = new Inliner()
val optimized = inliner(term)
// Check what was optimized
println(inliner.logs.mkString("\n"))
==Implementation Details==
The inliner performs capture-avoiding substitution to prevent variable capture during beta-reduction.
Value parameters
- logger
-
Logger for tracking inlining operations (defaults to new Log())
Attributes
- See also
-
TermAnalysis.isPure for purity analysis used in dead code elimination
Optimizer for the base optimizer trait
- Companion
- object
- Graph
-
- Supertypes
Members list
In this article