scalus.compiler.sir

Members list

Type members

Classlikes

Transforms error messages in SIR to abbreviated forms and collects a mapping of abbreviations to original messages.

Transforms error messages in SIR to abbreviated forms and collects a mapping of abbreviations to original messages.

This transformation helps reduce the size of error messages in the IR while maintaining traceability through a mapping of abbreviated forms to their original messages.

Attributes

Example
   // Input SIR containing: Error("Failed validation"), Error("Failed execution")
   // Transforms to: Error("FV"), Error("FE")
   // With mapping: Map("FV" -> "Failed validation", "FE" -> "Failed execution")
   val transformer = new AbbreviateErrorTraces
   val result = transformer.transformSIR(input)
   val abbrevMap = transformer.getAbbreviationMap
Supertypes
class Object
trait Matchable
class Any
sealed trait AnnotatedSIR extends SIR

Attributes

Supertypes
trait SIR
class Object
trait Matchable
class Any
Known subtypes
class And
class Apply
class Builtin
class Cast
class Const
class Constr
class Error
class ExternalVar
class IfThenElse
class LamAbs
class Let
class Match
class Not
class Or
class Select
class Var
Show all
case class AnnotationsDecl(pos: SIRPosition, comment: Option[String] = ..., data: Map[String, SIR] = ...)

Attributes

Companion
object
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
case object AnnotationsDecl

Attributes

Companion
class
Supertypes
trait Singleton
trait Product
trait Mirror
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
Self type
case class Binding(name: String, tp: SIRType, value: SIR)

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
case class ConstrDecl(name: String, params: List[TypeBinding], typeParams: List[TypeVar], parentTypeArgs: List[SIRType], annotations: AnnotationsDecl)

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
case class DataDecl(name: String, constructors: List[ConstrDecl], typeParams: List[TypeVar], annotations: AnnotationsDecl)

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
object EnrichedSIR

EnrichedSIR[P,T] mirrors the structure of SIR trait but allows parameterization with pattern type P and info type T.

EnrichedSIR[P,T] mirrors the structure of SIR trait but allows parameterization with pattern type P and info type T.

For each SIR case class Xxx, there is a sealed trait Xxx[P,T] with two cases:

  • XxxPattern[P,T](pattern: P, info: T) representing a pattern node
  • XxxInfo[P,T] with the same parameters as origin SIR, but using appropriate traits from EnrichedSIR[P,T] and with additional info: T

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
case class Module(version: (Int, Int), name: String, linked: Boolean, requireBackend: Option[String], defs: List[Binding], anns: AnnotationsDecl = ...)

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
object ModuleToExpr extends ToExprHS[Module]

Attributes

Supertypes
class ToExprHS[Module]
trait ToExpr[Module]
class Object
trait Matchable
class Any
Self type

Eliminates multi-binding recursive Let groups by rewriting each group into nested single-binding lets (peers-as-params), so the lowering backends only ever see single self-recursion, which they encode via self-application.

Eliminates multi-binding recursive Let groups by rewriting each group into nested single-binding lets (peers-as-params), so the lowering backends only ever see single self-recursion, which they encode via self-application.

For a group f1..fN (binding order) it emits, outermost first:

 let fNp = λf1...f(N-1). rhsN'   // fresh name fN$mutrec
 ...
 let f2p = λf1. rhs2'
 let f1  = rhs1'
 in body'

where inside rhs_i' (context i; context 1 also covers rhs1' and the body), a reference to fj is rewritten to argExpr(j, i):

  • j < i: stays the (param) variable fj;
  • j == i: the self-application chain fip f1 .. f(i-1) (or plain f1 when i == 1);
  • j == i + 1: the adjacent chain f(i+1)p f1 .. fi, where the fi argument is the j == i self chain above - still built from plain variables only;
  • j >= i + 2: a bounded reference to fj under its original name, backed by a non-recursive let fj = λ$eta. (fjp E(1) .. E(j-1)) $eta in ... emitted once per context around the rewritten rhs/body. The eta-wrapper defers the (potentially expensive) construction of fjp's argument chain until fj is actually called, which is required for correctness (a plain, non-eta-expanded let fj = fjp E(1)..E(j-1) would force that application immediately, re-entering the still-being-defined peers and diverging), and lets every E(k) for i + 2 = i + 2 references recursively re-expand their own 1 .. j-1 argument lists (each of which may again contain far references), which is exponential in the reference distance j - i. With the eta-lets, each context does O(distance) work and the whole group is O(N^2).

Each member's rhs must be a lambda; a cyclic group of plain values is rejected. See docs/superpowers/specs/2026-08-04-mutual-recursion-design.md.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
object PrettyPrinter

Pretty printers.

Pretty printers.

  • Use pretty to pretty print to a org.typelevel.paiges.Doc.
  • Use prettyXTerm to pretty print to a org.typelevel.paiges.Doc with syntax highlighting for XTerm.

For example:

PrettyPrinter.prettyXTerm(sir).render(80)
// renders a single line if possible
PrettyPrinter.pretty(sir).flatten.render(120)

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
case class Program(version: (Int, Int, Int), term: SIR)

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
object RemoveTraces

Removes fully-applied Trace builtin calls from SIR, replacing them with their value argument.

Removes fully-applied Trace builtin calls from SIR, replacing them with their value argument.

This is used for release builds to strip log() calls and their message computations (string concatenation, show calls, etc.) from the script, reducing size and execution cost.

The transformation also cleans up dead let bindings that become trivial () after trace removal (the common pattern from log("msg") → let _ = trace(msg)(()) in body → let _ = () in body → body).

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
object SIR

Attributes

Companion
trait
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
SIR.type
sealed trait SIR

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes
trait AnnotatedSIR
class And
class Apply
class Builtin
class Cast
class Const
class Constr
class Error
class ExternalVar
class IfThenElse
class LamAbs
class Let
class Match
class Not
class Or
class Select
class Var
class Decl
Show all
case class SIRBodyAnnotation(module: Module, deps: List[SIRModuleWithDeps]) extends StaticAnnotation

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
trait StaticAnnotation
class Annotation
class Object
trait Matchable
class Any
Show all
object SIRBuiltins

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
object SIRChecker

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
SIRChecker.type
trait SIRCompiled

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes

Default compiler options for SIR processing. Here to have a single place for default options, which is shared between the compiler plugin and the core library.

Default compiler options for SIR processing. Here to have a single place for default options, which is shared between the compiler plugin and the core library.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type

Attributes

Companion
trait
Supertypes
class Object
trait Matchable
class Any
Self type
object SIRMacro

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
SIRMacro.type

Attributes

Companion
class
Supertypes
class Object
trait Matchable
class Any
Self type
class SIRModuleWithDeps(val sirModule: Module, sirDepsExpr: => List[SIRCompiled]) extends SIRCompiled

Attributes

Companion
object
Supertypes
trait SIRCompiled
class Object
trait Matchable
class Any
object SIRPattern

Attributes

Companion
trait
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
SIRPattern.type
sealed trait SIRPattern

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class And
class Apply
class Builtin
class Cast
class Const
class Constr
class Error
class ExternalVar
class IfThenElse
class LamAbs
class Let
class Match
class Not
class Or
class Select
class Var
Show all
object SIRToExpr extends ToExprHS[SIR]

Attributes

Supertypes
class ToExprHS[SIR]
trait ToExpr[SIR]
class Object
trait Matchable
class Any
Self type
SIRToExpr.type
object SIRType

Attributes

Companion
trait
Supertypes
class Object
trait Matchable
class Any
Self type
SIRType.type
sealed trait SIRType

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class Annotated
class CaseClass
class Fun
trait Primitive
object Boolean
object BuiltinValue
object ByteString
object Integer
object String
object Unit
class SumCaseClass
class TypeLambda
object TypeNothing
class TypeProxy
class TypeVar
Show all
object SIRTypeToExpr extends ToExprHS[SIRType]

Attributes

Supertypes
class ToExprHS[SIRType]
trait ToExpr[SIRType]
class Object
trait Matchable
class Any
Self type
object SIRUnify

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
SIRUnify.type
object SIRVarStorage

Attributes

Companion
trait
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
sealed trait SIRVarStorage

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes
object Cases
object Data
object ScottEncoding
object SirDSL

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
SirDSL.type

Attributes

Supertypes
trait Enum
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
class ToExprHS[T](hst: HashConsedFlat[T], hste: Quotes ?=> Expr[HashConsedFlat[T]], tt: Quotes ?=> Type[T]) extends ToExpr[T]

Attributes

Supertypes
trait ToExpr[T]
class Object
trait Matchable
class Any
Known subtypes
object ModuleToExpr
object SIRToExpr
object SIRTypeToExpr

Called from SIRConverter via reflection.

Called from SIRConverter via reflection.

Attributes

Supertypes
trait Flat[SIR]
class Object
trait Matchable
class Any
Self type

Note, that this hashconsedflat should not be resolved as given. It is used only as parameter to ToExprHS. Given HashConsedFlat[(something other then Module)] is a no-no.

Note, that this hashconsedflat should not be resolved as given. It is used only as parameter to ToExprHS. Given HashConsedFlat[(something other then Module)] is a no-no.

Attributes

Supertypes
trait Flat[SIRType]
class Object
trait Matchable
class Any
Self type
case class TypeBinding(name: String, tp: SIRType, annotations: AnnotationsDecl = ...)

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Deprecated classlikes

Moved to scalus.compiler.sir.transform.BooleanOptimizer, alongside the other SIR-to-SIR passes. This alias forwards to the new location so existing callers keep compiling and linking.

Moved to scalus.compiler.sir.transform.BooleanOptimizer, alongside the other SIR-to-SIR passes. This alias forwards to the new location so existing callers keep compiling and linking.

Note that the pass itself changed when it moved: several rules that could drop an operand the original expression evaluates - and so delete an Error or a trace - were removed. See docs/internal/BOOLEAN_OPTIMIZER_FINDINGS.md.

Attributes

Deprecated
[Since version 1.1.1] use scalus.compiler.sir.transform.BooleanOptimizer instead
Supertypes
class Object
trait Matchable
class Any
Self type

Moved to scalus.compiler.sir.transform.StaticArgumentTransformation, alongside the other SIR-to-SIR passes. This alias forwards to the new location so existing callers keep compiling and linking.

Moved to scalus.compiler.sir.transform.StaticArgumentTransformation, alongside the other SIR-to-SIR passes. This alias forwards to the new location so existing callers keep compiling and linking.

Attributes

Deprecated
[Since version 1.1.1] use scalus.compiler.sir.transform.StaticArgumentTransformation instead
Supertypes
class Object
trait Matchable
class Any
Self type

Types

SIR Position - position in Scala source code. Now a type alias for ScalusSourcePos.

SIR Position - position in Scala source code. Now a type alias for ScalusSourcePos.

Attributes

Value members

Concrete fields

val SIRVersion: (Int, Int)

Givens