scalus.compiler.sir.lowering.simple

Members list

Type members

Classlikes

abstract class BaseSimpleLowering(sir: SIR, generateErrorTraces: Boolean = ...)

Base class for simple lowering from Scalus Intermediate Representation SIR to UPLC Term.

Base class for simple lowering from Scalus Intermediate Representation SIR to UPLC Term.

This class contains common functionality shared between different lowering strategies. Subclasses must implement the encoding-specific methods for constructors, pattern matching, and field selection.

Value parameters

generateErrorTraces

whether to generate error traces

sir

the Scalus Intermediate Representation to lower

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes
object LetFloating

Let-floating transformation that moves lazy let bindings closer to their usage points.

Let-floating transformation that moves lazy let bindings closer to their usage points.

This transformation implements "floating inward" as described in: Simon Peyton Jones, Will Partain, and André Santos. 1996. Let-floating: moving bindings to give faster programs.

The algorithm works in three phases:

  1. Enrichment pass (down-traversal): Build enriched SIR with node indices, track variable usage, lambda context, and dependencies
  2. Analysis pass: Find dominating nodes for each lazy let binding using tracked usage information and transitive dependency propagation
  3. Output generation pass (down-traversal): Reconstruct SIR, moving lazy lets to their computed dominating nodes

Lambda barrier: Non-effortless bindings (computations) are prevented from crossing lambda boundaries to avoid duplicating work when the lambda is called multiple times. Effortless bindings (constants, variables, lambdas) can cross freely.

TODO: optimization can introduce expressions like App((lambda x, x),y) which can be eliminated. Maybe add a beta-reduction pass after let-floating, or just handle it here.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
class ScottEncodingLowering(sir: SIR, generateErrorTraces: Boolean = ...) extends BaseSimpleLowering

Scott encoding-based lowering from Scalus Intermediate Representation SIR to UPLC Term.

Scott encoding-based lowering from Scalus Intermediate Representation SIR to UPLC Term.

This implementation uses Scott encoding for data types:

  • Nil is represented as \Nil Cons -> force Nil
  • Cons h tl is represented as (\head tail Nil Cons -> Cons head tail) h tl

Value parameters

generateErrorTraces

whether to generate error traces

sir

the Scalus Intermediate Representation to lower

Attributes

Supertypes
class Object
trait Matchable
class Any
class SumOfProductsLowering(sir: SIR, generateErrorTraces: Boolean = ...) extends BaseSimpleLowering

UPLC 1.1.0-based lowering from Scalus Intermediate Representation SIR to UPLC Term.

UPLC 1.1.0-based lowering from Scalus Intermediate Representation SIR to UPLC Term.

We use UPLC version 1.1.0 and generate Sums of Products (SoP) constructors case and constr to represent data types. Also we optimize newtype kind of constructors to be represented as just values.

Value parameters

generateErrorTraces

whether to generate error traces

sir

the Scalus Intermediate Representation to lower

Attributes

Example
case class Wrapper(a: BigInt)
val x = Wrapper(1) // lowers to just (const integer 1)
Supertypes
class Object
trait Matchable
class Any

Deprecated types

Attributes

Deprecated
[Since version 0.13.0] Use ScottEncodingLowering instead

Attributes

Deprecated
[Since version 0.13.0] Use SumOfProductsLowering instead