Skip to content

ty_holds skips a closure in a later instance of the same datatype #1513

Closed

Description

@jasisz

What you did

Build and run the program below on the CPU and Metal lanes:

bend main.bend -o main
./main --gpu off
./main --gpu on

What happened

The file checks, and JS and the native CPU lane print 42. Metal fail-stops with:

bend: a function the device does not hold

ty_holds sees Box<Num{}> first and records Box in seen, so it does not inspect the fields of the later Box<Fun{}> instance. Pick(Fun{}) and its function are therefore missed. Reversing the two fields of Duo, so Box<Fun{}> comes first, makes Metal print 42.

This looks like a remaining case after #1336: the Tag argument has a value-taking kind and is skipped, but its value selects the type-family result stored in Box.value.

Reproduced on current main at d71f42ee287bd7b9f86b44df44b210ac5eb651bd.

The file

import Base

type Tag is Data:
  Num{}
  Fun{}

def Pick(t: Tag) -> Type:
  match t:
    case Num{}:
      U32
    case Fun{}:
      U32 -> U32

type Box<-t: Tag> is Type:
  Box{value: Pick(t)}

type Duo is Type:
  Duo{plain: Box<Num{}>, callable: Box<Fun{}>}

def use(d: Duo) -> U32:
  match d:
    case Duo{plain, callable}:
      match plain:
        case Box{x}:
          match callable:
            case Box{f}:
              f(x)

def make() -> Duo:
  Duo{Box{41}, Box{x => (x + 1 : U32)}}

def main() -> IO(Unit):
  IO.print(U32.show(use!(make())))

#|42

bend --version

bend 2.0.36

uname -sm

Darwin arm64

clang --version (the first line)

Apple clang version 21.0.0 (clang-2100.0.123.102)

Activity

  1. oxura commented on Oct 12, 2026

    @oxura
    Contributor

    The focused fix tracks active datatype expansions rather than retaining names across siblings. Refreshed onto current main 381dc87 (including #1506 and #1509), the original closure-bang repro prints 42 on native CPU. Actual emitted-C CUDA preprocessing shows the host-minted closure FID 4 absent from the device evaluator on current main (which retains its missing-function error default) and included with the fix. Seventeen existing/new closure and current plain-number Nat seam cases pass; the repository gate passes 54/54. Removed my obsolete BigInt seam regression after #1506 changed the host contract to numbers. Preparing the PR with the original GPU regression; no Metal/CUDA hardware execution or performance claim.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions