diff options
author | Matthew Dempsky <mdempsky@google.com> | 2021-08-26 12:05:45 -0700 |
---|---|---|
committer | Matthew Dempsky <mdempsky@google.com> | 2021-08-26 19:34:58 +0000 |
commit | eb6a07fcf99050c447097a8ff6358c484c0f8715 (patch) | |
tree | ac169b5c63e13f13bc1e490bc024d6ba1b6d9b88 /src/cmd/compile/internal/types/type.go | |
parent | 3836983779a8f1f1a1b6dc629832e695dcacaf36 (diff) | |
download | go-eb6a07fcf99050c447097a8ff6358c484c0f8715.tar.gz go-eb6a07fcf99050c447097a8ff6358c484c0f8715.zip |
cmd/compile: unexport Type.Vargen
This field is only used outside of packages types in two places, and
they follow the same pattern. So this CL creates a Type.Setvargen
function that they can use instead, so that Type.Vargen can be
unexported.
A bit clumsy, but it works for now.
Change-Id: I7b4f33fac635e2464df2fbc0607ab40902f6f09f
Reviewed-on: https://go-review.googlesource.com/c/go/+/345469
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/types/type.go')
-rw-r--r-- | src/cmd/compile/internal/types/type.go | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/src/cmd/compile/internal/types/type.go b/src/cmd/compile/internal/types/type.go index 975280753a..06348c5094 100644 --- a/src/cmd/compile/internal/types/type.go +++ b/src/cmd/compile/internal/types/type.go @@ -178,7 +178,7 @@ type Type struct { } sym *Sym // symbol containing name, for named types - Vargen int32 // unique name for OTYPE/ONAME + 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) @@ -1221,8 +1221,8 @@ func (t *Type) cmp(x *Type) Cmp { if x.sym != nil { // Syms non-nil, if vargens match then equal. - if t.Vargen != x.Vargen { - return cmpForNe(t.Vargen < x.Vargen) + if t.vargen != x.vargen { + return cmpForNe(t.vargen < x.vargen) } return CMPeq } @@ -1768,6 +1768,25 @@ func (t *Type) Obj() Object { return nil } +// 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. SetUnderlying automatically updates any // types that were waiting for this type to be completed. func (t *Type) SetUnderlying(underlying *Type) { |