LoweringContext

scalus.compiler.sir.lowering.LoweringContext
See theLoweringContext companion object
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
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

def captureFingerprint(tps: SIRType*): String

Produce a stable fingerprint of the parts of the enclosing call-site state that a cached helper's RHS captures from lctx, restricted to TypeVars occurring in tps.

Produce a stable fingerprint of the parts of the enclosing call-site state that a cached helper's RHS captures from lctx, restricted to TypeVars occurring in tps.

Helpers in cachedTopLevelHelpers are built once per cache key and reused on subsequent hits — but their RHS bodies often consult typeVarReprEnv and the inUplcConstrListScope flag during construction (e.g. element-repr resolution inside an lvMatchList body). If the cache key omits this state, the FIRST caller's env wins, and later callers under a different env get a helper RHS that doesn't match their context. This is the alone-vs-combined Heisenbug pattern documented in sessions 11-15: the same (type, fromRepr, toRepr) cache key produces functionally-different helpers depending on first-miss timing.

Including this fingerprint in the cache key forces helpers with different captured env state to live as separate entries.

Attributes

def defineCachedTopLevelHelper(cacheKey: String, namePrefix: String, funType: SIRType, funRepr: LoweredValueRepresentation, label: String, pos: SIRPosition)(buildRhs: IdentifiableLoweredValue => LoweredValue): IdentifiableLoweredValue

Define a top-level recursive helper or reuse a previously-cached one for the same key.

Define a top-level recursive helper or reuse a previously-cached one for the same key.

The recipe — shared by ScalusRuntime.builtinListToUplcConstr, ScalusRuntime.uplcConstrToBuiltinList, and LoweringEq.createSumEqHelper — is:

  1. Look up cacheKey in cachedTopLevelHelpers. On hit, return the cached var.
  2. On miss, allocate a fresh VariableLoweredValue from funType/funRepr.
  3. Register it in the cache BEFORE building the rhs so the rhs (built by buildRhs) can refer to the var for self-recursion.
  4. Build the rhs by calling buildRhs(v).
  5. Append (v, rhs) to pendingTopLevelLetRecs so the lowering driver emits the let-rec wrapping the lowered SIR root.

label is the short site name passed to LoweringContext.traceLetRec — used when filtering SCALUS_TRACE_LETREC output.

Attributes

def findProviderBinding(providerModuleName: String, methodName: String): Option[Binding]

Find a binding in a provider module by module name and method name.

Find a binding in a provider module by module name and method name.

Attributes

def info(msg: String, pos: SIRPosition): Unit
def log(msg: String): Unit
def lookupCachedHelper(key: String): Option[IdentifiableLoweredValue]

Cache lookup with a diagnostic disable knob. Call sites should use this instead of cachedTopLevelHelpers.get(...) directly so the disable flag covers them uniformly.

Cache lookup with a diagnostic disable knob. Call sites should use this instead of cachedTopLevelHelpers.get(...) directly so the disable flag covers them uniformly.

Attributes

def lower(sir: SIR, optTargetType: Option[SIRType] = ...): LoweredValue
def newArgCacheKey(): Int

If this is typevariable, try get the value from context, else leave it as is.

If this is typevariable, try get the value from context, else leave it as is.

Attributes

def tryResolveTypeVar(tp: TypeVar): Option[SIRType]
def uniqueVarName(prefix: String = ...): String
def warn(msg: String, pos: SIRPosition): Unit

Concrete fields

val argCache: Map[Int, LoweredValue]

Annotation-keyed cache of pre-lowered values. Indexed by Int.

Annotation-keyed cache of pre-lowered values. Indexed by Int.

Used by intrinsic resolution as an alternative to identity-based precomputedValues: the resolver substitutes references to lambda parameters with SIR.Var(name, type, anns + "argCache" → Const(Integer(idx))). lowerSIR checks the annotation and returns argCache(idx) directly. Survives substituteVarAndTypes walking that creates fresh SIR.Var instances (annotations are preserved in the copy).

Attributes

val cachedTopLevelHelpers: LinkedHashMap[String, IdentifiableLoweredValue]

Cache for top-level recursive helpers (e.g. per-type sumEq functions emitted by LoweringEq.generateSumUplcConstrEquals). Keyed by a stable type-fingerprint string. Each entry is the recursive IdentifiableLoweredValue that subsequent uses can reference; the corresponding rhs is registered in pendingTopLevelLetRecs and emitted as a let-rec wrapping the lowered SIR root.

Cache for top-level recursive helpers (e.g. per-type sumEq functions emitted by LoweringEq.generateSumUplcConstrEquals). Keyed by a stable type-fingerprint string. Each entry is the recursive IdentifiableLoweredValue that subsequent uses can reference; the corresponding rhs is registered in pendingTopLevelLetRecs and emitted as a let-rec wrapping the lowered SIR root.

Attributes

var debug: Boolean
var debugLevel: Int
val decls: Map[String, DataDecl]
val generateErrorTraces: Boolean
var inUplcConstrListScope: Boolean
val intrinsicModules: Map[String, Module]
var nestingLevel: Int
val noWarn: Boolean

Pending top-level let-rec bindings collected during lowering. After Lowering.lowerSIR returns the lowered SIR root, the lowering driver wraps it with a chain of let-recs for each entry. Entries are appended by innermost-completing helpers first (helper +=s AFTER any transitively-triggered sub-helpers have completed their own +=), so with foldRight wrapping, the first entry becomes outermost — inner helpers can see their outer dependencies. NOT sound for mutually recursive sums; detect and reject those at helper-construction time.

Pending top-level let-rec bindings collected during lowering. After Lowering.lowerSIR returns the lowered SIR root, the lowering driver wraps it with a chain of let-recs for each entry. Entries are appended by innermost-completing helpers first (helper +=s AFTER any transitively-triggered sub-helpers have completed their own +=), so with foldRight wrapping, the first entry becomes outermost — inner helpers can see their outer dependencies. NOT sound for mutually recursive sums; detect and reject those at helper-construction time.

Attributes

val supportModules: Map[String, Module]
var varIdSeq: Int
val warnListConversions: Boolean
var zCombinatorNeeded: Boolean