Skip to content

Commit

Permalink
Skip partially instantiated generics
Browse files Browse the repository at this point in the history
  • Loading branch information
chriso committed Dec 13, 2023
1 parent 6c3a5fe commit 11f3430
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
22 changes: 22 additions & 0 deletions compiler/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,11 @@ func (c *compiler) generateFunctypes(p *packages.Package, f *ast.File, colors ma
}
for _, instance := range instances {
g := newGenericInstance(fn, instance)
if g.partial() {
// Skip instances where not all type params have concrete types.
// I'm not sure why these are generated in the SSA program.
continue
}
scope := &funcscope{vars: map[string]*funcvar{}}
name := g.gcshapePath()
collectFunctypes(p, name, instance.Syntax(), scope, colors, functypes, g)
Expand Down Expand Up @@ -430,6 +435,23 @@ func (g *genericInstance) typeOfParam(t types.Type) (types.Type, bool) {
return v, ok
}

func (g *genericInstance) partial() bool {
sig := g.instance.Signature
params := sig.Params()
for i := 0; i < params.Len(); i++ {
if _, ok := params.At(i).Type().(*types.TypeParam); ok {
return true
}
}
results := sig.Results()
for i := 0; i < results.Len(); i++ {
if _, ok := results.At(i).Type().(*types.TypeParam); ok {
return true
}
}
return false
}

func (g *genericInstance) scanRecvTypeArgs(fn func(*types.TypeParam, int, types.Type)) {
typeParams := g.recvType.TypeParams()
typeArgs := g.recvType.TypeArgs()
Expand Down
7 changes: 1 addition & 6 deletions compiler/testdata/coroutine_durable.go
Original file line number Diff line number Diff line change
Expand Up @@ -3255,7 +3255,7 @@ func IdentityGenericStructInt(n int) { (&IdentityGenericStruct[int]{n: n}).Run()

//go:noinline
func IdentityGenericClosure[T any](_fn0 T) {
_c := coroutine.LoadContext[T, any]()
_c := coroutine.LoadContext[int, any]()
var _f0 *struct {
IP int
X0 T
Expand Down Expand Up @@ -3443,10 +3443,5 @@ func init() {
F uintptr
X0 int
}]("github.com/stealthrocket/coroutine/compiler/testdata.buildClosure[go.shape.int].func1")
_types.RegisterFunc[func(n T) func()]("github.com/stealthrocket/coroutine/compiler/testdata.buildClosure[go.shape.interface{}]")
_types.RegisterClosure[func(), struct {
F uintptr
X0 T
}]("github.com/stealthrocket/coroutine/compiler/testdata.buildClosure[go.shape.interface{}].func1")
_types.RegisterFunc[func(_fn0 ...int)]("github.com/stealthrocket/coroutine/compiler/testdata.varArgs")
}

0 comments on commit 11f3430

Please sign in to comment.