]> Cypherpunks.ru repositories - gostls13.git/commitdiff
[dev.typeparams] cmd/compile/internal/types2: move instance.go contents into named...
authorRobert Griesemer <gri@golang.org>
Fri, 30 Jul 2021 05:24:37 +0000 (22:24 -0700)
committerRobert Griesemer <gri@golang.org>
Mon, 2 Aug 2021 21:08:34 +0000 (21:08 +0000)
This just moves the code around the instance type into named.go
where it belongs. While at it, also removed some left-over references
to instance types (which are gone). Removed instance.go.

Change-Id: I302a86ca50675b0be54f6138fa47f48f00f9c98f
Reviewed-on: https://go-review.googlesource.com/c/go/+/338469
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
src/cmd/compile/internal/types2/instance.go [deleted file]
src/cmd/compile/internal/types2/named.go
src/cmd/compile/internal/types2/predicates.go
src/cmd/compile/internal/types2/unify.go

diff --git a/src/cmd/compile/internal/types2/instance.go b/src/cmd/compile/internal/types2/instance.go
deleted file mode 100644 (file)
index 40e8928..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-// Copyright 2011 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package types2
-
-// TODO(rfindley): move this code to named.go.
-
-import "cmd/compile/internal/syntax"
-
-// instance holds position information for use in lazy instantiation.
-//
-// TODO(rfindley): come up with a better name for this type, now that its usage
-// has changed.
-type instance struct {
-       pos     syntax.Pos   // position of type instantiation; for error reporting only
-       posList []syntax.Pos // position of each targ; for error reporting only
-}
-
-// expand ensures that the underlying type of n is instantiated.
-// The underlying type will be Typ[Invalid] if there was an error.
-func (n *Named) expand() {
-       if n.instance != nil {
-               // n must be loaded before instantiation, in order to have accurate
-               // tparams. This is done implicitly by the call to n.TParams, but making it
-               // explicit is harmless: load is idempotent.
-               n.load()
-               inst := n.check.instantiate(n.instance.pos, n.orig.underlying, n.TParams().list(), n.targs, n.instance.posList)
-               n.underlying = inst
-               n.fromRHS = inst
-               n.instance = nil
-       }
-}
-
-// expand expands uninstantiated named types and leaves all other types alone.
-// expand does not recurse.
-func expand(typ Type) Type {
-       if t, _ := typ.(*Named); t != nil {
-               t.expand()
-       }
-       return typ
-}
index 96f2db1429d79f1d10e2e8ab2f784eae2e08db14..8ded197df5b08f771aefb301e2d1b66e717ab1cb 100644 (file)
@@ -4,7 +4,10 @@
 
 package types2
 
-import "sync"
+import (
+       "cmd/compile/internal/syntax"
+       "sync"
+)
 
 // TODO(gri) Clean up Named struct below; specifically the fromRHS field (can we use underlying?).
 
@@ -252,3 +255,36 @@ func (n *Named) setUnderlying(typ Type) {
                n.underlying = typ
        }
 }
+
+// instance holds position information for use in lazy instantiation.
+//
+// TODO(rfindley): come up with a better name for this type, now that its usage
+// has changed.
+type instance struct {
+       pos     syntax.Pos   // position of type instantiation; for error reporting only
+       posList []syntax.Pos // position of each targ; for error reporting only
+}
+
+// expand ensures that the underlying type of n is instantiated.
+// The underlying type will be Typ[Invalid] if there was an error.
+func (n *Named) expand() {
+       if n.instance != nil {
+               // n must be loaded before instantiation, in order to have accurate
+               // tparams. This is done implicitly by the call to n.TParams, but making it
+               // explicit is harmless: load is idempotent.
+               n.load()
+               inst := n.check.instantiate(n.instance.pos, n.orig.underlying, n.TParams().list(), n.targs, n.instance.posList)
+               n.underlying = inst
+               n.fromRHS = inst
+               n.instance = nil
+       }
+}
+
+// expand expands uninstantiated named types and leaves all other types alone.
+// expand does not recurse.
+func expand(typ Type) Type {
+       if t, _ := typ.(*Named); t != nil {
+               t.expand()
+       }
+       return typ
+}
index 84342b2796a7956205cfe4bb9ec4e1c502501721..bb7fedda3b23f0cf7a02bd34759010fbb6e14287 100644 (file)
@@ -57,9 +57,6 @@ func isNumericOrString(typ Type) bool { return is(typ, IsNumeric|IsString) }
 func isTyped(typ Type) bool {
        // isTyped is called with types that are not fully
        // set up. Must not call asBasic()!
-       // A *Named or *instance type is always typed, so
-       // we only need to check if we have a true *Basic
-       // type.
        t, _ := typ.(*Basic)
        return t == nil || t.info&IsUntyped == 0
 }
@@ -328,9 +325,6 @@ func identical(x, y Type, cmpTags bool, p *ifacePair) bool {
        case *TypeParam:
                // nothing to do (x and y being equal is caught in the very beginning of this function)
 
-       // case *instance:
-       //      unreachable since types are expanded
-
        case *top:
                // Either both types are theTop in which case the initial x == y check
                // will have caught them. Otherwise they are not identical.
index 7221356354aca128a9f0134deaa4f3e1f296ce44..aa9a23d243b37e28c120e8fe9d71e09e95f7e66a 100644 (file)
@@ -459,9 +459,6 @@ func (u *unifier) nify(x, y Type, p *ifacePair) bool {
                // are identical if they originate in the same declaration.
                return x == y
 
-       // case *instance:
-       //      unreachable since types are expanded
-
        case nil:
                // avoid a crash in case of nil type