Skip to content

Commit 5d06d16

Browse files
cuonglmgopherbot
authored andcommitted
cmd/compile: remove types.Type rparams field
This field is present during the initial development of generic support inside compiler, and indicating whether a type is fully instantiated is the solely purpose at this moment. Further, its name is also confused, and there have been a TODO to chose a better name for it. Instead, just using a bit to track whether a type is fully instantiated, then this rparams field can be removed to simplify the code. Change-Id: Ia29c6dd5792487c440b83b0f3b77bd60917c2019 Reviewed-on: https://go-review.googlesource.com/c/go/+/611255 Reviewed-by: Tim King <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Keith Randall <[email protected]> Auto-Submit: Cuong Manh Le <[email protected]> Reviewed-by: Keith Randall <[email protected]>
1 parent ec67622 commit 5d06d16

File tree

3 files changed

+26
-56
lines changed

3 files changed

+26
-56
lines changed

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,13 +1190,16 @@ func (r *reader) typeExt(name *ir.Name) {
11901190
typ := name.Type()
11911191

11921192
if r.hasTypeParams() {
1193-
// Set "RParams" (really type arguments here, not parameters) so
1194-
// this type is treated as "fully instantiated". This ensures the
1195-
// type descriptor is written out as DUPOK and method wrappers are
1196-
// generated even for imported types.
1197-
var targs []*types.Type
1198-
targs = append(targs, r.dict.targs...)
1199-
typ.SetRParams(targs)
1193+
// Mark type as fully instantiated to ensure the type descriptor is written
1194+
// out as DUPOK and method wrappers are generated even for imported types.
1195+
typ.SetIsFullyInstantiated(true)
1196+
// HasShape should be set if any type argument is or has a shape type.
1197+
for _, targ := range r.dict.targs {
1198+
if targ.HasShape() {
1199+
typ.SetHasShape(true)
1200+
break
1201+
}
1202+
}
12001203
}
12011204

12021205
name.SetPragma(r.pragmaFlag())

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func TestSizeof(t *testing.T) {
2121
_64bit uintptr // size on 64bit platforms
2222
}{
2323
{Sym{}, 32, 64},
24-
{Type{}, 64, 104},
24+
{Type{}, 60, 96},
2525
{Map{}, 16, 32},
2626
{Forward{}, 20, 32},
2727
{Func{}, 32, 56},

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

Lines changed: 15 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -208,16 +208,6 @@ type Type struct {
208208
// Note that for pointers, this is always PtrSize even if the element type
209209
// is NotInHeap. See size.go:PtrDataSize for details.
210210
ptrBytes int64
211-
212-
// For defined (named) generic types, a pointer to the list of type params
213-
// (in order) of this type that need to be instantiated. For instantiated
214-
// generic types, this is the targs used to instantiate them. These targs
215-
// may be typeparams (for re-instantiated types such as Value[T2]) or
216-
// concrete types (for fully instantiated types such as Value[int]).
217-
// rparams is only set for named types that are generic or are fully
218-
// instantiated from a generic type, and is otherwise set to nil.
219-
// TODO(danscales): choose a better name.
220-
rparams *[]*Type
221211
}
222212

223213
// Registers returns the number of integer and floating-point
@@ -240,19 +230,24 @@ const (
240230
typeRecur
241231
typeIsShape // represents a set of closely related types, for generics
242232
typeHasShape // there is a shape somewhere in the type
233+
// typeIsFullyInstantiated reports whether a type is fully instantiated generic type; i.e.
234+
// an instantiated generic type where all type arguments are non-generic or fully instantiated generic types.
235+
typeIsFullyInstantiated
243236
)
244237

245-
func (t *Type) NotInHeap() bool { return t.flags&typeNotInHeap != 0 }
246-
func (t *Type) Noalg() bool { return t.flags&typeNoalg != 0 }
247-
func (t *Type) Deferwidth() bool { return t.flags&typeDeferwidth != 0 }
248-
func (t *Type) Recur() bool { return t.flags&typeRecur != 0 }
249-
func (t *Type) IsShape() bool { return t.flags&typeIsShape != 0 }
250-
func (t *Type) HasShape() bool { return t.flags&typeHasShape != 0 }
238+
func (t *Type) NotInHeap() bool { return t.flags&typeNotInHeap != 0 }
239+
func (t *Type) Noalg() bool { return t.flags&typeNoalg != 0 }
240+
func (t *Type) Deferwidth() bool { return t.flags&typeDeferwidth != 0 }
241+
func (t *Type) Recur() bool { return t.flags&typeRecur != 0 }
242+
func (t *Type) IsShape() bool { return t.flags&typeIsShape != 0 }
243+
func (t *Type) HasShape() bool { return t.flags&typeHasShape != 0 }
244+
func (t *Type) IsFullyInstantiated() bool { return t.flags&typeIsFullyInstantiated != 0 }
251245

252-
func (t *Type) SetNotInHeap(b bool) { t.flags.set(typeNotInHeap, b) }
253-
func (t *Type) SetNoalg(b bool) { t.flags.set(typeNoalg, b) }
254-
func (t *Type) SetDeferwidth(b bool) { t.flags.set(typeDeferwidth, b) }
255-
func (t *Type) SetRecur(b bool) { t.flags.set(typeRecur, b) }
246+
func (t *Type) SetNotInHeap(b bool) { t.flags.set(typeNotInHeap, b) }
247+
func (t *Type) SetNoalg(b bool) { t.flags.set(typeNoalg, b) }
248+
func (t *Type) SetDeferwidth(b bool) { t.flags.set(typeDeferwidth, b) }
249+
func (t *Type) SetRecur(b bool) { t.flags.set(typeRecur, b) }
250+
func (t *Type) SetIsFullyInstantiated(b bool) { t.flags.set(typeIsFullyInstantiated, b) }
256251

257252
// Should always do SetHasShape(true) when doing SetIsShape(true).
258253
func (t *Type) SetIsShape(b bool) { t.flags.set(typeIsShape, b) }
@@ -281,34 +276,6 @@ func (t *Type) Pos() src.XPos {
281276
return src.NoXPos
282277
}
283278

284-
func (t *Type) RParams() []*Type {
285-
if t.rparams == nil {
286-
return nil
287-
}
288-
return *t.rparams
289-
}
290-
291-
func (t *Type) SetRParams(rparams []*Type) {
292-
if len(rparams) == 0 {
293-
base.Fatalf("Setting nil or zero-length rparams")
294-
}
295-
t.rparams = &rparams
296-
// HasShape should be set if any type argument is or has a shape type.
297-
for _, rparam := range rparams {
298-
if rparam.HasShape() {
299-
t.SetHasShape(true)
300-
break
301-
}
302-
}
303-
}
304-
305-
// IsFullyInstantiated reports whether t is a fully instantiated generic type; i.e. an
306-
// instantiated generic type where all type arguments are non-generic or fully
307-
// instantiated generic types.
308-
func (t *Type) IsFullyInstantiated() bool {
309-
return len(t.RParams()) > 0
310-
}
311-
312279
// Map contains Type fields specific to maps.
313280
type Map struct {
314281
Key *Type // Key type

0 commit comments

Comments
 (0)