]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.typeparams] cmd/compile: handle objStub earlier in reader
authorMatthew Dempsky <mdempsky@google.com>
Tue, 13 Jul 2021 20:25:16 +0000 (13:25 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Wed, 14 Jul 2021 02:41:01 +0000 (02:41 +0000)
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 <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
src/cmd/compile/internal/noder/reader.go

index 25aac6c026a62a466025b11688a70e5ea40670c6..2351d1d0ba61538e38cbf92e39e706ee3b1a1129 100644 (file)
@@ -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())