mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
[dev.typeparams] runtime: make deferproc take a func() argument
Previously it takes a *funcval, as it can be any function types. Now it must be func(). Make it so. Change-Id: I04273047b024386f55dbbd5fbda4767cbee7ac93 Reviewed-on: https://go-review.googlesource.com/c/go/+/325918 Trust: Cherry Mui <cherryyz@google.com> Run-TryBot: Cherry Mui <cherryyz@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com>
This commit is contained in:
parent
8e5304f729
commit
83da32749c
4 changed files with 17 additions and 25 deletions
|
|
@ -381,12 +381,13 @@ func dumpgoroutine(gp *g) {
|
||||||
dumpint(uint64(uintptr(unsafe.Pointer(gp))))
|
dumpint(uint64(uintptr(unsafe.Pointer(gp))))
|
||||||
dumpint(uint64(d.sp))
|
dumpint(uint64(d.sp))
|
||||||
dumpint(uint64(d.pc))
|
dumpint(uint64(d.pc))
|
||||||
dumpint(uint64(uintptr(unsafe.Pointer(d.fn))))
|
fn := *(**funcval)(unsafe.Pointer(&d.fn))
|
||||||
if d.fn == nil {
|
dumpint(uint64(uintptr(unsafe.Pointer(fn))))
|
||||||
|
if fn == nil {
|
||||||
// d.fn can be nil for open-coded defers
|
// d.fn can be nil for open-coded defers
|
||||||
dumpint(uint64(0))
|
dumpint(uint64(0))
|
||||||
} else {
|
} else {
|
||||||
dumpint(uint64(uintptr(unsafe.Pointer(d.fn.fn))))
|
dumpint(uint64(uintptr(unsafe.Pointer(fn.fn))))
|
||||||
}
|
}
|
||||||
dumpint(uint64(uintptr(unsafe.Pointer(d.link))))
|
dumpint(uint64(uintptr(unsafe.Pointer(d.link))))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -227,7 +227,7 @@ func panicmemAddr(addr uintptr) {
|
||||||
// Create a new deferred function fn, which has no arguments and results.
|
// Create a new deferred function fn, which has no arguments and results.
|
||||||
// The compiler turns a defer statement into a call to this.
|
// The compiler turns a defer statement into a call to this.
|
||||||
//go:nosplit
|
//go:nosplit
|
||||||
func deferproc(fn *funcval) { // TODO: Make deferproc just take a func().
|
func deferproc(fn func()) {
|
||||||
gp := getg()
|
gp := getg()
|
||||||
if gp.m.curg != gp {
|
if gp.m.curg != gp {
|
||||||
// go code on the system stack can't defer
|
// go code on the system stack can't defer
|
||||||
|
|
@ -363,16 +363,6 @@ func testdefersizes() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// deferFunc returns d's deferred function. This is temporary while we
|
|
||||||
// support both modes of GOEXPERIMENT=regabidefer. Once we commit to
|
|
||||||
// that experiment, we should change the type of d.fn.
|
|
||||||
//go:nosplit
|
|
||||||
func deferFunc(d *_defer) func() {
|
|
||||||
var fn func()
|
|
||||||
*(**funcval)(unsafe.Pointer(&fn)) = d.fn
|
|
||||||
return fn
|
|
||||||
}
|
|
||||||
|
|
||||||
var deferType *_type // type of _defer struct
|
var deferType *_type // type of _defer struct
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
@ -555,7 +545,9 @@ func deferreturn() {
|
||||||
// called with a callback on an LR architecture and jmpdefer is on the
|
// called with a callback on an LR architecture and jmpdefer is on the
|
||||||
// stack, because the stack trace can be incorrect in that case - see
|
// stack, because the stack trace can be incorrect in that case - see
|
||||||
// issue #8153).
|
// issue #8153).
|
||||||
_ = fn.fn
|
if fn == nil {
|
||||||
|
fn()
|
||||||
|
}
|
||||||
jmpdefer(fn, argp)
|
jmpdefer(fn, argp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -619,7 +611,7 @@ func Goexit() {
|
||||||
} else {
|
} else {
|
||||||
// Save the pc/sp in deferCallSave(), so we can "recover" back to this
|
// Save the pc/sp in deferCallSave(), so we can "recover" back to this
|
||||||
// loop if necessary.
|
// loop if necessary.
|
||||||
deferCallSave(&p, deferFunc(d))
|
deferCallSave(&p, d.fn)
|
||||||
}
|
}
|
||||||
if p.aborted {
|
if p.aborted {
|
||||||
// We had a recursive panic in the defer d we started, and
|
// We had a recursive panic in the defer d we started, and
|
||||||
|
|
@ -824,12 +816,12 @@ func runOpenDeferFrame(gp *g, d *_defer) bool {
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
closure := *(**funcval)(unsafe.Pointer(d.varp - uintptr(closureOffset)))
|
closure := *(*func())(unsafe.Pointer(d.varp - uintptr(closureOffset)))
|
||||||
d.fn = closure
|
d.fn = closure
|
||||||
deferBits = deferBits &^ (1 << i)
|
deferBits = deferBits &^ (1 << i)
|
||||||
*(*uint8)(unsafe.Pointer(d.varp - uintptr(deferBitsOffset))) = deferBits
|
*(*uint8)(unsafe.Pointer(d.varp - uintptr(deferBitsOffset))) = deferBits
|
||||||
p := d._panic
|
p := d._panic
|
||||||
deferCallSave(p, deferFunc(d))
|
deferCallSave(p, d.fn)
|
||||||
if p != nil && p.aborted {
|
if p != nil && p.aborted {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
@ -950,8 +942,7 @@ func gopanic(e interface{}) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
p.argp = unsafe.Pointer(getargp())
|
p.argp = unsafe.Pointer(getargp())
|
||||||
fn := deferFunc(d)
|
d.fn()
|
||||||
fn()
|
|
||||||
}
|
}
|
||||||
p.argp = nil
|
p.argp = nil
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -956,7 +956,7 @@ type _defer struct {
|
||||||
openDefer bool
|
openDefer bool
|
||||||
sp uintptr // sp at time of defer
|
sp uintptr // sp at time of defer
|
||||||
pc uintptr // pc at time of defer
|
pc uintptr // pc at time of defer
|
||||||
fn *funcval // can be nil for open-coded defers
|
fn func() // can be nil for open-coded defers
|
||||||
_panic *_panic // panic that is running defer
|
_panic *_panic // panic that is running defer
|
||||||
link *_defer
|
link *_defer
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -177,7 +177,7 @@ func cgocallback(fn, frame, ctxt uintptr)
|
||||||
func gogo(buf *gobuf)
|
func gogo(buf *gobuf)
|
||||||
|
|
||||||
//go:noescape
|
//go:noescape
|
||||||
func jmpdefer(fv *funcval, argp uintptr)
|
func jmpdefer(fv func(), argp uintptr)
|
||||||
func asminit()
|
func asminit()
|
||||||
func setg(gg *g)
|
func setg(gg *g)
|
||||||
func breakpoint()
|
func breakpoint()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue