Skip to content

Commit 884e75f

Browse files
hopehookodeke-em
authored andcommitted
reflect: fix the collision of variable name and package name
The return value "abi" of func "funcLayout" is the same as package "internal/abi", which currently works fine, but it is more reliable to avoid conflicts. Change-Id: I83715dd79beff7cb3fc25747fef186dc0e2dfa8b Reviewed-on: https://go-review.googlesource.com/c/go/+/385414 Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Reviewed-by: Emmanuel Odeke <[email protected]>
1 parent a92ca51 commit 884e75f

File tree

3 files changed

+30
-30
lines changed

3 files changed

+30
-30
lines changed

src/reflect/makefunc.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ func MakeFunc(typ Type, fn func(args []Value) (results []Value)) Value {
5454
code := abi.FuncPCABI0(makeFuncStub)
5555

5656
// makeFuncImpl contains a stack map for use by the runtime
57-
_, _, abi := funcLayout(ftyp, nil)
57+
_, _, abid := funcLayout(ftyp, nil)
5858

5959
impl := &makeFuncImpl{
6060
makeFuncCtxt: makeFuncCtxt{
6161
fn: code,
62-
stack: abi.stackPtrs,
63-
argLen: abi.stackCallArgsSize,
64-
regPtrs: abi.inRegPtrs,
62+
stack: abid.stackPtrs,
63+
argLen: abid.stackCallArgsSize,
64+
regPtrs: abid.inRegPtrs,
6565
},
6666
ftyp: ftyp,
6767
fn: fn,
@@ -109,13 +109,13 @@ func makeMethodValue(op string, v Value) Value {
109109
code := methodValueCallCodePtr()
110110

111111
// methodValue contains a stack map for use by the runtime
112-
_, _, abi := funcLayout(ftyp, nil)
112+
_, _, abid := funcLayout(ftyp, nil)
113113
fv := &methodValue{
114114
makeFuncCtxt: makeFuncCtxt{
115115
fn: code,
116-
stack: abi.stackPtrs,
117-
argLen: abi.stackCallArgsSize,
118-
regPtrs: abi.inRegPtrs,
116+
stack: abid.stackPtrs,
117+
argLen: abid.stackCallArgsSize,
118+
regPtrs: abid.inRegPtrs,
119119
},
120120
method: int(v.flag) >> flagMethodShift,
121121
rcvr: rcvr,

src/reflect/type.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3051,7 +3051,7 @@ type layoutKey struct {
30513051
type layoutType struct {
30523052
t *rtype
30533053
framePool *sync.Pool
3054-
abi abiDesc
3054+
abid abiDesc
30553055
}
30563056

30573057
var layoutCache sync.Map // map[layoutKey]layoutType
@@ -3063,7 +3063,7 @@ var layoutCache sync.Map // map[layoutKey]layoutType
30633063
// The returned type exists only for GC, so we only fill out GC relevant info.
30643064
// Currently, that's just size and the GC program. We also fill in
30653065
// the name for possible debugging use.
3066-
func funcLayout(t *funcType, rcvr *rtype) (frametype *rtype, framePool *sync.Pool, abi abiDesc) {
3066+
func funcLayout(t *funcType, rcvr *rtype) (frametype *rtype, framePool *sync.Pool, abid abiDesc) {
30673067
if t.Kind() != Func {
30683068
panic("reflect: funcLayout of non-func type " + t.String())
30693069
}
@@ -3073,11 +3073,11 @@ func funcLayout(t *funcType, rcvr *rtype) (frametype *rtype, framePool *sync.Poo
30733073
k := layoutKey{t, rcvr}
30743074
if lti, ok := layoutCache.Load(k); ok {
30753075
lt := lti.(layoutType)
3076-
return lt.t, lt.framePool, lt.abi
3076+
return lt.t, lt.framePool, lt.abid
30773077
}
30783078

30793079
// Compute the ABI layout.
3080-
abi = newAbiDesc(t, rcvr)
3080+
abid = newAbiDesc(t, rcvr)
30813081

30823082
// build dummy rtype holding gc program
30833083
x := &rtype{
@@ -3086,11 +3086,11 @@ func funcLayout(t *funcType, rcvr *rtype) (frametype *rtype, framePool *sync.Poo
30863086
// reflectcall's frame, not in the allocated frame.
30873087
// TODO(mknyszek): Remove this comment when register
30883088
// spill space in the frame is no longer required.
3089-
size: align(abi.retOffset+abi.ret.stackBytes, goarch.PtrSize),
3090-
ptrdata: uintptr(abi.stackPtrs.n) * goarch.PtrSize,
3089+
size: align(abid.retOffset+abid.ret.stackBytes, goarch.PtrSize),
3090+
ptrdata: uintptr(abid.stackPtrs.n) * goarch.PtrSize,
30913091
}
3092-
if abi.stackPtrs.n > 0 {
3093-
x.gcdata = &abi.stackPtrs.data[0]
3092+
if abid.stackPtrs.n > 0 {
3093+
x.gcdata = &abid.stackPtrs.data[0]
30943094
}
30953095

30963096
var s string
@@ -3108,10 +3108,10 @@ func funcLayout(t *funcType, rcvr *rtype) (frametype *rtype, framePool *sync.Poo
31083108
lti, _ := layoutCache.LoadOrStore(k, layoutType{
31093109
t: x,
31103110
framePool: framePool,
3111-
abi: abi,
3111+
abid: abid,
31123112
})
31133113
lt := lti.(layoutType)
3114-
return lt.t, lt.framePool, lt.abi
3114+
return lt.t, lt.framePool, lt.abid
31153115
}
31163116

31173117
// ifaceIndir reports whether t is stored indirectly in an interface value.

src/reflect/value.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ func (v Value) call(op string, in []Value) []Value {
453453
var regArgs abi.RegArgs
454454

455455
// Compute frame type.
456-
frametype, framePool, abi := funcLayout(t, rcvrtype)
456+
frametype, framePool, abid := funcLayout(t, rcvrtype)
457457

458458
// Allocate a chunk of memory for frame if needed.
459459
var stackArgs unsafe.Pointer
@@ -470,7 +470,7 @@ func (v Value) call(op string, in []Value) []Value {
470470

471471
if debugReflectCall {
472472
println("reflect.call", t.String())
473-
abi.dump()
473+
abid.dump()
474474
}
475475

476476
// Copy inputs into args.
@@ -481,7 +481,7 @@ func (v Value) call(op string, in []Value) []Value {
481481
// Guaranteed to only be one word in size,
482482
// so it will only take up exactly 1 abiStep (either
483483
// in a register or on the stack).
484-
switch st := abi.call.steps[0]; st.kind {
484+
switch st := abid.call.steps[0]; st.kind {
485485
case abiStepStack:
486486
storeRcvr(rcvr, stackArgs)
487487
case abiStepIntReg, abiStepPointer:
@@ -507,7 +507,7 @@ func (v Value) call(op string, in []Value) []Value {
507507
// was possible to use space in the argument frame.
508508
v = v.assignTo("reflect.Value.Call", targ, nil)
509509
stepsLoop:
510-
for _, st := range abi.call.stepsForValue(i + inStart) {
510+
for _, st := range abid.call.stepsForValue(i + inStart) {
511511
switch st.kind {
512512
case abiStepStack:
513513
// Copy values to the "stack."
@@ -552,10 +552,10 @@ func (v Value) call(op string, in []Value) []Value {
552552
// TODO(mknyszek): Remove this when we no longer have
553553
// caller reserved spill space.
554554
frameSize = align(frameSize, goarch.PtrSize)
555-
frameSize += abi.spill
555+
frameSize += abid.spill
556556

557557
// Mark pointers in registers for the return path.
558-
regArgs.ReturnIsPtr = abi.outRegPtrs
558+
regArgs.ReturnIsPtr = abid.outRegPtrs
559559

560560
if debugReflectCall {
561561
regArgs.Dump()
@@ -567,7 +567,7 @@ func (v Value) call(op string, in []Value) []Value {
567567
}
568568

569569
// Call.
570-
call(frametype, fn, stackArgs, uint32(frametype.size), uint32(abi.retOffset), uint32(frameSize), &regArgs)
570+
call(frametype, fn, stackArgs, uint32(frametype.size), uint32(abid.retOffset), uint32(frameSize), &regArgs)
571571

572572
// For testing; see TestCallMethodJump.
573573
if callGC {
@@ -585,7 +585,7 @@ func (v Value) call(op string, in []Value) []Value {
585585
// Zero the now unused input area of args,
586586
// because the Values returned by this function contain pointers to the args object,
587587
// and will thus keep the args object alive indefinitely.
588-
typedmemclrpartial(frametype, stackArgs, 0, abi.retOffset)
588+
typedmemclrpartial(frametype, stackArgs, 0, abid.retOffset)
589589
}
590590

591591
// Wrap Values around return values in args.
@@ -598,7 +598,7 @@ func (v Value) call(op string, in []Value) []Value {
598598
ret[i] = Zero(tv)
599599
continue
600600
}
601-
steps := abi.ret.stepsForValue(i)
601+
steps := abid.ret.stepsForValue(i)
602602
if st := steps[0]; st.kind == abiStepStack {
603603
// This value is on the stack. If part of a value is stack
604604
// allocated, the entire value is according to the ABI. So
@@ -690,7 +690,7 @@ func callReflect(ctxt *makeFuncImpl, frame unsafe.Pointer, retValid *bool, regs
690690
ftyp := ctxt.ftyp
691691
f := ctxt.fn
692692

693-
_, _, abi := funcLayout(ftyp, nil)
693+
_, _, abid := funcLayout(ftyp, nil)
694694

695695
// Copy arguments into Values.
696696
ptr := frame
@@ -701,7 +701,7 @@ func callReflect(ctxt *makeFuncImpl, frame unsafe.Pointer, retValid *bool, regs
701701
continue
702702
}
703703
v := Value{typ, nil, flag(typ.Kind())}
704-
steps := abi.call.stepsForValue(i)
704+
steps := abid.call.stepsForValue(i)
705705
if st := steps[0]; st.kind == abiStepStack {
706706
if ifaceIndir(typ) {
707707
// value cannot be inlined in interface data.
@@ -791,7 +791,7 @@ func callReflect(ctxt *makeFuncImpl, frame unsafe.Pointer, retValid *bool, regs
791791
// target location used as scratch space. See issue 39541.
792792
v = v.assignTo("reflect.MakeFunc", typ, nil)
793793
stepsLoop:
794-
for _, st := range abi.ret.stepsForValue(i) {
794+
for _, st := range abid.ret.stepsForValue(i) {
795795
switch st.kind {
796796
case abiStepStack:
797797
// Copy values to the "stack."

0 commit comments

Comments
 (0)