coroutine icon indicating copy to clipboard operation
coroutine copied to clipboard

Generic function instance types are registered in the origin package

Open chriso opened this issue 1 year ago • 0 comments

We use the x/tools/go/ssa package to instantiate generics for us. We collect generic functions and their instances here, and then register type information for the runtime here.

If a package in which a generic function is instantiated refers to the package in which the generic function was defined, and the instance has a parameter that refers to a package-local type, registering function types in the origin package will cause a circular import. There's a repro here.

We either need to:

  1. register function types in a brand new package (which nothing depends on), or
  2. we need to figure out a way to register the types of generic function instances in a/the package in which the instance was created/required.

I've been digging through the SSA package to see if there's a way to do (2), but have had no luck. The *ssa.Function of generic instances has a .Pkg == nil. There don't seem to be any methods or fields that would help us determine the package (or packages) in which the instance is used.

chriso avatar Jul 03 '24 19:07 chriso