]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/types2: move NewTypeParam off of Checker
authorRobert Griesemer <gri@golang.org>
Wed, 8 Sep 2021 20:45:16 +0000 (13:45 -0700)
committerRobert Griesemer <gri@golang.org>
Wed, 8 Sep 2021 22:41:27 +0000 (22:41 +0000)
This is a port of CL 347561.

A comment was corrected both in types2 and go/types, and the
compiler adjusted for the updated NewTypeParameter function.

Change-Id: I4381f0dd8e43228e1d037c5d997d421b7838f905
Reviewed-on: https://go-review.googlesource.com/c/go/+/348574
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
src/cmd/compile/internal/importer/iimport.go
src/cmd/compile/internal/noder/reader2.go
src/cmd/compile/internal/types2/builtins.go
src/cmd/compile/internal/types2/decl.go
src/cmd/compile/internal/types2/typeparam.go
src/go/types/typeparam.go

index 38cb8db23557b170d140df4da081475716774b92..646cad60d9a90758dfc6f7fc8aed770b83f08c07 100644 (file)
@@ -365,7 +365,7 @@ func (r *importReader) obj(name string) {
                }
                name0, sub := parseSubscript(name)
                tn := types2.NewTypeName(pos, r.currPkg, name0, nil)
-               t := (*types2.Checker)(nil).NewTypeParam(tn, nil)
+               t := types2.NewTypeParam(tn, nil)
                if sub == 0 {
                        errorf("missing subscript")
                }
index 6c0d9c8c9dad4fc7dda9427d419c1827354cc88e..a5e925b3db3d54447048acc94531a14f68a60a07 100644 (file)
@@ -483,7 +483,7 @@ func (r *reader2) typeParamNames() []*types2.TypeParam {
                pkg, name := r.localIdent()
 
                tname := types2.NewTypeName(pos, pkg, name, nil)
-               r.dict.tparams[i] = r.p.check.NewTypeParam(tname, nil)
+               r.dict.tparams[i] = types2.NewTypeParam(tname, nil)
        }
 
        for i, bound := range r.dict.bounds {
index e3844d5163e168313143e038e568052eb5474ba3..3b8d85859a7eb70741f88d72cbd2b947e9e3b344 100644 (file)
@@ -826,7 +826,7 @@ func (check *Checker) applyTypeFunc(f func(Type) Type, x Type) Type {
                // type param is placed in the current package so export/import
                // works as expected.
                tpar := NewTypeName(nopos, check.pkg, "<type parameter>", nil)
-               ptyp := check.NewTypeParam(tpar, NewInterfaceType(nil, []Type{NewUnion(terms)})) // assigns type to tpar as a side-effect
+               ptyp := check.newTypeParam(tpar, NewInterfaceType(nil, []Type{NewUnion(terms)})) // assigns type to tpar as a side-effect
                ptyp.index = tp.index
 
                return ptyp
index 1d46b004b620f669bab5bde3fd2171c44d525dd7..5be4a9f804dfc85c7654a80a464baa2b6c85afb9 100644 (file)
@@ -648,7 +648,7 @@ func (check *Checker) declareTypeParam(name *syntax.Name) *TypeParam {
        //           constraints to make sure we don't rely on them if they
        //           are not properly set yet.
        tname := NewTypeName(name.Pos(), check.pkg, name.Value, nil)
-       tpar := check.NewTypeParam(tname, Typ[Invalid])          // assigns type to tname as a side-effect
+       tpar := check.newTypeParam(tname, Typ[Invalid])          // assigns type to tname as a side-effect
        check.declare(check.scope, name, tname, check.scope.pos) // TODO(gri) check scope position
        return tpar
 }
index 445337fee88ed85b5a8bd6f3e661ff2cd4815682..e7181281afb5fac6e193c350ea949f688ccc3f02 100644 (file)
@@ -32,15 +32,19 @@ func (t *TypeParam) Obj() *TypeName { return t.obj }
 // or Signature type by calling SetTParams. Setting a type parameter on more
 // than one type will result in a panic.
 //
-// The bound argument can be nil, and set later via SetBound.
-func (check *Checker) NewTypeParam(obj *TypeName, bound Type) *TypeParam {
+// The constraint argument can be nil, and set later via SetConstraint.
+func NewTypeParam(obj *TypeName, constraint Type) *TypeParam {
+       return (*Checker)(nil).newTypeParam(obj, constraint)
+}
+
+func (check *Checker) newTypeParam(obj *TypeName, constraint Type) *TypeParam {
        // Always increment lastID, even if it is not used.
        id := nextID()
        if check != nil {
                check.nextID++
                id = check.nextID
        }
-       typ := &TypeParam{check: check, id: id, obj: obj, index: -1, bound: bound}
+       typ := &TypeParam{check: check, id: id, obj: obj, index: -1, bound: constraint}
        if obj.typ == nil {
                obj.typ = typ
        }
index a0f2a3acd0d15cc352a9e4e883b19796ca0ed3b7..150ad079a8889fc9c3f4796c3ccd4acb89c35c8e 100644 (file)
@@ -32,7 +32,7 @@ type TypeParam struct {
 // or Signature type by calling SetTypeParams. Setting a type parameter on more
 // than one type will result in a panic.
 //
-// The bound argument can be nil, and set later via SetConstraint.
+// The constraint argument can be nil, and set later via SetConstraint.
 func NewTypeParam(obj *TypeName, constraint Type) *TypeParam {
        return (*Checker)(nil).newTypeParam(obj, constraint)
 }