From bdf2db7255565db3d7ca1ffb721203e6d9460ccc Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Wed, 24 Aug 2022 11:53:42 -0700 Subject: [PATCH] go/internal/gcimporter: call Interface.Complete in unified importer To support concurrent use of the go/types API, importers need to call Interface.Complete on constructed interfaces before returning. There's an issue that the interfaces may contain embedded defined types, whose underlying type isn't known yet. This issue will eventually go away once CL 424876 lands, but that CL needs to wait for CL 424854 to re-land, which needs to wait for CL 421879 to land... In the mean time, this CL implements the same solution used by the indexed importer: maintaining a list of constructed interfaces, and calling Interface.Complete on them after the SetUnderlying loop and just before returning the imported package. Updates #54653. Change-Id: I0f42c915a4b7d28c628bbab7ac2eab2415c7858f Reviewed-on: https://go-review.googlesource.com/c/go/+/425360 TryBot-Result: Gopher Robot Run-TryBot: Matthew Dempsky Reviewed-by: Robert Griesemer --- src/go/internal/gcimporter/ureader.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/go/internal/gcimporter/ureader.go b/src/go/internal/gcimporter/ureader.go index dacc161ec8..15c8c2032d 100644 --- a/src/go/internal/gcimporter/ureader.go +++ b/src/go/internal/gcimporter/ureader.go @@ -31,6 +31,10 @@ type pkgReader struct { laterFns []func() // laterFors is used in case of 'type A B' to ensure that B is processed before A. laterFors map[types.Type]int + + // ifaces holds a list of constructed Interfaces, which need to have + // Complete called after importing is done. + ifaces []*types.Interface } // later adds a function to be invoked at the end of import reading. @@ -86,6 +90,10 @@ func readUnifiedPackage(fset *token.FileSet, ctxt *types.Context, imports map[st fn() } + for _, iface := range pr.ifaces { + iface.Complete() + } + pkg.MarkComplete() return pkg } @@ -386,6 +394,16 @@ func (r *reader) interfaceType() *types.Interface { if implicit { iface.MarkImplicit() } + + // We need to call iface.Complete(), but if there are any embedded + // defined types, then we may not have set their underlying + // interface type yet. So we need to defer calling Complete until + // after we've called SetUnderlying everywhere. + // + // TODO(mdempsky): After CL 424876 lands, it should be safe to call + // iface.Complete() immediately. + r.p.ifaces = append(r.p.ifaces, iface) + return iface } -- 2.50.0