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) {
if base.EnableTrace && base.Flag.LowerT {
defer tracePrint("typecheckdeftype", n)(nil)
t := types.NewNamed(n)
if n.Curfn != nil {
- TypeGen++
- t.Vargen = TypeGen
+ t.SetVargen()
}
if n.Pragma()&ir.NotInHeap != 0 {
// 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)
+ if mode == fmtTypeID && t.vargen != 0 {
+ fmt.Fprintf(b, "·%d", t.vargen)
}
return
}
}
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)
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
}
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) {