Skip to content

Monomorphization: no transitive instantiation of generic-calling-generic #317

@aallan

Description

@aallan

Bug

The monomorphizer only scans non-generic function bodies for generic call sites. When a generic function calls another generic function (e.g. array_map calls array_map_go), the inner call is never collected and monomorphized.

Example

forall<A, B> fn array_map(@Array<A>, @Fn<A,B> -> @Array<B>) {
  array_map_go(@Array<A>.0, @Fn<A,B>.0, 0, [])
}

The user calls array_map([1,2,3], fn(...)), which generates array_map$Int_Int. But array_map_go$Int_Int is never generated because the monomorphizer doesn't scan the body of array_map$Int_Int for further generic calls.

Impact

Any generic function that delegates to another generic function fails to compile with 'unknown func'.

Fix

Replaced the single-pass monomorphization with a worklist-based transitive closure. After generating each monomorphized function, its body is scanned for further generic calls, which are added to the worklist. Fixed in the feat/array-operations branch.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions