]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.typeparams] cmd/compile: introduce IsTypeParam() helper
authorKeith Randall <khr@golang.org>
Sat, 5 Jun 2021 06:01:13 +0000 (23:01 -0700)
committerKeith Randall <khr@golang.org>
Mon, 7 Jun 2021 19:51:26 +0000 (19:51 +0000)
better than Kind() == types.TTYPEPARAM

Change-Id: I4f35a177cd0cda3be615a92b7b2af1b5a60a3bbc
Reviewed-on: https://go-review.googlesource.com/c/go/+/325410
Trust: Keith Randall <khr@golang.org>
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
src/cmd/compile/internal/noder/helpers.go
src/cmd/compile/internal/typecheck/iexport.go
src/cmd/compile/internal/typecheck/iimport.go
src/cmd/compile/internal/typecheck/subr.go
src/cmd/compile/internal/types/type.go

index ea30a3bfa9994637346452ef45d97c09d40878c9..456df312a6d2b538c96cdefd6af28ded43aea150 100644 (file)
@@ -63,7 +63,7 @@ func FixValue(typ *types.Type, val constant.Value) constant.Value {
        if !typ.IsUntyped() {
                val = typecheck.DefaultLit(ir.NewBasicLit(src.NoXPos, val), typ).Val()
        }
-       if typ.Kind() != types.TTYPEPARAM {
+       if !typ.IsTypeParam() {
                ir.AssertValidTypeForConst(typ, val)
        }
        return val
index 6987bc99188189518c1965c67ca90ffea88f3040..10d4bd6e7eefb6a6b116c0cbcbad4b043983a863 100644 (file)
@@ -522,7 +522,7 @@ func (p *iexporter) doDecl(n *ir.Name) {
                }
 
        case ir.OTYPE:
-               if n.Type().Kind() == types.TTYPEPARAM && n.Type().Underlying() == n.Type() {
+               if n.Type().IsTypeParam() && n.Type().Underlying() == n.Type() {
                        // Even though it has local scope, a typeparam requires a
                        // declaration via its package and unique name, because it
                        // may be referenced within its type bound during its own
@@ -898,7 +898,7 @@ func (w *exportWriter) doTyp(t *types.Type) {
        // The 't.Underlying() == t' check is to confirm this is a base typeparam
        // type, rather than a defined type with typeparam underlying type, like:
        // type orderedAbs[T any] T
-       if t.Kind() == types.TTYPEPARAM && t.Underlying() == t {
+       if t.IsTypeParam() && t.Underlying() == t {
                assert(base.Flag.G > 0)
                if s.Pkg == types.BuiltinPkg || s.Pkg == ir.Pkgs.Unsafe {
                        base.Fatalf("builtin type missing from typIndex: %v", t)
@@ -1042,7 +1042,7 @@ func (w *exportWriter) typeList(ts []*types.Type) {
 func (w *exportWriter) tparamList(fs []*types.Field) {
        w.uint64(uint64(len(fs)))
        for _, f := range fs {
-               if f.Type.Kind() != types.TTYPEPARAM {
+               if !f.Type.IsTypeParam() {
                        base.Fatalf("unexpected non-typeparam")
                }
                w.typ(f.Type)
@@ -1095,7 +1095,7 @@ func (w *exportWriter) value(typ *types.Type, v constant.Value) {
        var kind constant.Kind
        var valType *types.Type
 
-       if typ.Kind() == types.TTYPEPARAM {
+       if typ.IsTypeParam() {
                // A constant will have a TYPEPARAM type if it appears in a place
                // where it must match that typeparam type (e.g. in a binary
                // operation with a variable of that typeparam type). If so, then
index cafb18d7a8802d4b4dcf0b782deb4a4b9806d8d3..6d42875f4964ccb70ab3d3d0ba42ce6c4e2474a2 100644 (file)
@@ -415,7 +415,7 @@ func (p *importReader) value(typ *types.Type) constant.Value {
        var kind constant.Kind
        var valType *types.Type
 
-       if typ.Kind() == types.TTYPEPARAM {
+       if typ.IsTypeParam() {
                // If a constant had a typeparam type, then we wrote out its
                // actual constant kind as well.
                kind = constant.Kind(p.int64())
index 8ef49f91c833584f7ef5187247a9ba03309c3a3b..e9a9a57126955d9b3a29c568357be78ef81ae355 100644 (file)
@@ -984,7 +984,7 @@ func (ts *Tsubster) Typ(t *types.Type) *types.Type {
                return t
        }
 
-       if t.Kind() == types.TTYPEPARAM {
+       if t.IsTypeParam() {
                for i, tp := range ts.Tparams {
                        if tp == t {
                                return ts.Targs[i]
index a3a6050c526844ca19d95df64df37882179808f0..075009d6a3b95efde4cd1f1775bf8c1d02cdd992 100644 (file)
@@ -1487,6 +1487,10 @@ func (t *Type) IsUnion() bool {
        return t.kind == TUNION
 }
 
+func (t *Type) IsTypeParam() bool {
+       return t.kind == TTYPEPARAM
+}
+
 // IsEmptyInterface reports whether t is an empty interface type.
 func (t *Type) IsEmptyInterface() bool {
        return t.IsInterface() && t.AllMethods().Len() == 0