From: Matthew Dempsky Date: Fri, 16 Sep 2022 21:27:01 +0000 (-0700) Subject: go/internal/gcimporter: fix ureader.go handling of local defined types X-Git-Tag: go1.20rc1~991 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=29153be75763b7cbf9395d732f454336e3df0286;p=gostls13.git go/internal/gcimporter: fix ureader.go handling of local defined types In unified IR, local defined types are promoted to a global defined type with a "vargen" suffix. These shouldn't actually be exposed to go/types users, because they're only relevant within function bodies, which go/types doesn't support importing. Moreover, in the case of defined types that were declared within a generic function, they can have ambient type parameters, which the go/types importer doesn't know how to handle (because they shouldn't be needed for that use case). While here, prune the gcimporter_test.go skip list, because some of the listed failures have actually been fixed and all of them are specific to the Go 1.18 (nounified) frontend. They all work correctly with GOEXPERIMENT=unified. Fixes #55110. Change-Id: I7dd8b86355d910dfed1d47edbad7695144c3f84d Reviewed-on: https://go-review.googlesource.com/c/go/+/431495 Reviewed-by: Cuong Manh Le Reviewed-by: Cherry Mui Run-TryBot: Matthew Dempsky TryBot-Result: Gopher Robot --- diff --git a/src/go/internal/gcimporter/gcimporter_test.go b/src/go/internal/gcimporter/gcimporter_test.go index 54fda86208..8c86bac54c 100644 --- a/src/go/internal/gcimporter/gcimporter_test.go +++ b/src/go/internal/gcimporter/gcimporter_test.go @@ -173,13 +173,14 @@ func TestImportTypeparamTests(t *testing.T) { t.Fatal(err) } - skip := map[string]string{ - "equal.go": "inconsistent embedded sorting", // TODO(rfindley): investigate this. - "nested.go": "fails to compile", // TODO(rfindley): investigate this. - "issue50417.go": "inconsistent interface member sorting", - "issue53419.go": "fails to compile", - "issue53477.go": "fails to compile", - "issue55101.go": "fails to compile", + var skip map[string]string + if !goexperiment.Unified { + // The Go 1.18 frontend still fails several cases. + skip = map[string]string{ + "equal.go": "inconsistent embedded sorting", // TODO(rfindley): investigate this. + "nested.go": "fails to compile", // TODO(rfindley): investigate this. + "issue55101.go": "fails to compile", + } } for _, entry := range list { diff --git a/src/go/internal/gcimporter/support.go b/src/go/internal/gcimporter/support.go index af3b6cbbcc..7ed8c9a404 100644 --- a/src/go/internal/gcimporter/support.go +++ b/src/go/internal/gcimporter/support.go @@ -167,3 +167,17 @@ type typeInfo struct { idx pkgbits.Index derived bool } + +// See cmd/compile/internal/types.SplitVargenSuffix. +func splitVargenSuffix(name string) (base, suffix string) { + i := len(name) + for i > 0 && name[i-1] >= '0' && name[i-1] <= '9' { + i-- + } + const dot = "·" + if i >= len(dot) && name[i-len(dot):i] == dot { + i -= len(dot) + return name[:i], name[i:] + } + return name, "" +} diff --git a/src/go/internal/gcimporter/ureader.go b/src/go/internal/gcimporter/ureader.go index 53bb9bacb0..ad8e9a43d9 100644 --- a/src/go/internal/gcimporter/ureader.go +++ b/src/go/internal/gcimporter/ureader.go @@ -469,6 +469,11 @@ func (pr *pkgReader) objIdx(idx pkgbits.Index) (*types.Package, string) { return objPkg, objName } + // Ignore local types promoted to global scope (#55110). + if _, suffix := splitVargenSuffix(objName); suffix != "" { + return objPkg, objName + } + if objPkg.Scope().Lookup(objName) == nil { dict := pr.objDictIdx(idx)