Skip to content

emit-c: closures are unsupported ("unsupported const kind 7"), so no generator program — push or pulled — goes through the C backend #1766

Closed

Description

@ehartford

Spec: §13.4 (D69: generators lower as calls; a for over a generator passes its body as a closure), §12.4 closures. Found on gen-push-pull (#1725) while checking the C backend's coroutine prototypes; the push form reproduces on the gen-push-impl base.

Repro (with build r0.w --emit-c -o r0.c):

gen fn nums(n: i32) -> i32:
    for i in 0..n:
        yield i * 7

fn main:
    for v in nums(3):
        print(v)

Expected: C output that compiles and prints 0, 7, 14. Actual:

error: C emission failed: unsupported const kind 7
error: build failed

Const kind 7 is ConstKind.CK_CLOSURE: CCodegen has no lowering for a closure constant, so any closure — including the loop-body closure D69 introduces for every for over a generator, and std.task's gen_pull — fails emit-c loudly. (A program with a collection literal fails earlier: "emit-c does not support generic intrinsic __collection_literal".)

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