scalus.compiler.sir.lowering

Members list

Type members

Classlikes

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
trait LoweredValue
class Object
trait Matchable
class Any
Show all
abstract class BaseRepresentationProxyLoweredValue(input: LoweredValue, val representation: LoweredValueRepresentation, val pos: SIRPosition) extends ProxyLoweredValue

Attributes

Supertypes
trait LoweredValue
class Object
trait Matchable
class Any
Known subtypes

Attributes

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

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
trait LoweredValue
class Object
trait Matchable
class Any
Show all
abstract class BuiltinApplyLoweredValue(val fun: Builtin, tp: SIRType, repr: LoweredValueRepresentation, inPos: SIRPosition, val args: LoweredValue*) extends ComplexLoweredValue

Attributes

Supertypes
trait LoweredValue
class Object
trait Matchable
class Any
Known subtypes
case class BuiltinRefLoweredValue(sir: Builtin, term: Term, representation: LoweredValueRepresentation) extends LeafLoweredValue

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
trait LoweredValue
class Object
trait Matchable
class Any
Show all
case class CaseBooleanLoweredValue(scrutinee: LoweredValue, falseBranch: LoweredValue, trueBranch: LoweredValue, tp: SIRType, repr: LoweredValueRepresentation, inPos: SIRPosition) extends ComplexLoweredValue

LoweredValue for case on boolean builtins (PlutusV4 feature).

LoweredValue for case on boolean builtins (PlutusV4 feature).

In PlutusV4, Case can be used directly on boolean constants: Case(bool, [falseBranch, trueBranch]) where False = index 0 and True = index 1.

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
trait LoweredValue
class Object
trait Matchable
class Any
Show all
case class CaseDataLoweredValue(scrutinee: LoweredValue, constrTagVar: IdentifiableLoweredValue, constrArgsVar: IdentifiableLoweredValue, constrBranch: LoweredValue, mapEntriesVar: IdentifiableLoweredValue, mapBranch: LoweredValue, listElementsVar: IdentifiableLoweredValue, listBranch: LoweredValue, iValueVar: IdentifiableLoweredValue, iBranch: LoweredValue, bValueVar: IdentifiableLoweredValue, bBranch: LoweredValue, tp: SIRType, repr: LoweredValueRepresentation, inPos: SIRPosition) extends ComplexLoweredValue

LoweredValue for Case on Data (PlutusV4+).

LoweredValue for Case on Data (PlutusV4+).

Data has 5 constructors with different bound variables:

  • Constr (index 0): receives tag (Integer) and args (List[Data])
  • Map (index 1): receives entries (List[(Data, Data)])
  • List (index 2): receives elements (List[Data])
  • I (index 3): receives value (Integer)
  • B (index 4): receives value (ByteString)

Each branch is a lambda that receives the appropriate arguments.

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
trait LoweredValue
class Object
trait Matchable
class Any
Show all
case class CaseIntegerLoweredValue(scrutinee: LoweredValue, branches: List[LoweredValue], tp: SIRType, repr: LoweredValueRepresentation, inPos: SIRPosition) extends ComplexLoweredValue

LoweredValue for case on integer builtins (PlutusV4 feature).

LoweredValue for case on integer builtins (PlutusV4 feature).

In PlutusV4, Case can be used directly on integer constants when the cases form a contiguous sequence starting from 0: Case(int, [branch0, branch1, ..., branchN]) where integer value i selects branch i.

Note: This only works when cases are 0, 1, 2, ..., n without gaps. For integers outside this range, behavior is undefined (will error at runtime).

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
trait LoweredValue
class Object
trait Matchable
class Any
Show all
case class CaseListLoweredValue(scrutinee: LoweredValue, consHead: IdentifiableLoweredValue, consTail: IdentifiableLoweredValue, consBranch: LoweredValue, optNilBranch: Option[LoweredValue], tp: SIRType, repr: LoweredValueRepresentation, inPos: SIRPosition) extends ComplexLoweredValue

LoweredValue for case on list builtins (PlutusV4 feature).

