Commit 0e94d3209d for golang
commit 0e94d3209db123ebdfb41798a2ca608994aca8ee
Author: Austin Clements <austin@google.com>
Date: Tue Dec 1 13:22:01 2026 -0500
internal/abi: add UncommonType.Flags
Use 16 bits of pre-existing padding in UncommonType to add a new Flags
field, of the new type UFlag, to record rare properties of types that
don't merit one of the few remaining TFlag bits. Add Type.UFlags to
read it. No flags are defined yet.
The padding is a uint32 added in CL 24070, when Moff grew to 32 bits.
It keeps the size of UncommonType a multiple of 8, which is necessary
because the type-dependent data that can follow it contains pointers.
This keeps the remaining 16 bits as padding, so the size and alignment
of UncommonType don't change.
Change-Id: I8520ee39e2128871a44f5a179f55cb2a6a6a6964
Reviewed-on: https://go-review.googlesource.com/c/go/+/868842
Auto-Submit: Austin Clements <austin@google.com>
Reviewed-by: Junyang Shao <shaojunyang@google.com>
LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
diff --git a/src/cmd/compile/internal/reflectdata/reflect.go b/src/cmd/compile/internal/reflectdata/reflect.go
index 238a7e2d3b..1e10131b86 100644
--- a/src/cmd/compile/internal/reflectdata/reflect.go
+++ b/src/cmd/compile/internal/reflectdata/reflect.go
@@ -345,7 +345,8 @@ func dextratype(lsym *obj.LSym, off int64, t *types.Type, dataAdd int) {
c.Field("Mcount").WriteUint16(uint16(mcount))
c.Field("Xcount").WriteUint16(uint16(xcount))
c.Field("Moff").WriteUint32(uint32(dataAdd))
- // Note: there is an unused uint32 field here.
+ // Note: no UFlags are defined yet, so Flags uint16 is left zero.
+ // Note: there is an unused uint16 of padding here.
// Write the backing array for the []method field.
array := rttype.NewArrayCursor(lsym, off+int64(dataAdd), rttype.Method, mcount)
diff --git a/src/internal/abi/compiletype.go b/src/internal/abi/compiletype.go
index 517d67fb7b..bf52faf2e1 100644
--- a/src/internal/abi/compiletype.go
+++ b/src/internal/abi/compiletype.go
@@ -19,7 +19,7 @@ func StructFieldSize(ptrSize int) int { return 3 * ptrSize }
// UncommonSize returns sizeof(UncommonType). This currently does not depend on ptrSize.
// This exported function is in an internal package, so it may change to depend on ptrSize in the future.
-func UncommonSize() uint64 { return 4 + 2 + 2 + 4 + 4 }
+func UncommonSize() uint64 { return 4 + 2 + 2 + 4 + 2 + 2 }
// TFlagOff returns the offset of Type.TFlag for a compilation target with a given ptrSize
func TFlagOff(ptrSize int) int { return 2*ptrSize + 4 }
diff --git a/src/internal/abi/type.go b/src/internal/abi/type.go
index e125e67e37..6a0bcd4f9c 100644
--- a/src/internal/abi/type.go
+++ b/src/internal/abi/type.go
@@ -232,9 +232,19 @@ type UncommonType struct {
Mcount uint16 // number of methods
Xcount uint16 // number of exported methods
Moff uint32 // offset from this uncommontype to [mcount]Method
- _ uint32 // unused
+ Flags UFlag // flags for rare properties of the type
+
+ // Padding: the type-dependent data that may follow an UncommonType
+ // (see cmd/compile/internal/reflectdata.writeType) can contain
+ // pointers, so the size of UncommonType must be a multiple of 8.
+ _ uint16
}
+// UFlag is used by an UncommonType to record rare properties of a type, which
+// don't merit one of the scarce TFlag bits. Only a type with an UncommonType
+// can have these properties.
+type UFlag uint16
+
func (t *UncommonType) Methods() []Method {
if t.Mcount == 0 {
return nil
@@ -375,6 +385,14 @@ func (t *Type) Uncommon() *UncommonType {
}
}
+// UFlags returns the flags in t's "uncommon" data, or 0 if there is none.
+func (t *Type) UFlags() UFlag {
+ if u := t.Uncommon(); u != nil {
+ return u.Flags
+ }
+ return 0
+}
+
// Elem returns the element type for t if t is an array, channel, map, pointer, or slice, otherwise nil.
func (t *Type) Elem() *Type {
switch t.Kind() {