From aa381c538af4eeaf5044ca657c5778805bed77d7 Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Mon, 11 Sep 2023 18:50:26 -0700 Subject: [PATCH] cmd/compile/internal/types: remove Type.vargen The unified frontend diasmbiguates local types by putting vargen directly into their symbol name instead. We no longer need a separate int field for it. Change-Id: I556c588ed68c5e2cb324cd46abd934894b5aaef9 Reviewed-on: https://go-review.googlesource.com/c/go/+/527517 Reviewed-by: Cuong Manh Le Auto-Submit: Matthew Dempsky Reviewed-by: Than McIntosh LUCI-TryBot-Result: Go LUCI --- src/cmd/compile/internal/types/fmt.go | 8 ------ src/cmd/compile/internal/types/sizeof_test.go | 2 +- src/cmd/compile/internal/types/type.go | 27 +------------------ 3 files changed, 2 insertions(+), 35 deletions(-) diff --git a/src/cmd/compile/internal/types/fmt.go b/src/cmd/compile/internal/types/fmt.go index 4f27baeab7..c9b9853f78 100644 --- a/src/cmd/compile/internal/types/fmt.go +++ b/src/cmd/compile/internal/types/fmt.go @@ -319,14 +319,6 @@ func tconv2(b *bytes.Buffer, t *Type, verb rune, mode fmtMode, visited map[*Type } } sconv2(b, sym, verb, mode) - - // TODO(mdempsky): Investigate including Vargen in fmtTypeIDName - // output too. It seems like it should, but that mode is currently - // used in string representation used by reflection, which is - // user-visible and doesn't expect this. - if mode == fmtTypeID && t.vargen != 0 { - fmt.Fprintf(b, "·%d", t.vargen) - } return } diff --git a/src/cmd/compile/internal/types/sizeof_test.go b/src/cmd/compile/internal/types/sizeof_test.go index 8a6f24124a..a06ab0d18c 100644 --- a/src/cmd/compile/internal/types/sizeof_test.go +++ b/src/cmd/compile/internal/types/sizeof_test.go @@ -21,7 +21,7 @@ func TestSizeof(t *testing.T) { _64bit uintptr // size on 64bit platforms }{ {Sym{}, 32, 64}, - {Type{}, 56, 96}, + {Type{}, 52, 96}, {Map{}, 12, 24}, {Forward{}, 20, 32}, {Func{}, 32, 56}, diff --git a/src/cmd/compile/internal/types/type.go b/src/cmd/compile/internal/types/type.go index fd01ef8c0e..49ac5d7b1c 100644 --- a/src/cmd/compile/internal/types/type.go +++ b/src/cmd/compile/internal/types/type.go @@ -156,7 +156,7 @@ var DefaultKinds = [...]Kind{ // package.Lookup(name)) and checking sym.Def. If sym.Def is non-nil, the type // already exists at package scope and is available at sym.Def.(*ir.Name).Type(). // Local types (which may have the same name as a package-level type) are -// distinguished by the value of vargen. +// distinguished by their vargen, which is embedded in their symbol name. type Type struct { // extra contains extra etype-specific fields. // As an optimization, those etype-specific structs which contain exactly @@ -195,8 +195,6 @@ type Type struct { slice *Type // []T, or nil } - vargen int32 // unique name for OTYPE/ONAME - kind Kind // kind of type align uint8 // the required alignment of this type, in bytes (0 means Width and Align have not yet been computed) @@ -1114,10 +1112,6 @@ func (t *Type) cmp(x *Type) Cmp { } if x.obj != nil { - // Syms non-nil, if vargens match then equal. - if t.vargen != x.vargen { - return cmpForNe(t.vargen < x.vargen) - } return CMPeq } // both syms nil, look at structure below. @@ -1617,25 +1611,6 @@ func (t *Type) Obj() Object { return t.obj } -// typeGen tracks the number of function-scoped defined types that -// have been declared. It's used to generate unique linker symbols for -// their runtime type descriptors. -var typeGen int32 - -// SetVargen assigns a unique generation number to type t, which must -// be a defined type declared within function scope. The generation -// number is used to distinguish it from other similarly spelled -// defined types from the same package. -// -// TODO(mdempsky): Come up with a better solution. -func (t *Type) SetVargen() { - base.Assertf(t.Sym() != nil, "SetVargen on anonymous type %v", t) - base.Assertf(t.vargen == 0, "type %v already has Vargen %v", t, t.vargen) - - typeGen++ - t.vargen = typeGen -} - // SetUnderlying sets the underlying type of an incomplete type (i.e. type whose kind // is currently TFORW). SetUnderlying automatically updates any types that were waiting // for this type to be completed. -- 2.50.0