Skip to content

Commit b79c135

Browse files
committed
cmd/compile: skip exporting generic functions for -buildmode=plugin
Generic functions require instantiation, which package plugin doesn't support, and likely never will. So instead, we can just skip writing out any generic functions, which avoids an ICE in the plugin generation code. This issue doesn't affect GOEXPERIMENT=unified, because it avoids leaking any non-instantiated types/functions to the rest of the compiler backend. Fixes #52937. Change-Id: Ie35529c5c241e46b77fcb5b8cca48bb99ce7bfcb Reviewed-on: https://go-review.googlesource.com/c/go/+/406358 TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Run-TryBot: Matthew Dempsky <[email protected]>
1 parent a900a17 commit b79c135

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

src/cmd/compile/internal/reflectdata/reflect.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1726,6 +1726,9 @@ func CollectPTabs() {
17261726
if s.Pkg.Name != "main" {
17271727
continue
17281728
}
1729+
if n.Type().HasTParam() {
1730+
continue // skip generic functions (#52937)
1731+
}
17291732
ptabs = append(ptabs, n)
17301733
}
17311734
}

test/run.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,10 @@ func (t *test) run() {
993993

994994
case "build":
995995
// Build Go file.
996-
_, err := runcmd(goTool(), "build", t.goGcflags(), "-o", "a.exe", long)
996+
cmd := []string{goTool(), "build", t.goGcflags()}
997+
cmd = append(cmd, flags...)
998+
cmd = append(cmd, "-o", "a.exe", long)
999+
_, err := runcmd(cmd...)
9971000
if err != nil {
9981001
t.err = err
9991002
}

test/typeparam/issue52937.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// build -buildmode=plugin
2+
3+
//go:build !js
4+
// +build !js
5+
6+
// Copyright 2022 The Go Authors. All rights reserved.
7+
// Use of this source code is governed by a BSD-style
8+
// license that can be found in the LICENSE file.
9+
10+
package main
11+
12+
func main() {}
13+
func F[T any]() {}
14+
func G[T any](T) {}

0 commit comments

Comments
 (0)