LoweredValue for case on list builtins (PlutusV4 feature).

In PlutusV4, Case can be used directly on list constants: Case(list, [consBranch, nilBranch]) where Cons = index 0 (receives head and tail as arguments) and Nil = index 1 (no arguments).

The consBranch must be a lambda that accepts head and tail: λhead.λtail.body

NOTE: This type is only correct for SumBuiltinList scrutinees (Plutus Constant.List). For native SumUplcConstr lists, Cek dispatches by constructor tag (Nil=0, Cons=1), which requires the opposite branch order. Intrinsic/match lowerings that may produce either kind should keep list matches at the SumBuiltinList boundary.

Attributes

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

LoweredValue for Case on Pair (PlutusV4+).

LoweredValue for Case on Pair (PlutusV4+).

In PlutusV4, Case can be used directly on pair constants: Case(pair, [branch]) where the branch receives fst and snd as arguments.

The branch must be a lambda that accepts fst and snd: λfst.λsnd.body

Attributes

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

LoweredValue for ChooseList builtin (PlutusV1-V3).

LoweredValue for ChooseList builtin (PlutusV1-V3).

Uses the ChooseList builtin with delayed branches: Force(ChooseList list (Delay nil) (Delay cons))

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
trait LoweredValue
class Object
trait Matchable
class Any
Show all
trait ComplexLoweredValue(val ownVars: Set[IdentifiableLoweredValue], subvalues: LoweredValue*) extends LoweredValue

ComplexLoweredValue is a base trait for lowered values that consist of multiple subvalues. ownVars - var that used in subvalues but defined in this value. (i.e. not propagated up in dominatedUplevelVars)

ComplexLoweredValue is a base trait for lowered values that consist of multiple subvalues. ownVars - var that used in subvalues but defined in this value. (i.e. not propagated up in dominatedUplevelVars)

Attributes

Supertypes
trait LoweredValue
class Object
trait Matchable
class Any
Known subtypes
case class ConstantLoweredValue(sir: Const, representation: LoweredValueRepresentation) extends LeafLoweredValue

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
trait LoweredValue
class Object
trait Matchable
class Any
Show all
case class DelayLoweredValue(input: LoweredValue, pos: SIRPosition) extends ProxyLoweredValue

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
trait LoweredValue
class Object
trait Matchable
class Any
Show all
case class DependendVariableLoweredValue(id: String, name: String, parent: VariableLoweredValue, representation: LoweredValueRepresentation, rhs: LoweredValue, inPos: SIRPosition, directDepended: Set[IdentifiableLoweredValue] = ..., directDependFrom: Set[IdentifiableLoweredValue] = ...) extends IdentifiableLoweredValue

Represent a variable which is dependent on another variable. i.e. var x1 = (toOtherReperesentation(y))

Represent a variable which is dependent on another variable. i.e. var x1 = (toOtherReperesentation(y))

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
trait LoweredValue
class Object
trait Matchable
class Any
Show all
case class ErrorLoweredValue(sir: Error, term: Term) extends LeafLoweredValue

Attributes

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

Attributes

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 ForceLoweredValue(input: LoweredValue, pos: SIRPosition) extends ProxyLoweredValue

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
trait LoweredValue
class Object
trait Matchable
class Any
Show all
sealed trait IdentifiableLoweredValue extends LoweredValue

Values with id which can be represented by variables (if needed).

Values with id which can be represented by variables (if needed).

Identificatin is id.

Attributes

Supertypes
trait LoweredValue
class Object
trait Matchable
class Any
Known subtypes
case class IfThenElseLoweredValue(cond: LoweredValue, thenBranch: LoweredValue, elseBranch: LoweredValue, tp: SIRType, repr: LoweredValueRepresentation, inPos: SIRPosition) extends ComplexLoweredValue

Attributes

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

Attributes

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

Resolves intrinsic implementations for method calls based on argument representation and protocol version.

Resolves intrinsic implementations for method calls based on argument representation and protocol version.

