mirror of https://github.com/golang/go.git
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>
This commit is contained in:
parent
3836983779
commit
eb6a07fcf9
|
|
@ -154,8 +154,7 @@ func (g *irgen) typeDecl(out *ir.Nodes, decl *syntax.TypeDecl) {
|
||||||
name, obj := g.def(decl.Name)
|
name, obj := g.def(decl.Name)
|
||||||
ntyp, otyp := name.Type(), obj.Type()
|
ntyp, otyp := name.Type(), obj.Type()
|
||||||
if ir.CurFunc != nil {
|
if ir.CurFunc != nil {
|
||||||
typecheck.TypeGen++
|
ntyp.SetVargen()
|
||||||
ntyp.Vargen = typecheck.TypeGen
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pragmas := g.pragmaFlags(decl.Pragma, typePragmas)
|
pragmas := g.pragmaFlags(decl.Pragma, typePragmas)
|
||||||
|
|
|
||||||
|
|
@ -1736,11 +1736,6 @@ func CheckMapKeys() {
|
||||||
mapqueue = nil
|
mapqueue = 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
|
|
||||||
|
|
||||||
func typecheckdeftype(n *ir.Name) {
|
func typecheckdeftype(n *ir.Name) {
|
||||||
if base.EnableTrace && base.Flag.LowerT {
|
if base.EnableTrace && base.Flag.LowerT {
|
||||||
defer tracePrint("typecheckdeftype", n)(nil)
|
defer tracePrint("typecheckdeftype", n)(nil)
|
||||||
|
|
@ -1748,8 +1743,7 @@ func typecheckdeftype(n *ir.Name) {
|
||||||
|
|
||||||
t := types.NewNamed(n)
|
t := types.NewNamed(n)
|
||||||
if n.Curfn != nil {
|
if n.Curfn != nil {
|
||||||
TypeGen++
|
t.SetVargen()
|
||||||
t.Vargen = TypeGen
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if n.Pragma()&ir.NotInHeap != 0 {
|
if n.Pragma()&ir.NotInHeap != 0 {
|
||||||
|
|
|
||||||
|
|
@ -361,8 +361,8 @@ func tconv2(b *bytes.Buffer, t *Type, verb rune, mode fmtMode, visited map[*Type
|
||||||
// output too. It seems like it should, but that mode is currently
|
// output too. It seems like it should, but that mode is currently
|
||||||
// used in string representation used by reflection, which is
|
// used in string representation used by reflection, which is
|
||||||
// user-visible and doesn't expect this.
|
// user-visible and doesn't expect this.
|
||||||
if mode == fmtTypeID && t.Vargen != 0 {
|
if mode == fmtTypeID && t.vargen != 0 {
|
||||||
fmt.Fprintf(b, "·%d", t.Vargen)
|
fmt.Fprintf(b, "·%d", t.vargen)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -178,7 +178,7 @@ type Type struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
sym *Sym // symbol containing name, for named types
|
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
|
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)
|
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 {
|
if x.sym != nil {
|
||||||
// Syms non-nil, if vargens match then equal.
|
// Syms non-nil, if vargens match then equal.
|
||||||
if t.Vargen != x.Vargen {
|
if t.vargen != x.vargen {
|
||||||
return cmpForNe(t.Vargen < x.Vargen)
|
return cmpForNe(t.vargen < x.vargen)
|
||||||
}
|
}
|
||||||
return CMPeq
|
return CMPeq
|
||||||
}
|
}
|
||||||
|
|
@ -1768,6 +1768,25 @@ func (t *Type) Obj() Object {
|
||||||
return nil
|
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
|
// SetUnderlying sets the underlying type. SetUnderlying automatically updates any
|
||||||
// types that were waiting for this type to be completed.
|
// types that were waiting for this type to be completed.
|
||||||
func (t *Type) SetUnderlying(underlying *Type) {
|
func (t *Type) SetUnderlying(underlying *Type) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue