]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.typeparams] cmd/compile/internal/types2: remove support for type parameter point...
authorRobert Griesemer <gri@golang.org>
Wed, 25 Nov 2020 23:20:30 +0000 (15:20 -0800)
committerRobert Griesemer <gri@golang.org>
Tue, 1 Dec 2020 06:30:45 +0000 (06:30 +0000)
An earlier version of the draft design supported pointer designation for
type parameters. Remove related code since we don't need it anymore.

Change-Id: I0d9e8c5f02a9a6745ff7ee15b8267a99ab1529e1
Reviewed-on: https://go-review.googlesource.com/c/go/+/273327
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
src/cmd/compile/internal/types2/builtins.go
src/cmd/compile/internal/types2/decl.go
src/cmd/compile/internal/types2/lookup.go
src/cmd/compile/internal/types2/subst.go
src/cmd/compile/internal/types2/type.go
src/cmd/compile/internal/types2/typestring.go
src/cmd/compile/internal/types2/typexpr.go

index c1706fd873100a74f720adb45d0f0a9c1ac206c2..6ad84f43540bae1c18c028b85ab7be404abfebaa 100644 (file)
@@ -727,7 +727,7 @@ func (check *Checker) applyTypeFunc(f func(Type) Type, x Type) Type {
 
                // construct a suitable new type parameter
                tpar := NewTypeName(nopos, nil /* = Universe pkg */, "<type parameter>", nil)
-               ptyp := check.NewTypeParam(tp.ptr, tpar, 0, &emptyInterface) // assigns type to tpar as a side-effect
+               ptyp := check.NewTypeParam(tpar, 0, &emptyInterface) // assigns type to tpar as a side-effect
                tsum := NewSum(rtypes)
                ptyp.bound = &Interface{types: tsum, allMethods: markComplete, allTypes: tsum}
 
index ef8dc7a245455abfd952947ab6d6f6a5c35b4f40..ff37d85c6f4deb484dc36d294c5adf32e389fa26 100644 (file)
@@ -734,15 +734,9 @@ func (check *Checker) collectTypeParams(list []*syntax.Field) (tparams []*TypeNa
 }
 
 func (check *Checker) declareTypeParam(tparams []*TypeName, name *syntax.Name) []*TypeName {
-       var ptr bool
-       nstr := name.Value
-       if len(nstr) > 0 && nstr[0] == '*' {
-               ptr = true
-               nstr = nstr[1:]
-       }
-       tpar := NewTypeName(name.Pos(), check.pkg, nstr, nil)
-       check.NewTypeParam(ptr, tpar, len(tparams), &emptyInterface) // assigns type to tpar as a side-effect
-       check.declare(check.scope, name, tpar, check.scope.pos)      // TODO(gri) check scope position
+       tpar := NewTypeName(name.Pos(), check.pkg, name.Value, nil)
+       check.NewTypeParam(tpar, len(tparams), &emptyInterface) // assigns type to tpar as a side-effect
+       check.declare(check.scope, name, tpar, check.scope.pos) // TODO(gri) check scope position
        tparams = append(tparams, tpar)
 
        if check.conf.Trace {
index 277212c568dd878e32ae67539fc03e74b0091dd2..e1e7b5814dc89cf1a0f8c8355c0f39851b51027c 100644 (file)
@@ -222,7 +222,7 @@ func (check *Checker) rawLookupFieldOrMethod(T Type, addressable bool, pkg *Pack
                        //        is shorthand for (&x).m()".
                        if f, _ := obj.(*Func); f != nil {
                                // determine if method has a pointer receiver
-                               hasPtrRecv := tpar == nil && ptrRecv(f) || tpar != nil && tpar.ptr
+                               hasPtrRecv := tpar == nil && ptrRecv(f)
                                if hasPtrRecv && !indirect && !addressable {
                                        return nil, nil, true // pointer/addressable receiver required
                                }
index 27c907de10e68262f8ba14486a69dd9debd9cb43..e64e24a8a1c8799808afd44997bf384fb454e74c 100644 (file)
@@ -143,27 +143,14 @@ func (check *Checker) instantiate(pos syntax.Pos, typ Type, targs []Type, poslis
                // - check only if we have methods
                check.completeInterface(nopos, iface)
                if len(iface.allMethods) > 0 {
-                       // If the type argument is a type parameter itself, its pointer designation
-                       // must match the pointer designation of the callee's type parameter.
                        // If the type argument is a pointer to a type parameter, the type argument's
                        // method set is empty.
                        // TODO(gri) is this what we want? (spec question)
-                       if tparg := targ.TypeParam(); tparg != nil {
-                               if tparg.ptr != tpar.ptr {
-                                       check.errorf(pos, "pointer designation mismatch")
-                                       break
-                               }
-                       } else if base, isPtr := deref(targ); isPtr && base.TypeParam() != nil {
+                       if base, isPtr := deref(targ); isPtr && base.TypeParam() != nil {
                                check.errorf(pos, "%s has no methods", targ)
                                break
                        }
-                       // If a type parameter is marked as a pointer type, the type bound applies
-                       // to a pointer of the type argument.
-                       actual := targ
-                       if tpar.ptr {
-                               actual = NewPointer(targ)
-                       }
-                       if m, wrong := check.missingMethod(actual, iface, true); m != nil {
+                       if m, wrong := check.missingMethod(targ, iface, true); m != nil {
                                // TODO(gri) needs to print updated name to avoid major confusion in error message!
                                //           (print warning for now)
                                // check.softErrorf(pos, "%s does not satisfy %s (warning: name not updated) = %s (missing method %s)", targ, tpar.bound, iface, m)
index c26d243f3c230b1f4b6a066386aa687c408fb068..1bfde41159644325ea36f7e2001d787dc086f040 100644 (file)
@@ -832,7 +832,6 @@ func (t *Named) AddMethod(m *Func) {
 type TypeParam struct {
        check *Checker  // for lazy type bound completion
        id    uint64    // unique id
-       ptr   bool      // pointer designation
        obj   *TypeName // corresponding type name
        index int       // parameter index
        bound Type      // *Named or *Interface; underlying type is always *Interface
@@ -840,9 +839,9 @@ type TypeParam struct {
 }
 
 // NewTypeParam returns a new TypeParam.
-func (check *Checker) NewTypeParam(ptr bool, obj *TypeName, index int, bound Type) *TypeParam {
+func (check *Checker) NewTypeParam(obj *TypeName, index int, bound Type) *TypeParam {
        assert(bound != nil)
-       typ := &TypeParam{check: check, id: check.nextId, ptr: ptr, obj: obj, index: index, bound: bound}
+       typ := &TypeParam{check: check, id: check.nextId, obj: obj, index: index, bound: bound}
        check.nextId++
        if obj.typ == nil {
                obj.typ = typ
index 98021797a1807441807f3f6300e66d5cb8f0f48b..6b6d7ad2be32a4e2dbadd9470cba3674c6cbdae4 100644 (file)
@@ -350,9 +350,6 @@ func writeTParamList(buf *bytes.Buffer, list []*TypeName, qf Qualifier, visited
                prev = b
 
                if t, _ := p.typ.(*TypeParam); t != nil {
-                       if t.ptr {
-                               buf.WriteByte('*')
-                       }
                        writeType(buf, t, qf, visited)
                } else {
                        buf.WriteString(p.name)
index 0edd7731fad5cc6051743f94151ce02de527e1ad..1adf967859a0f6c38c388144d54efd30a460a91e 100644 (file)
@@ -307,12 +307,8 @@ func (check *Checker) funcType(sig *Signature, recvPar *syntax.Field, tparams []
                        // - only do this if we have the right number (otherwise an error is reported elsewhere)
                        if len(sig.rparams) == len(recvTParams) {
                                // We have a list of *TypeNames but we need a list of Types.
-                               // While creating this list, also update type parameter pointer designation
-                               // for each (*TypeParam) list entry, by copying the information from the
-                               // receiver base type's type parameters.
                                list := make([]Type, len(sig.rparams))
                                for i, t := range sig.rparams {
-                                       t.typ.(*TypeParam).ptr = recvTParams[i].typ.(*TypeParam).ptr
                                        list[i] = t.typ
                                }
                                for i, tname := range sig.rparams {