When the lowering encounters a method call like list.isEmpty, the resolver checks if there is an optimized intrinsic implementation for the argument's runtime representation (e.g., SumDataList). If found, it substitutes the provider's body (with the actual argument SIR) and re-lowers it. Already-lowered arguments are tracked via the annotation-keyed argCache mechanism (see LoweringContext.argCache), so re-lowering the substituted SIR returns the pre-lowered value without recomputation.

The registry is hardcoded — adding new intrinsic providers requires editing the registry and creating the @Compile provider object.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
trait LoweredValue
class Object
trait Matchable
class Any
Show all
case class LambdaRepresentation(funTp: SIRType, canonicalRepresentationPair: InOutRepresentationPair) extends LoweredValueRepresentation

Representation for lambda function. By default, lanbda-s accept default reperesentation for input and output types. But when we pass functions to type-parametrized functions, then calling party does not know about real parameter types and can't use default representation, so pass parameters as packed data.

Representation for lambda function. By default, lanbda-s accept default reperesentation for input and output types. But when we pass functions to type-parametrized functions, then calling party does not know about real parameter types and can't use default representation, so pass parameters as packed data.

So, we translate higher-order functions to packed data representation when pass as arguments to type-parametrized functions.

But some builtin function accept more then one representations, because they poplymorhiocj on plutus level. (i.e. have builtin type variables). For example: makeCons work with SumDataList and SumPairDataList, so we need to reevaluate representation when argument type is known.

Attributes

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

Leaf values have no subvalues and no uplevel variable dependencies. Constants, errors, and builtin refs are all leaves.

Leaf values have no subvalues and no uplevel variable dependencies. Constants, errors, and builtin refs are all leaves.

Attributes

Supertypes
trait LoweredValue
class Object
trait Matchable
class Any
Known subtypes

Attributes

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

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
trait LoweredValue
class Object
trait Matchable
class Any
Show all
case class LocalScope(byId: Map[String, VariableLoweredValue], byName: Map[String, VariableLoweredValue])

Attributes

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

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
LocalScope.type
trait LoweredValue

SEA of nodes - like representation. E.e. each value is node, which manage dependencies. LoweredValue:

SEA of nodes - like representation. E.e. each value is node, which manage dependencies. LoweredValue:

  • represents a value in lowered SIR, which is
  • a generator of a block of code with generate specific SIRType in specific representation. -- (representation is LoweredValueRepresentation, which can be term or data in specific encoding)
  • some lowered values can be named (see IdentifiableLoweredValue and maintain a set of dependencies) The idea of SEA of nodes -- than we can generate code 'by need' based on dependencies. I.e. if value not used at all - code will not be generated, if value used once -- no intermediate construction will be created and code will be generated directly in place of usage. If value used multiple times -- it will be generated near the usage (i.e. in the nearest block, which contains all depended).

The idea of SEA of nodes described in the paper: Cliff Click. 1995. Global code motion/global value numbering. SIGPLAN Not. 30, 6 (June 1995), 246–257. "https://doi.org/10.1145/223428.207154"

We have a quite different code (non-SSA form, only dominators), but the main idea of relaxing order is the same,

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes
object LoweredValue

Attributes

Companion
trait
Supertypes
class Object
trait Matchable
class Any
Self type

representation, depends on the type of the value.

representation, depends on the type of the value.

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes

Attributes

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

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
Lowering.type
class LoweringContext(var zCombinatorNeeded: Boolean = ..., val decls: Map[String, DataDecl] = ..., var varIdSeq: Int = ..., var scope: LocalScope = ..., val targetLanguage: Language = ..., val targetProtocolVersion: MajorProtocolVersion = ..., val generateErrorTraces: Boolean = ..., val warnListConversions: Boolean = ..., val noWarn: Boolean = ..., var inUplcConstrListScope: Boolean = ..., var typeUnifyEnv: Env = ..., var typeVarReprEnv: Map[TypeVar, LoweredValueRepresentation] = ..., var debug: Boolean = ..., var debugLevel: Int = ..., var nestingLevel: Int = ..., var enclosingLambdaParams: List[IdentifiableLoweredValue] = ..., val intrinsicModules: Map[String, Module] = ..., val supportModules: Map[String, Module] = ...)

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any

