Scalus Intermediate Representation (SIR)
Scalus generates an intermediate representation (SIR) of your code. SIR is a simplified, lambda calculus-based representation that closely resembles Plutus Core but is easier to work with and optimize.
SIR serves as a bridge between your high-level Scala code and the final Plutus Core output. It preserves the semantics of your program while stripping away Scala-specific constructs, making it ideal for:
- Applying optimizations before final code generation
- Analyzing and debugging the compiled script
- Understanding how your Scala code translates to on-chain logic
Pretty-printing SIR
It’s a good idea to print the SIR to understand what the compiler has generated.
import scalus.*, scalus.sir.SIR
val sir: SIR = ??? // from the previous example
println(sir.show) // pretty-print the SIR
println(sir.showHighlighted) // pretty-print the SIR with colorized syntax highlighting
SIR optimisations
Scalus Intermediate Representation (SIR) can be optimized. Currently,
the only optimization is the RemoveRecursivity
optimization that inlines let
expressions.
import scalus.*, scalus.sir.*
val sir: SIR = ??? // from the previous example
val optimized = RemoveRecursivity(sir)
// or using the `|>` operator
val optimized2 = sir |> RemoveRecursivity.apply
Last updated on