Skip to content

Compile BuiltinData transparently in the plugin#7863

Open
Unisay wants to merge 7 commits into
masterfrom
yura/builtin-data-transparent
Open

Compile BuiltinData transparently in the plugin#7863
Unisay wants to merge 7 commits into
masterfrom
yura/builtin-data-transparent

Conversation

@Unisay

@Unisay Unisay commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Alternative to #7719 for fixing #7716 — the two PRs are mutually exclusive; whichever lands, the other closes.

The plugin treats BuiltinData as representationally transparent: PlutusCore.Data.Data compiles to the builtin data type (same as BuiltinData), the BuiltinData constructor compiles to the identity, and a single-alternative case on it binds both the case binder and the field to the scrutinee. GHC unwrapping the wrapper — the worker/wrapper unboxing that exposed Data in join point types and crashed the plugin with Unsupported feature: Type constructor: GHC.Prim.Addr# — then becomes harmless instead of fatal. Details in Note [Transparent BuiltinData] in PlutusTx.Compiler.Expr.

The problematic Core shape, from the unfolding of the useTwiceData regression test (condensed) — the source mentions only BuiltinData, yet the join point's type signature exposes Data:

useTwiceData = \ (bd :: BuiltinData) ->
  case bd of bd1 { BuiltinData ipv ->
    let $j :: PlutusCore.Data.Data -> BuiltinUnit   <join 1>
        $j = \ (ipv2 :: PlutusCore.Data.Data) -> ...
    in ... }

Unlike the second-constructor approach, BuiltinData itself is untouched and costs don't move: no budget golden changes under either GHC version. Large-script UPLC goldens (cardano-constitution, Ed25519) shift shape through different CSE choices at identical budget and CBOR size.

Stage violations that previously died at the Cannot construct a value of type: BuiltinData check now surface as a missing-unfolding error; the last commits port #7719's improved diagnostics to that path (see the StageViolation/builtinData goldens).

@Unisay Unisay self-assigned this Jul 22, 2026
@Unisay
Unisay force-pushed the yura/builtin-data-transparent branch from e0f8648 to e9f6c8f Compare July 23, 2026 14:44
@Unisay
Unisay force-pushed the yura/builtin-data-transparent branch from e9f6c8f to 3bc4fee Compare July 24, 2026 09:42
@Unisay
Unisay marked this pull request as ready for review July 24, 2026 09:43
@Unisay
Unisay requested a review from zliu41 July 24, 2026 14:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant