From 82744bfbfc2d0407ecf1bf055f548c3948d4683b Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Tue, 13 Jul 2021 13:25:16 -0700 Subject: [PATCH] [dev.typeparams] cmd/compile: handle objStub earlier in reader There's no point in reading the object dictionary for a stub declaration. Only the package that contains the full object definition will contain an object dictionary. Change-Id: I458b77d20745105bf46190ef552312bdb5ca4d06 Reviewed-on: https://go-review.googlesource.com/c/go/+/334409 Trust: Matthew Dempsky Run-TryBot: Matthew Dempsky TryBot-Result: Go Bot Reviewed-by: Cuong Manh Le --- src/cmd/compile/internal/noder/reader.go | 38 +++++++++++++----------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/cmd/compile/internal/noder/reader.go b/src/cmd/compile/internal/noder/reader.go index 25aac6c026..2351d1d0ba 100644 --- a/src/cmd/compile/internal/noder/reader.go +++ b/src/cmd/compile/internal/noder/reader.go @@ -520,14 +520,22 @@ func (pr *pkgReader) objIdx(idx int, implicits, explicits []*types.Type) ir.Node r.typeParamBounds(sym, implicits, explicits) - origSym := sym - - sym = r.mangle(sym) - if !sym.IsBlank() && sym.Def != nil { - return sym.Def.(ir.Node) - } - tag := codeObj(r.code(syncCodeObj)) + if tag == objStub { + assert(!sym.IsBlank()) + switch sym.Pkg { + case types.BuiltinPkg, ir.Pkgs.Unsafe: + return sym.Def.(ir.Node) + } + if pri, ok := objReader[sym]; ok { + return pri.pr.objIdx(pri.idx, nil, explicits) + } + if haveLegacyImports { + assert(!r.hasTypeParams()) + return typecheck.Resolve(ir.NewIdent(src.NoXPos, sym)) + } + base.Fatalf("unresolved stub: %v", sym) + } { rdict := pr.newReader(relocObjDict, idx, syncObject1) @@ -538,6 +546,11 @@ func (pr *pkgReader) objIdx(idx int, implicits, explicits []*types.Type) ir.Node } } + sym = r.mangle(sym) + if !sym.IsBlank() && sym.Def != nil { + return sym.Def.(*ir.Name) + } + do := func(op ir.Op, hasTParams bool) *ir.Name { pos := r.pos() if hasTParams { @@ -560,17 +573,6 @@ func (pr *pkgReader) objIdx(idx int, implicits, explicits []*types.Type) ir.Node default: panic("unexpected object") - case objStub: - if pri, ok := objReader[origSym]; ok { - return pri.pr.objIdx(pri.idx, nil, explicits) - } - if haveLegacyImports { - assert(!r.hasTypeParams()) - return typecheck.Resolve(ir.NewIdent(src.NoXPos, origSym)) - } - base.Fatalf("unresolved stub: %v", origSym) - panic("unreachable") - case objAlias: name := do(ir.OTYPE, false) r.setType(name, r.typ())