Skip to content

Commit 74421a3

Browse files
randall77gopherbot
authored andcommitted
Revert "cmd/compile: allow multi-field structs to be stored directly in interfaces"
This reverts commit cd55f86 (CL 681937) Reason for revert: still causing compiler failures on Google test code Change-Id: I5cd482fd607fd060a523257082d48821b5f965d6 Reviewed-on: https://go-review.googlesource.com/c/go/+/695016 Reviewed-by: Keith Randall <[email protected]> Auto-Submit: Keith Randall <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]>
1 parent c313591 commit 74421a3

File tree

7 files changed

+36
-33
lines changed

7 files changed

+36
-33
lines changed

src/cmd/compile/internal/ssa/_gen/generic.rules

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -921,8 +921,8 @@
921921
@x.Block (Load <v.Type> (OffPtr <v.Type.PtrTo()> [t.FieldOff(int(i))] ptr) mem)
922922

923923
// Putting struct{*byte} and similar into direct interfaces.
924-
(IMake _typ (StructMake val)) => imakeOfStructMake(v)
925-
(StructSelect [_] (IData x)) => (IData x)
924+
(IMake _typ (StructMake val)) => (IMake _typ val)
925+
(StructSelect [0] (IData x)) => (IData x)
926926

927927
// un-SSAable values use mem->mem copies
928928
(Store {t} dst (Load src mem) mem) && !CanSSA(t) =>

src/cmd/compile/internal/ssa/expand_calls.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -423,14 +423,7 @@ func (x *expandState) decomposeAsNecessary(pos src.XPos, b *Block, a, m0 *Value,
423423
if a.Op == OpIMake {
424424
data := a.Args[1]
425425
for data.Op == OpStructMake || data.Op == OpArrayMake1 {
426-
// A struct make might have a few zero-sized fields.
427-
// Use the pointer-y one we know is there.
428-
for _, a := range data.Args {
429-
if a.Type.Size() > 0 {
430-
data = a
431-
break
432-
}
433-
}
426+
data = data.Args[0]
434427
}
435428
return x.decomposeAsNecessary(pos, b, data, mem, rc.next(data.Type))
436429
}

src/cmd/compile/internal/ssa/rewrite.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2621,17 +2621,3 @@ func panicBoundsCToAux(p PanicBoundsC) Aux {
26212621
func panicBoundsCCToAux(p PanicBoundsCC) Aux {
26222622
return p
26232623
}
2624-
2625-
// When v is (IMake typ (StructMake ...)), convert to
2626-
// (IMake typ arg) where arg is the pointer-y argument to
2627-
// the StructMake (there must be exactly one).
2628-
func imakeOfStructMake(v *Value) *Value {
2629-
var arg *Value
2630-
for _, a := range v.Args[1].Args {
2631-
if a.Type.Size() > 0 {
2632-
arg = a
2633-
break
2634-
}
2635-
}
2636-
return v.Block.NewValue2(v.Pos, OpIMake, v.Type, v.Args[0], arg)
2637-
}

src/cmd/compile/internal/ssa/rewritegeneric.go

Lines changed: 7 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cmd/compile/internal/types/type.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1822,7 +1822,26 @@ func IsReflexive(t *Type) bool {
18221822
// Can this type be stored directly in an interface word?
18231823
// Yes, if the representation is a single pointer.
18241824
func IsDirectIface(t *Type) bool {
1825-
return t.Size() == int64(PtrSize) && PtrDataSize(t) == int64(PtrSize)
1825+
switch t.Kind() {
1826+
case TPTR:
1827+
// Pointers to notinheap types must be stored indirectly. See issue 42076.
1828+
return !t.Elem().NotInHeap()
1829+
case TCHAN,
1830+
TMAP,
1831+
TFUNC,
1832+
TUNSAFEPTR:
1833+
return true
1834+
1835+
case TARRAY:
1836+
// Array of 1 direct iface type can be direct.
1837+
return t.NumElem() == 1 && IsDirectIface(t.Elem())
1838+
1839+
case TSTRUCT:
1840+
// Struct with 1 field of direct iface type can be direct.
1841+
return t.NumFields() == 1 && IsDirectIface(t.Field(0).Type)
1842+
}
1843+
1844+
return false
18261845
}
18271846

18281847
// IsInterfaceMethod reports whether (field) m is

src/internal/abi/type.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ const (
121121
TFlagGCMaskOnDemand TFlag = 1 << 4
122122

123123
// TFlagDirectIface means that a value of this type is stored directly
124-
// in the data field of an interface, instead of indirectly.
125-
// This flag is just a cached computation of Size_ == PtrBytes == goarch.PtrSize.
124+
// in the data field of an interface, instead of indirectly. Normally
125+
// this means the type is pointer-ish.
126126
TFlagDirectIface TFlag = 1 << 5
127127

128128
// Leaving this breadcrumb behind for dlv. It should not be used, and no

src/reflect/type.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2524,7 +2524,8 @@ func StructOf(fields []StructField) Type {
25242524
}
25252525

25262526
switch {
2527-
case typ.Size_ == goarch.PtrSize && typ.PtrBytes == goarch.PtrSize:
2527+
case len(fs) == 1 && fs[0].Typ.IsDirectIface():
2528+
// structs of 1 direct iface type can be direct
25282529
typ.TFlag |= abi.TFlagDirectIface
25292530
default:
25302531
typ.TFlag &^= abi.TFlagDirectIface
@@ -2693,7 +2694,8 @@ func ArrayOf(length int, elem Type) Type {
26932694
}
26942695

26952696
switch {
2696-
case array.Size_ == goarch.PtrSize && array.PtrBytes == goarch.PtrSize:
2697+
case length == 1 && typ.IsDirectIface():
2698+
// array of 1 direct iface type can be direct
26972699
array.TFlag |= abi.TFlagDirectIface
26982700
default:
26992701
array.TFlag &^= abi.TFlagDirectIface

0 commit comments

Comments
 (0)