]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.typeparams] cmd/compile: fold reader checking type params logic to separate...
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Sun, 20 Jun 2021 07:33:51 +0000 (14:33 +0700)
committerCuong Manh Le <cuong.manhle.vn@gmail.com>
Mon, 21 Jun 2021 04:53:09 +0000 (04:53 +0000)
So making it less verbose and clearer to the reader what that check means.

Change-Id: I41587aab399e63600356c5cecec64978048bed36
Reviewed-on: https://go-review.googlesource.com/c/go/+/329571
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/internal/noder/reader.go

index 004f9cc271d34653770e18cd4462f2871b2ff42a..ad3cc25fd0bd945da77dcf3ccf98ddabf98b02db 100644 (file)
@@ -543,7 +543,7 @@ func (pr *pkgReader) objIdx(idx int, implicits, explicits []*types.Type) ir.Node
                        return pri.pr.objIdx(pri.idx, pri.implicits, r.explicits)
                }
                if haveLegacyImports {
-                       assert(len(r.implicits)+len(r.explicits) == 0)
+                       assert(!r.hasTypeParams())
                        return typecheck.Resolve(ir.NewIdent(src.NoXPos, origSym))
                }
                base.Fatalf("unresolved stub: %v", origSym)
@@ -608,7 +608,7 @@ func (pr *pkgReader) objIdx(idx int, implicits, explicits []*types.Type) ir.Node
 }
 
 func (r *reader) mangle(sym *types.Sym) *types.Sym {
-       if len(r.implicits)+len(r.explicits) == 0 {
+       if !r.hasTypeParams() {
                return sym
        }
 
@@ -722,6 +722,10 @@ func (r *reader) selector() (origPkg *types.Pkg, sym *types.Sym) {
        return
 }
 
+func (r *reader) hasTypeParams() bool {
+       return len(r.implicits)+len(r.explicits) != 0
+}
+
 // @@@ Compiler extensions
 
 func (r *reader) funcExt(name *ir.Name) {
@@ -739,7 +743,7 @@ func (r *reader) funcExt(name *ir.Name) {
 
        // TODO(mdempsky): Remember why I wrote this code. I think it has to
        // do with how ir.VisitFuncsBottomUp works?
-       if name.Sym().Pkg == types.LocalPkg || len(r.implicits)+len(r.explicits) != 0 {
+       if name.Sym().Pkg == types.LocalPkg || r.hasTypeParams() {
                name.Defn = fn
        }
 
@@ -774,7 +778,7 @@ func (r *reader) typeExt(name *ir.Name) {
 
        typ := name.Type()
 
-       if len(r.implicits)+len(r.explicits) != 0 {
+       if r.hasTypeParams() {
                // Set "RParams" (really type arguments here, not parameters) so
                // this type is treated as "fully instantiated". This ensures the
                // type descriptor is written out as DUPOK and method wrappers are