You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
cmd/compile: generate closure for go/defer builtin calls #19710
The defer statement is supposed to freeze its arguments the instant it is evaluated, but it does not when used with delete. Compare to this program, which works correctly:
@mattn I have a map that I occasionally add temporary values to (for intermediate computations). I was trying to use defer+delete to remove those temporary entries automatically.
Bad news is this has been broken forever. (I tested Go 1.5, Go 1.6, Go 1.7, and Go 1.8) Because it's not a regression and has been broken forever, it doesn't qualify for a Go 1.8.1 cherry-pick.
Good news is that it's fixed at tip (what will be Go 1.9).
I haven't bisected to see where it was fixed and whether it was intentional. If it was fixed by accident, it likely still lacks a test.
Probably fixed by the order.go changes for mapdelete_fast*. Yes, needs a test. Should double-check go delete(x), and defer/delete of the other built-in functions.
order.go, walk.go, and ssa.go are scattered with special handling of go/defer of built-in functions. I wonder whether instead we should just do a very early rewrite of
deferbuiltin(a, b, c)
to
deferfunc(atypa, btypb, ctypc) {
builtin(a, b, c)
}(a, b, c)
That would probably also simplify instrumentation of such cases, which are also the topic of scattered special handling.
I think we should add a test for 1.9 and and leave the closurization of deferred built-ins for 1.10. (That will also enable us to simplify other things, like not lowering OPANIC in walk.go.)
Note to self: walkprintfunc does this now for defer println(...). It also has a minor naming bug: lookupN("print·%d", walkprintfunc_prgen) generates names like "".print·%d1·f. :P
Activity
deal with Go defer bug
deal with Go defer bug
mattn commentedon Mar 25, 2017
This is my interesting. Why you use defer delete?
unixpickle commentedon Mar 25, 2017
@mattn I have a map that I occasionally add temporary values to (for intermediate computations). I was trying to use defer+delete to remove those temporary entries automatically.
bradfitz commentedon Mar 25, 2017
Good news and bad news:
Bad news is this has been broken forever. (I tested Go 1.5, Go 1.6, Go 1.7, and Go 1.8) Because it's not a regression and has been broken forever, it doesn't qualify for a Go 1.8.1 cherry-pick.
Good news is that it's fixed at tip (what will be Go 1.9).
I haven't bisected to see where it was fixed and whether it was intentional. If it was fixed by accident, it likely still lacks a test.
/cc @griesemer @randall77 @mdempsky @josharian
[-]defer+delete argument bug[/-][+]cmd/compile: defer+delete argument bug[/+]josharian commentedon Mar 25, 2017
Probably fixed by the order.go changes for mapdelete_fast*. Yes, needs a test. Should double-check go delete(x), and defer/delete of the other built-in functions.
cespare commentedon Mar 25, 2017
A bisect points at 5d6b7fc (CL 38172)
josharian commentedon Mar 25, 2017
order.go, walk.go, and ssa.go are scattered with special handling of go/defer of built-in functions. I wonder whether instead we should just do a very early rewrite of
to
That would probably also simplify instrumentation of such cases, which are also the topic of scattered special handling.
randall77 commentedon Mar 25, 2017
@josharian I was thinking the same thing.
josharian commentedon May 15, 2017
I think we should add a test for 1.9 and and leave the closurization of deferred built-ins for 1.10. (That will also enable us to simplify other things, like not lowering OPANIC in walk.go.)
I'll send a test CL.
gopherbot commentedon May 15, 2017
CL https://golang.org/cl/43497 mentions this issue.
1 remaining item
josharian commentedon May 19, 2017
Note to self: walkprintfunc does this now for
defer println(...). It also has a minor naming bug:lookupN("print·%d", walkprintfunc_prgen)generates names like"".print·%d1·f. :P[-]cmd/compile: defer+delete argument bug[/-][+]cmd/compile: generate closure for go/defer builtin calls[/+]cuonglm commentedon Oct 22, 2020
This is fixed at tip, we can close this now cc @mdempsky