Skip to content

postcheck panic: tag pattern matched non-tag value during build specialization #10028

Description

@lukewilliamboswell

Summary

On the harden-glue branch, roc build panics during specialization with:

postcheck invariant violated: tag pattern matched a non-tag value

I reduced this from roc-ray/examples/hello_world.roc to a fully standalone three-file app/platform. roc check passes for the same source; only roc build panics.

Version

Observed with:

branch: harden-glue
commit: a4febaa2d63dbe44ff194065f61b19838987f1ac
roc version: debug-6334a2ed

Minimal repro

Create these three files:

mkdir -p repro-tag-pattern/platform
cd repro-tag-pattern

app.roc

app [main!] { pf: platform "platform/main.roc" }

import pf.Draw

main! : () => Try({}, [Exit(I64), ..])
main! = || {
    _offset = Draw.offset(Draw.align_left)
    Ok({})
}

platform/main.roc

platform ""
    requires {} { main! : () => Try({}, [Exit(I64), ..]) }
    exposes [Draw]
    packages {}
    provides {
        "render_for_host": render_for_host!,
    }
    hosted {}
    targets: {
        x64glibc: { inputs: [app] },
    }

import Draw

render_for_host! : () => Try({}, I64)
render_for_host! = || {
    match main!() {
        Ok({}) => Ok({})
        Err(Exit(code)) => Err(code)
        Err(_) => Err(-1)
    }
}

platform/Draw.roc

Draw := [].{
    HAlign : [Left, Center, Right]

    Align : {
        horizontal : HAlign,
    }

    align_left : Align
    align_left = { horizontal: Left }

    offset : Align -> F32
    offset = |align|
        match align.horizontal {
            Left => 0
            Center => 1
            Right => 2
        }
}

Run:

roc check app.roc
roc build app.roc

Expected

roc build should not panic. If this platform is invalid for linking because it only supplies app as a target input, it should fail with a normal linker/platform error after lowering.

Actual

roc check app.roc passes.

roc build app.roc exits 134 and panics:

thread ... panic: postcheck invariant violated: tag pattern matched a non-tag value
src/postcheck/common.zig:82
src/postcheck/monotype_lifted/spec_constr.zig:2927 bindPatToValue
src/postcheck/monotype_lifted/spec_constr.zig:2351 simplifyKnownMatchValue
src/postcheck/monotype_lifted/spec_constr.zig:1609 cloneExprValue
src/postcheck/monotype_lifted/spec_constr.zig:1517 cloneExpr
src/postcheck/monotype_lifted/spec_constr.zig:914 writeSpecialization
src/postcheck/monotype_lifted/spec_constr.zig:493 createSpecializations
src/postcheck/monotype_lifted/spec_constr.zig:421 run
src/lir/checked_pipeline.zig:237 lowerCheckedModulesToLir
src/cli/main.zig:8244 rocBuildLlvm

Reduction notes

  • This does not depend on the roc-ray platform package.
  • This does not depend on hello_world.roc.
  • This does not need hosted effects, raylib libraries, Host, App, Draw.text!, or a model type.
  • The minimal trigger appears to be specializing through the platform-provided wrapper while the app calls a function that matches on a tag field from a known record constant.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Fields

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions