reflect: remove redundent ifaceIndir

Use abi.(*Type).IfaceIndir instead.

Change-Id: I31197cbf0edaf53bbb0455fa76d2a4a2ab40b420
GitHub-Last-Rev: 2659b696ef3680e13e22bdf6a63e5d82b7b1ecdf
GitHub-Pull-Request: golang/go#67227
Reviewed-on: https://go-review.googlesource.com/c/go/+/583755
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Keith Randall <khr@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
apocelipes 2024-05-07 13:25:16 +00:00 committed by Gopher Robot
parent c637d4b939
commit 55a06f7920
3 changed files with 10 additions and 15 deletions

View File

@ -166,7 +166,7 @@ func (a *abiSeq) addRcvr(rcvr *abi.Type) (*abiStep, bool) {
// The receiver is always one word. // The receiver is always one word.
a.valueStart = append(a.valueStart, len(a.steps)) a.valueStart = append(a.valueStart, len(a.steps))
var ok, ptr bool var ok, ptr bool
if ifaceIndir(rcvr) || rcvr.Pointers() { if rcvr.IfaceIndir() || rcvr.Pointers() {
ok = a.assignIntN(0, goarch.PtrSize, 1, 0b1) ok = a.assignIntN(0, goarch.PtrSize, 1, 0b1)
ptr = true ptr = true
} else { } else {

View File

@ -2606,7 +2606,7 @@ func StructOf(fields []StructField) Type {
} }
switch { switch {
case len(fs) == 1 && !ifaceIndir(fs[0].Typ): case len(fs) == 1 && !fs[0].Typ.IfaceIndir():
// structs of 1 direct iface type can be direct // structs of 1 direct iface type can be direct
typ.Kind_ |= abi.KindDirectIface typ.Kind_ |= abi.KindDirectIface
default: default:
@ -2801,7 +2801,7 @@ func ArrayOf(length int, elem Type) Type {
} }
switch { switch {
case length == 1 && !ifaceIndir(typ): case length == 1 && !typ.IfaceIndir():
// array of 1 direct iface type can be direct // array of 1 direct iface type can be direct
array.Kind_ |= abi.KindDirectIface array.Kind_ |= abi.KindDirectIface
default: default:
@ -2903,11 +2903,6 @@ func funcLayout(t *funcType, rcvr *abi.Type) (frametype *abi.Type, framePool *sy
return lt.t, lt.framePool, lt.abid return lt.t, lt.framePool, lt.abid
} }
// ifaceIndir reports whether t is stored indirectly in an interface value.
func ifaceIndir(t *abi.Type) bool {
return t.Kind_&abi.KindDirectIface == 0
}
// Note: this type must agree with runtime.bitvector. // Note: this type must agree with runtime.bitvector.
type bitVector struct { type bitVector struct {
n uint32 // number of bits n uint32 // number of bits

View File

@ -624,7 +624,7 @@ func (v Value) call(op string, in []Value) []Value {
} }
// Handle pointers passed in registers. // Handle pointers passed in registers.
if !ifaceIndir(tv) { if !tv.IfaceIndir() {
// Pointer-valued data gets put directly // Pointer-valued data gets put directly
// into v.ptr. // into v.ptr.
if steps[0].kind != abiStepPointer { if steps[0].kind != abiStepPointer {
@ -714,7 +714,7 @@ func callReflect(ctxt *makeFuncImpl, frame unsafe.Pointer, retValid *bool, regs
v := Value{typ, nil, flag(typ.Kind())} v := Value{typ, nil, flag(typ.Kind())}
steps := abid.call.stepsForValue(i) steps := abid.call.stepsForValue(i)
if st := steps[0]; st.kind == abiStepStack { if st := steps[0]; st.kind == abiStepStack {
if ifaceIndir(typ) { if typ.IfaceIndir() {
// value cannot be inlined in interface data. // value cannot be inlined in interface data.
// Must make a copy, because f might keep a reference to it, // Must make a copy, because f might keep a reference to it,
// and we cannot let f keep a reference to the stack frame // and we cannot let f keep a reference to the stack frame
@ -728,7 +728,7 @@ func callReflect(ctxt *makeFuncImpl, frame unsafe.Pointer, retValid *bool, regs
v.ptr = *(*unsafe.Pointer)(add(ptr, st.stkOff, "1-ptr")) v.ptr = *(*unsafe.Pointer)(add(ptr, st.stkOff, "1-ptr"))
} }
} else { } else {
if ifaceIndir(typ) { if typ.IfaceIndir() {
// All that's left is values passed in registers that we need to // All that's left is values passed in registers that we need to
// create space for the values. // create space for the values.
v.flag |= flagIndir v.flag |= flagIndir
@ -914,7 +914,7 @@ func storeRcvr(v Value, p unsafe.Pointer) {
// the interface data word becomes the receiver word // the interface data word becomes the receiver word
iface := (*nonEmptyInterface)(v.ptr) iface := (*nonEmptyInterface)(v.ptr)
*(*unsafe.Pointer)(p) = iface.word *(*unsafe.Pointer)(p) = iface.word
} else if v.flag&flagIndir != 0 && !ifaceIndir(t) { } else if v.flag&flagIndir != 0 && !t.IfaceIndir() {
*(*unsafe.Pointer)(p) = *(*unsafe.Pointer)(v.ptr) *(*unsafe.Pointer)(p) = *(*unsafe.Pointer)(v.ptr)
} else { } else {
*(*unsafe.Pointer)(p) = v.ptr *(*unsafe.Pointer)(p) = v.ptr
@ -1232,7 +1232,7 @@ func (v Value) Elem() Value {
case Pointer: case Pointer:
ptr := v.ptr ptr := v.ptr
if v.flag&flagIndir != 0 { if v.flag&flagIndir != 0 {
if ifaceIndir(v.typ()) { if v.typ().IfaceIndir() {
// This is a pointer to a not-in-heap object. ptr points to a uintptr // This is a pointer to a not-in-heap object. ptr points to a uintptr
// in the heap. That uintptr is the address of a not-in-heap object. // in the heap. That uintptr is the address of a not-in-heap object.
// In general, pointers to not-in-heap objects can be total junk. // In general, pointers to not-in-heap objects can be total junk.
@ -2258,7 +2258,7 @@ func (v Value) recv(nb bool) (val Value, ok bool) {
t := tt.Elem t := tt.Elem
val = Value{t, nil, flag(t.Kind())} val = Value{t, nil, flag(t.Kind())}
var p unsafe.Pointer var p unsafe.Pointer
if ifaceIndir(t) { if t.IfaceIndir() {
p = unsafe_New(t) p = unsafe_New(t)
val.ptr = p val.ptr = p
val.flag |= flagIndir val.flag |= flagIndir
@ -3297,7 +3297,7 @@ func New(typ Type) Value {
} }
t := &typ.(*rtype).t t := &typ.(*rtype).t
pt := ptrTo(t) pt := ptrTo(t)
if ifaceIndir(pt) { if pt.IfaceIndir() {
// This is a pointer to a not-in-heap type. // This is a pointer to a not-in-heap type.
panic("reflect: New of type that may not be allocated in heap (possibly undefined cgo C type)") panic("reflect: New of type that may not be allocated in heap (possibly undefined cgo C type)")
} }