Skip to content

ADR-029 Phase 5: PV11 compiler optimizations umbrella #77

Description

@satran004

Summary

Umbrella issue for ADR-029 Phase 5: target-aware compiler and stdlib optimizations that use PV11 features to reduce script size and/or execution budget.

No Phase 5 optimization should begin until the explicit V3/PV11 compiler target and feature enforcement in #76 are complete. Correctness and target legality come first. Each optimization accepted for implementation will receive its own focused issue and PR, linked back to this umbrella.

Related readiness umbrella: #65
Compiler-target prerequisite: #76
Phase 0 contract cleanup: #75
ADR tasks: PV11-050 through PV11-056
Cost/reference baseline: cardano-node 11.0.1 / Plutus 1.63.0.0 at f92b7d7d82622a26caf456a6be33859f697e2cfc

Initial policy

The initial compiler target is V3/PV11 only. Phase 5 therefore does not need to maintain PV10 fallback lowerings. If JuLC later adds a PV10 compiler target, each affected optimization must define a legal fallback or reject that feature for PV10 in a separate target-support issue.

This phase is not required for Java/Truffle evaluator parity. It improves generated code after the compiler can prove that the selected operations are legal for its target.

Candidate workstreams

PV11-050 — Lower JulcList.drop to DropList — P1 / S

Replace the current recursive NullList/TailList lowering with the native PV11 DropList builtin for the V3/PV11 target.

Required evidence:

  • equivalent results and failure behavior;
  • smaller generated UPLC;
  • lower budget for representative list sizes and counts;
  • regression tests demonstrating that the final program contains DropList rather than the recursive template.

PV11-051 — Case-on-builtin lowering — P1 / L

Evaluate target-aware lowering of:

  • boolean conditionals to Case Bool;
  • list matching/decomposition to Case List;
  • integer switches to Case Integer;
  • native pair destructuring to Case Pair.

Each rewrite must preserve strictness and failure behavior and must beat the existing chooser/equality/list-builtin form under the pinned PV11 cost model. This may become more than one child issue if the lowerings are independently reviewable.

PV11-052 — Typed native Value API and lowering — P1 / M

Introduce a dedicated native Value type, tentatively JulcValue, instead of representing both ordinary Data and native Value as PlutusData.

Target flow:

Data-encoded Value
    -> UnValueData once
    -> native lookup/union/contains/scale operations
    -> ValueData only at an external Data boundary

The design should prevent accidental Data/Value mixing and allow redundant conversions and nested-map scans to be eliminated safely.

PV11-053 — Cost-directed list-to-array promotion — P2 / L

Detect repeated indexed access to the same immutable list and, only when profitable, lower it to:

ListToArray once
    -> repeated IndexArray calls

The child issue must define cost-model-derived break-even thresholds, use-count/escape analysis, and cases that must remain lists. Single or cheap sequential accesses must not be promoted blindly.

PV11-054 — BLS MSM fusion and typed API — P2 / M

Recognize or expose typed expressions equivalent to:

s1 * P1 + s2 * P2 + ... + sn * Pn

and lower them to the PV11 G1/G2 multi-scalar-multiplication builtins when list length, scalar bounds, and failure semantics match. Replace loosely typed PlutusData list surfaces where practical.

PV11-055 — ExpModInteger lowering and constant folding — P2 / M

  • Add a target-aware mapping for explicit modular-exponentiation idioms.
  • Constant-fold literal calls only when reference failure behavior is preserved.
  • Never rewrite ordinary exponentiation without an explicit modulus.

PV11-056 — Target-aware Value/Array constant folding — P2 / M

Fold pure literal operations whose result or failure is statically known and legal for V3/PV11, including selected array length/index/drop and native Value operations. Known failures must remain failures at the correct semantic point.

Child-issue policy

Before implementing a workstream:

  1. Create a focused issue linked here.
  2. Record the exact source pattern and generated before/after UPLC.
  3. Define semantic, strictness, and failure-equivalence tests.
  4. Define representative script-size and CPU/memory benchmarks using the pinned PV11 costs.
  5. Decide whether the optimization is mandatory, optional, or behind a compiler flag.
  6. Document any generated-script hash change and migration impact.
  7. Have the implementation independently reviewed before merge.

Shared acceptance requirements

Every child optimization must:

  • Run only for a compiler target where every introduced term and builtin is legal.
  • Preserve results, evaluation order, strictness, and reference failure behavior.
  • Include a non-rewritten comparison test or golden output.
  • Demonstrate a measured budget and/or script-size improvement; availability alone is not sufficient.
  • Use the selected target cost model rather than hard-coded intuition when profitability depends on input size.
  • Be deterministic and document script-hash changes.
  • Pass compiler, Java VM, Truffle VM, examples, and full repository tests.
  • Add user-facing documentation when generated code or public typed APIs change.

Umbrella checklist

  • Create and complete a focused issue for PV11-050 (DropList lowering).
  • Create and complete or explicitly defer focused issue(s) for PV11-051 (case-on-builtin lowering).
  • Create and complete or explicitly defer a focused issue for PV11-052 (typed native Value).
  • Create and complete or explicitly defer a focused issue for PV11-053 (list-to-array promotion).
  • Create and complete or explicitly defer a focused issue for PV11-054 (BLS MSM fusion/API).
  • Create and complete or explicitly defer a focused issue for PV11-055 (ExpModInteger lowering/folding).
  • Create and complete or explicitly defer a focused issue for PV11-056 (Value/Array folding).
  • Publish aggregate before/after size and budget results for the optimizations that ship.
  • Update ADR-029 and release documentation with completed and deferred work.

Out of scope

Deferred implementation follow-ups

ADR-032 research/disposition is complete. The checklist below tracks later implementation or prerequisite work. A rule must not be enabled merely because its PV11 builtin exists.

Each follow-up inherits this umbrella's shared acceptance requirements and adds operation-specific gates for semantic equivalence, evaluation order and strictness, reference failure behavior, deterministic output, pinned PV11 size/CPU/memory evidence, Java/Truffle agreement, Scalus language-level cross-checking where supported, affected-module and repository tests, documentation, and independent correctness review.

A follow-up may close without enabling a rewrite when its decision gate proves that no safe or useful source contract exists. Such a rejection must be recorded in ADR evidence; it must not be converted into an untyped peephole optimization.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions