Skip to content

Generic functions do not infer T from Vec[Task[T]] parameters #595

Closed

Description

@ehartford

Summary

Codegen generic binding fails to infer a type parameter nested under Vec[Task[T]], even though the same shape is valid in concrete code. This surfaced while implementing #421: inlining cleanup loops works, but extracting them into a generic helper fails.

Minimal reproduction

//! expect-stdout: ok
fn cleanup_remaining[T](tasks: Vec[Task[T]], start: i32):
    let total = tasks.len() as i32
    var i = start
    while i < total:
        tasks.get(i).join_cleanup()
        i = i + 1

async fn child() -> i32:
    1

async fn main_task -> i32:
    let tasks: Vec[Task[i32]] = Vec.new()
    tasks.push(child())
    cleanup_remaining(tasks, 0)
    0

fn main:
    let _ = main_task().await
    print("ok")

Expected

T is inferred as i32, the helper is monomorphized, and the program prints ok.

Actual

error: unknown type for generic parameter 'T' in 'cleanup_remaining'
error: code generation failed

Notes

#421 avoids this by keeping the cleanup loops inline in std.task, but this is a real generic inference/codegen bug and should be fixed at the generic parameter binding layer, not worked around in user code.

Activity

  1. ehartford commented on Jul 2, 2026

    @ehartford
    ContributorAuthor

    Status update (skepticism pass, 2026-07-02): MUTATED AND WORSE on HEAD. The reported 'unknown type for generic parameter T' diagnostic is gone; with build on the repro now SIGSEGVs the compiler (exit 139, zero output, no diagnostic; check passes). A silent compiler crash is strictly worse than a clean rejection — escalating this to the front of the generics track.

  2. ehartford commented on Jul 2, 2026

    @ehartford
    ContributorAuthor

    Fixed by the commit above: codegen's generic monomorphization now unifies the param type node STRUCTURALLY against the argument's sema type (worklist over named leaves / ref-ptr unwrap / generic-inst recursion), binding T at any nesting depth — Vec[Task[T]] vs Vec[Task[i32]] → T=i32. The repro builds and runs (ok); the compiler SIGSEGV (and the original 'unknown type for generic parameter T') are gone. Pinned by behav_generic_nested_type_param covering Vec[Pair[T]], Pair[Vec[T]], and the async Vec[Task[T]] shape. Spec §11 generics; full gates green.

  3. added a commit that references this issue on Jul 4, 2026
    1da33da
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