Attributes

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

Equality lowering — recognizes equalsRepr(a, b) (and the FunctionalInterface Eq path) and emits the most efficient comparison for the lhs/rhs representation pair.

Equality lowering — recognizes equalsRepr(a, b) (and the FunctionalInterface Eq path) and emits the most efficient comparison for the lhs/rhs representation pair.

Dispatch order in generateEqualsForRepr:

  • Primitives (Integer, ByteString, String): specialized builtins
  • BLS curve elements: bls12_381_G1/G2_equal
  • BLS MlResult, Fun: compile error (no equality)
  • @UplcRepr(UplcConstr) products: field-by-field via generateProdUplcConstrEquals
  • @UplcRepr(UplcConstr) sums: native letrec via generateSumUplcConstrEquals
  • Everything else: convert to Data, equalsData

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
LoweringEq.type
case class LoweringException(msg: String, pos: SIRPosition, cause: Throwable = ...) extends RuntimeException

Attributes

Supertypes
trait Product
trait Equals
class RuntimeException
class Exception
class Throwable
trait Serializable
class Object
trait Matchable
class Any
Show all

Proxy wrapping the value's sirType with an outer TypeLambda binding free TypeVars not bound by any inner TypeLambda. When the underlying value is a Lambda, its LambdaRepresentation.funTp is rewrapped consistently so representation.funTp == sirType. Used when an inlined intrinsic body has dropped its outer TypeLambda and downstream lvApply.reprFun needs the bound TypeVars to resolve element reprs.

Proxy wrapping the value's sirType with an outer TypeLambda binding free TypeVars not bound by any inner TypeLambda. When the underlying value is a Lambda, its LambdaRepresentation.funTp is rewrapped consistently so representation.funTp == sirType. Used when an inlined intrinsic body has dropped its outer TypeLambda and downstream lvApply.reprFun needs the bound TypeVars to resolve element reprs.

Attributes

Companion
object
Supertypes
trait LoweredValue
class Object
trait Matchable
class Any

Attributes

Companion
class
Supertypes
class Object
trait Matchable
class Any
Self type

Mixin for representations that always store values as Data at the UPLC level.

Mixin for representations that always store values as Data at the UPLC level.

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes
object PackedData
object PackedDataMap
object DataConstr
object DataData
Show all
sealed trait PrimitiveRepresentation(val isPackedData: Boolean, val isDataCentric: Boolean) extends LoweredValueRepresentation

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes
object Constant
object PackedData

Attributes

Companion
trait
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
object ProdDispatch

Dispatch layer for product-typed operations. Single entry point for Prod-side toRepresentation. Routing typegens (ProductCase*, OneElementWrapperEmitter) extend the base SirTypeUplcGenerator only — they don't have toRepresentation at all, so direct calls are compile-time errors. See docs/local/claude/compiler/sum-prod-dispatch-design.md.

Dispatch layer for product-typed operations. Single entry point for Prod-side toRepresentation. Routing typegens (ProductCase*, OneElementWrapperEmitter) extend the base SirTypeUplcGenerator only — they don't have toRepresentation at all, so direct calls are compile-time errors. See docs/local/claude/compiler/sum-prod-dispatch-design.md.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
sealed trait ProductCaseClassRepresentation(val isPackedData: Boolean, val isDataCentric: Boolean) extends LoweredValueRepresentation

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes

Attributes

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

Proxy whose sirType is origin.sirType with an @UplcRepr annotation derived from the value's actual representation, attached at the return / scalar position. representation is inherited from origin, so the annotation can never drift from the emitted bytes.

Proxy whose sirType is origin.sirType with an @UplcRepr annotation derived from the value's actual representation, attached at the return / scalar position. representation is inherited from origin, so the annotation can never drift from the emitted bytes.

Attributes

Companion
object
Supertypes
trait LoweredValue
class Object
trait Matchable
class Any

Attributes

