Skip to content

Commit f5eb0a7

Browse files
committed
cmd/compile/internal/types: remove TTYPEPARAM and TUNION types
These were used by the nounified frontend for representing uninstantiated generic types; however, the unified frontend only needs types1 to represent instantiated types. Updates #57410. Change-Id: Iac417fbf2b86f4e08bd7fdd26ae8ed17395ce833 Reviewed-on: https://go-review.googlesource.com/c/go/+/458621 Run-TryBot: Matthew Dempsky <[email protected]> Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Keith Randall <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent ea6d4b0 commit f5eb0a7

File tree

8 files changed

+23
-248
lines changed

8 files changed

+23
-248
lines changed

src/cmd/compile/internal/noder/helpers.go

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@ func FixValue(typ *types.Type, val constant.Value) constant.Value {
6161
if !typ.IsUntyped() {
6262
val = typecheck.DefaultLit(ir.NewBasicLit(src.NoXPos, val), typ).Val()
6363
}
64-
if !typ.IsTypeParam() {
65-
ir.AssertValidTypeForConst(typ, val)
66-
}
64+
ir.AssertValidTypeForConst(typ, val)
6765
return val
6866
}
6967

@@ -211,15 +209,7 @@ var one = constant.MakeInt64(1)
211209
func IncDec(pos src.XPos, op ir.Op, x ir.Node) *ir.AssignOpStmt {
212210
assert(x.Type() != nil)
213211
bl := ir.NewBasicLit(pos, one)
214-
if x.Type().HasTParam() {
215-
// If the operand is generic, then types2 will have proved it must be
216-
// a type that fits with increment/decrement, so just set the type of
217-
// "one" to n.Type(). This works even for types that are eventually
218-
// float or complex.
219-
typed(x.Type(), bl)
220-
} else {
221-
bl = typecheck.DefaultLit(bl, x.Type())
222-
}
212+
bl = typecheck.DefaultLit(bl, x.Type())
223213
return ir.NewAssignOpStmt(pos, op, x, bl)
224214
}
225215

src/cmd/compile/internal/reflectdata/reflect.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -959,7 +959,7 @@ func formalType(t *types.Type) *types.Type {
959959

960960
func writeType(t *types.Type) *obj.LSym {
961961
t = formalType(t)
962-
if t.IsUntyped() || t.HasTParam() {
962+
if t.IsUntyped() {
963963
base.Fatalf("writeType %v", t)
964964
}
965965

@@ -1260,11 +1260,6 @@ func InterfaceMethodOffset(ityp *types.Type, i int64) int64 {
12601260

12611261
// NeedRuntimeType ensures that a runtime type descriptor is emitted for t.
12621262
func NeedRuntimeType(t *types.Type) {
1263-
if t.HasTParam() {
1264-
// Generic types don't really exist at run-time and have no runtime
1265-
// type descriptor. But we do write out shape types.
1266-
return
1267-
}
12681263
if _, ok := signatset[t]; !ok {
12691264
signatset[t] = struct{}{}
12701265
signatslice = append(signatslice, typeAndStr{t: t, short: types.TypeSymName(t), regular: t.String()})
@@ -1781,9 +1776,6 @@ func CollectPTabs() {
17811776
if s.Pkg.Name != "main" {
17821777
continue
17831778
}
1784-
if n.Type().HasTParam() {
1785-
continue // skip generic functions (#52937)
1786-
}
17871779
ptabs = append(ptabs, n)
17881780
}
17891781
}

src/cmd/compile/internal/typecheck/dcl.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -305,12 +305,6 @@ func autotmpname(n int) string {
305305
// f is method type, with receiver.
306306
// return function type, receiver as first argument (or not).
307307
func NewMethodType(sig *types.Type, recv *types.Type) *types.Type {
308-
if sig.HasTParam() {
309-
base.Fatalf("NewMethodType with type parameters in signature %+v", sig)
310-
}
311-
if recv != nil && recv.HasTParam() {
312-
base.Fatalf("NewMethodType with type parameters in receiver %+v", recv)
313-
}
314308
nrecvs := 0
315309
if recv != nil {
316310
nrecvs++

src/cmd/compile/internal/typecheck/subr.go

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -730,19 +730,7 @@ func implements(t, iface *types.Type, m, samename **types.Field, ptr *int) bool
730730
return false
731731
}
732732

733-
if t.IsInterface() || t.IsTypeParam() {
734-
if t.IsTypeParam() {
735-
// If t is a simple type parameter T, its type and underlying is the same.
736-
// If t is a type definition:'type P[T any] T', its type is P[T] and its
737-
// underlying is T. Therefore we use 't.Underlying() != t' to distinguish them.
738-
if t.Underlying() != t {
739-
CalcMethods(t)
740-
} else {
741-
// A typeparam satisfies an interface if its type bound
742-
// has all the methods of that interface.
743-
t = t.Bound()
744-
}
745-
}
733+
if t.IsInterface() {
746734
i := 0
747735
tms := t.AllMethods().Slice()
748736
for _, im := range iface.AllMethods().Slice() {

src/cmd/compile/internal/types/fmt.go

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -571,27 +571,6 @@ func tconv2(b *bytes.Buffer, t *Type, verb rune, mode fmtMode, visited map[*Type
571571
case TUNSAFEPTR:
572572
b.WriteString("unsafe.Pointer")
573573

574-
case TTYPEPARAM:
575-
if t.Sym() != nil {
576-
sconv2(b, t.Sym(), 'v', mode)
577-
} else {
578-
b.WriteString("tp")
579-
// Print out the pointer value for now to disambiguate type params
580-
fmt.Fprintf(b, "%p", t)
581-
}
582-
583-
case TUNION:
584-
for i := 0; i < t.NumTerms(); i++ {
585-
if i > 0 {
586-
b.WriteString("|")
587-
}
588-
elem, tilde := t.Term(i)
589-
if tilde {
590-
b.WriteString("~")
591-
}
592-
tconv2(b, elem, 0, mode, visited)
593-
}
594-
595574
case Txxx:
596575
b.WriteString("Txxx")
597576

src/cmd/compile/internal/types/kind_string.go

Lines changed: 11 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cmd/compile/internal/types/size.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,6 @@ func expandiface(t *Type) {
123123
continue
124124
}
125125

126-
if m.Type.IsUnion() {
127-
continue
128-
}
129-
130126
// In 1.18, embedded types can be anything. In Go 1.17, we disallow
131127
// embedding anything other than interfaces. This requirement was caught
132128
// by types2 already, so allow non-interface here.
@@ -343,12 +339,6 @@ func CalcSize(t *Type) {
343339
t.align = uint8(PtrSize)
344340
expandiface(t)
345341

346-
case TUNION:
347-
// Always part of an interface for now, so size/align don't matter.
348-
// Pretend a union is represented like an interface.
349-
w = 2 * int64(PtrSize)
350-
t.align = uint8(PtrSize)
351-
352342
case TCHAN: // implemented as pointer
353343
w = int64(PtrSize)
354344

@@ -445,11 +435,6 @@ func CalcSize(t *Type) {
445435
base.Warn("bad type %v %d\n", t1, w)
446436
}
447437
t.align = 1
448-
449-
case TTYPEPARAM:
450-
// TODO(danscales) - remove when we eliminate the need
451-
// to do CalcSize in noder2 (which shouldn't be needed in the noder)
452-
w = int64(PtrSize)
453438
}
454439

455440
if PtrSize == 4 && w != int64(int32(w)) {

0 commit comments

Comments
 (0)