Optimizer

scalus.uplc.transform.Optimizer
trait Optimizer

Base trait for UPLC term optimizers.

An optimizer transforms a UPLC (Untyped Plutus Core) term into an equivalent but more efficient term. Optimizers can perform various transformations such as:

  • Dead code elimination
  • Function inlining and beta-reduction
  • Eta-reduction (removing redundant lambda abstractions)
  • Constant folding
  • Conversion of lazy evaluation to strict evaluation when safe

==Usage==

Optimizers are typically used in optimization pipelines (see V1V2Optimizer and V3Optimizer) where multiple optimization passes are applied sequentially:

val optimizer = new StrictIf()
val optimizedTerm = optimizer(term)
println(s"Optimizations applied: ${optimizer.logs.mkString(", ")}")

==Implementation Notes==

Optimizer implementations should:

  • Accept a scalus.uplc.eval.Logger as constructor parameter for logging optimizations
  • Be deterministic: applying the same optimizer to the same term should always produce the same result
  • Preserve semantics: the optimized term must be equivalent to the original term
  • Log all applied optimizations for debugging and analysis

Attributes

See also

StrictIf for lazy-to-strict if-then-else conversion

EtaReduce for eta-reduction optimization

Inliner for function inlining and dead code elimination

ForcedBuiltinsExtractor for extracting forced builtins to top level

CaseConstrApply for optimizing nested Apply with Case/Constr (Plutus V3)

Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class EtaReduce
class Inliner
object NoopOptimizer
class StrictIf
class V3Optimizer
Show all

Members list

Value members

Abstract methods

def apply(term: Term): Term

Applies the optimization to a UPLC term.

Applies the optimization to a UPLC term.

Value parameters

term

The UPLC term to optimize

Attributes

Returns

The optimized UPLC term, semantically equivalent to the input

def logs: Seq[String]

Returns the log messages from optimization operations.

Returns the log messages from optimization operations.

Each log entry describes an optimization that was applied, useful for debugging and understanding the optimization process.

Attributes

Returns

Sequence of log messages describing applied optimizations