Companion
class
Supertypes
class Object
trait Matchable
class Any
Self type

A proxy which change only the representation of the input value (without changing the underlying generated code)

A proxy which change only the representation of the input value (without changing the underlying generated code)

Attributes

Companion
object
Supertypes
trait LoweredValue
class Object
trait Matchable
class Any
Show all

Attributes

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

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type

Lowered value which exists to create a scope for the set of variables. Need to prevent pulling out variables outsiode scope from lambda-s, while we have not yet full tracking of control-flow dependencies. (i.e. variables defined inside scope should not be pulled outside of it automatically by lambda barrier logic)

Lowered value which exists to create a scope for the set of variables. Need to prevent pulling out variables outsiode scope from lambda-s, while we have not yet full tracking of control-flow dependencies. (i.e. variables defined inside scope should not be pulled outside of it automatically by lambda barrier logic)

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
trait LoweredValue
class Object
trait Matchable
class Any
Show all
class SirToUplcV3Lowering(sir: SIR, generateErrorTraces: Boolean = ..., upcastTo: SIRType = ..., representation: LoweredValueRepresentation = ..., debug: Boolean = ..., warnListConversions: Boolean = ..., noWarn: Boolean = ..., targetLanguage: Language = ..., targetProtocolVersion: MajorProtocolVersion = ..., intrinsicModules: Map[String, Module] = ..., supportModules: Map[String, Module] = ...)

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any

Attributes

Companion
class
Supertypes
class Object
trait Matchable
class Any
Self type
sealed trait SumCaseClassRepresentation(val isPackedData: Boolean, val isDataCentric: Boolean) extends LoweredValueRepresentation

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes

Attributes

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

Dispatch layer for sum-typed operations. Single entry point for Sum-side toRepresentation; routing typegens (DataConstrEmitter, SumCaseUplcConstr*, SumListEmitterCommon subclasses, plus the Prod typegens that delegate via ProdDispatch) extend the base SirTypeUplcGenerator only — they don't have toRepresentation at all, so direct calls are compile-time errors. See docs/local/claude/compiler/sum-prod-dispatch-design.md.

Dispatch layer for sum-typed operations. Single entry point for Sum-side toRepresentation; routing typegens (DataConstrEmitter, SumCaseUplcConstr*, SumListEmitterCommon subclasses, plus the Prod typegens that delegate via ProdDispatch) extend the base SirTypeUplcGenerator only — they don't have toRepresentation at all, so direct calls are compile-time errors. See docs/local/claude/compiler/sum-prod-dispatch-design.md.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
case class TermGenerationContext(generatedVars: Set[String], processUndefinedValues: Boolean = ..., debug: Boolean = ...)

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
final class TypeRepresentationProxyLoweredValue(input: LoweredValue, inSirType: SIRType, val representation: LoweredValueRepresentation, inPos: SIRPosition) extends ProxyLoweredValue

A proxy which changes the input value to be specific type and representation.

A proxy which changes the input value to be specific type and representation.

Attributes

Supertypes
trait LoweredValue
class Object
trait Matchable
class Any

TypeVarRepresentation is used for type variables. Usually this is a synonym for some other specific-type representation.

TypeVarRepresentation is used for type variables. Usually this is a synonym for some other specific-type representation.

  • Transparent: builtin UPLC type variable, can be freely used in any representation
  • Fixed: Scala type variable with native representation
  • Fixed: Scala type variable that flows into list element position, uses Data representation (explicit per-element representation requires an @UplcRepr annotation).

Attributes

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

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
class VariableLoweredValue(val id: String, val name: String, val sir: Var, val representation: LoweredValueRepresentation, val otherRepresentations: Map[LoweredValueRepresentation, DependendVariableLoweredValue] = ..., val optRhs: Option[LoweredValue] = ..., val directDepended: Set[IdentifiableLoweredValue] = ..., val directDependFrom: Set[IdentifiableLoweredValue] = ...) extends IdentifiableLoweredValue

Attributes

Supertypes
trait LoweredValue
class Object
trait Matchable
class Any