]> Cypherpunks repositories - gostls13.git/commitdiff
reflect: fix the collision of variable name and package name
authorhopehook <hopehook.com@gmail.com>
Sat, 12 Feb 2022 09:03:19 +0000 (17:03 +0800)
committerEmmanuel Odeke <emmanuel@orijtech.com>
Mon, 4 Apr 2022 04:04:18 +0000 (04:04 +0000)
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 <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
src/reflect/makefunc.go
src/reflect/type.go
src/reflect/value.go

index e4acdc318b0aca8459e1e03a70867135a5a9531e..3d9279ceaa64e7a60fab8591035b607e4d2ac08f 100644 (file)
@@ -54,14 +54,14 @@ func MakeFunc(typ Type, fn func(args []Value) (results []Value)) Value {
        code := abi.FuncPCABI0(makeFuncStub)
 
        // makeFuncImpl contains a stack map for use by the runtime
-       _, _, abi := funcLayout(ftyp, nil)
+       _, _, abid := funcLayout(ftyp, nil)
 
        impl := &makeFuncImpl{
                makeFuncCtxt: makeFuncCtxt{
                        fn:      code,
-                       stack:   abi.stackPtrs,
-                       argLen:  abi.stackCallArgsSize,
-                       regPtrs: abi.inRegPtrs,
+                       stack:   abid.stackPtrs,
+                       argLen:  abid.stackCallArgsSize,
+                       regPtrs: abid.inRegPtrs,
                },
                ftyp: ftyp,
                fn:   fn,
@@ -109,13 +109,13 @@ func makeMethodValue(op string, v Value) Value {
        code := methodValueCallCodePtr()
 
        // methodValue contains a stack map for use by the runtime
-       _, _, abi := funcLayout(ftyp, nil)
+       _, _, abid := funcLayout(ftyp, nil)
        fv := &methodValue{
                makeFuncCtxt: makeFuncCtxt{
                        fn:      code,
-                       stack:   abi.stackPtrs,
-                       argLen:  abi.stackCallArgsSize,
-                       regPtrs: abi.inRegPtrs,
+                       stack:   abid.stackPtrs,
+                       argLen:  abid.stackCallArgsSize,
+                       regPtrs: abid.inRegPtrs,
                },
                method: int(v.flag) >> flagMethodShift,
                rcvr:   rcvr,
index 9589e83dbdf49b76710609637af2e44fd43d8d91..209a7bae4d557f38b77a9b84c2dfcb21b30d7425 100644 (file)
@@ -3051,7 +3051,7 @@ type layoutKey struct {
 type layoutType struct {
        t         *rtype
        framePool *sync.Pool
-       abi       abiDesc
+       abid      abiDesc
 }
 
 var layoutCache sync.Map // map[layoutKey]layoutType
@@ -3063,7 +3063,7 @@ var layoutCache sync.Map // map[layoutKey]layoutType
 // The returned type exists only for GC, so we only fill out GC relevant info.
 // Currently, that's just size and the GC program. We also fill in
 // the name for possible debugging use.
-func funcLayout(t *funcType, rcvr *rtype) (frametype *rtype, framePool *sync.Pool, abi abiDesc) {
+func funcLayout(t *funcType, rcvr *rtype) (frametype *rtype, framePool *sync.Pool, abid abiDesc) {
        if t.Kind() != Func {
                panic("reflect: funcLayout of non-func type " + t.String())
        }
@@ -3073,11 +3073,11 @@ func funcLayout(t *funcType, rcvr *rtype) (frametype *rtype, framePool *sync.Poo
        k := layoutKey{t, rcvr}
        if lti, ok := layoutCache.Load(k); ok {
                lt := lti.(layoutType)
-               return lt.t, lt.framePool, lt.abi
+               return lt.t, lt.framePool, lt.abid
        }
 
        // Compute the ABI layout.
-       abi = newAbiDesc(t, rcvr)
+       abid = newAbiDesc(t, rcvr)
 
        // build dummy rtype holding gc program
        x := &rtype{
@@ -3086,11 +3086,11 @@ func funcLayout(t *funcType, rcvr *rtype) (frametype *rtype, framePool *sync.Poo
                // reflectcall's frame, not in the allocated frame.
                // TODO(mknyszek): Remove this comment when register
                // spill space in the frame is no longer required.
-               size:    align(abi.retOffset+abi.ret.stackBytes, goarch.PtrSize),
-               ptrdata: uintptr(abi.stackPtrs.n) * goarch.PtrSize,
+               size:    align(abid.retOffset+abid.ret.stackBytes, goarch.PtrSize),
+               ptrdata: uintptr(abid.stackPtrs.n) * goarch.PtrSize,
        }
-       if abi.stackPtrs.n > 0 {
-               x.gcdata = &abi.stackPtrs.data[0]
+       if abid.stackPtrs.n > 0 {
+               x.gcdata = &abid.stackPtrs.data[0]
        }
 
        var s string
@@ -3108,10 +3108,10 @@ func funcLayout(t *funcType, rcvr *rtype) (frametype *rtype, framePool *sync.Poo
        lti, _ := layoutCache.LoadOrStore(k, layoutType{
                t:         x,
                framePool: framePool,
-               abi:       abi,
+               abid:      abid,
        })
        lt := lti.(layoutType)
-       return lt.t, lt.framePool, lt.abi
+       return lt.t, lt.framePool, lt.abid
 }
 
 // ifaceIndir reports whether t is stored indirectly in an interface value.
index 7a20b6bd23f54055100a7800e509fe23969a2ca1..8410dfc30a6b3ca5906d8695a46062a03152651b 100644 (file)
@@ -453,7 +453,7 @@ func (v Value) call(op string, in []Value) []Value {
        var regArgs abi.RegArgs
 
        // Compute frame type.
-       frametype, framePool, abi := funcLayout(t, rcvrtype)
+       frametype, framePool, abid := funcLayout(t, rcvrtype)
 
        // Allocate a chunk of memory for frame if needed.
        var stackArgs unsafe.Pointer
@@ -470,7 +470,7 @@ func (v Value) call(op string, in []Value) []Value {
 
        if debugReflectCall {
                println("reflect.call", t.String())
-               abi.dump()
+               abid.dump()
        }
 
        // Copy inputs into args.
@@ -481,7 +481,7 @@ func (v Value) call(op string, in []Value) []Value {
                // Guaranteed to only be one word in size,
                // so it will only take up exactly 1 abiStep (either
                // in a register or on the stack).
-               switch st := abi.call.steps[0]; st.kind {
+               switch st := abid.call.steps[0]; st.kind {
                case abiStepStack:
                        storeRcvr(rcvr, stackArgs)
                case abiStepIntReg, abiStepPointer:
@@ -507,7 +507,7 @@ func (v Value) call(op string, in []Value) []Value {
                // was possible to use space in the argument frame.
                v = v.assignTo("reflect.Value.Call", targ, nil)
        stepsLoop:
-               for _, st := range abi.call.stepsForValue(i + inStart) {
+               for _, st := range abid.call.stepsForValue(i + inStart) {
                        switch st.kind {
                        case abiStepStack:
                                // Copy values to the "stack."
@@ -552,10 +552,10 @@ func (v Value) call(op string, in []Value) []Value {
        // TODO(mknyszek): Remove this when we no longer have
        // caller reserved spill space.
        frameSize = align(frameSize, goarch.PtrSize)
-       frameSize += abi.spill
+       frameSize += abid.spill
 
        // Mark pointers in registers for the return path.
-       regArgs.ReturnIsPtr = abi.outRegPtrs
+       regArgs.ReturnIsPtr = abid.outRegPtrs
 
        if debugReflectCall {
                regArgs.Dump()
@@ -567,7 +567,7 @@ func (v Value) call(op string, in []Value) []Value {
        }
 
        // Call.
-       call(frametype, fn, stackArgs, uint32(frametype.size), uint32(abi.retOffset), uint32(frameSize), &regArgs)
+       call(frametype, fn, stackArgs, uint32(frametype.size), uint32(abid.retOffset), uint32(frameSize), &regArgs)
 
        // For testing; see TestCallMethodJump.
        if callGC {
@@ -585,7 +585,7 @@ func (v Value) call(op string, in []Value) []Value {
                        // Zero the now unused input area of args,
                        // because the Values returned by this function contain pointers to the args object,
                        // and will thus keep the args object alive indefinitely.
-                       typedmemclrpartial(frametype, stackArgs, 0, abi.retOffset)
+                       typedmemclrpartial(frametype, stackArgs, 0, abid.retOffset)
                }
 
                // Wrap Values around return values in args.
@@ -598,7 +598,7 @@ func (v Value) call(op string, in []Value) []Value {
                                ret[i] = Zero(tv)
                                continue
                        }
-                       steps := abi.ret.stepsForValue(i)
+                       steps := abid.ret.stepsForValue(i)
                        if st := steps[0]; st.kind == abiStepStack {
                                // This value is on the stack. If part of a value is stack
                                // allocated, the entire value is according to the ABI. So
@@ -690,7 +690,7 @@ func callReflect(ctxt *makeFuncImpl, frame unsafe.Pointer, retValid *bool, regs
        ftyp := ctxt.ftyp
        f := ctxt.fn
 
-       _, _, abi := funcLayout(ftyp, nil)
+       _, _, abid := funcLayout(ftyp, nil)
 
        // Copy arguments into Values.
        ptr := frame
@@ -701,7 +701,7 @@ func callReflect(ctxt *makeFuncImpl, frame unsafe.Pointer, retValid *bool, regs
                        continue
                }
                v := Value{typ, nil, flag(typ.Kind())}
-               steps := abi.call.stepsForValue(i)
+               steps := abid.call.stepsForValue(i)
                if st := steps[0]; st.kind == abiStepStack {
                        if ifaceIndir(typ) {
                                // value cannot be inlined in interface data.
@@ -791,7 +791,7 @@ func callReflect(ctxt *makeFuncImpl, frame unsafe.Pointer, retValid *bool, regs
                        // target location used as scratch space. See issue 39541.
                        v = v.assignTo("reflect.MakeFunc", typ, nil)
                stepsLoop:
-                       for _, st := range abi.ret.stepsForValue(i) {
+                       for _, st := range abid.ret.stepsForValue(i) {
                                switch st.kind {
                                case abiStepStack:
                                        // Copy values to the "stack."