fix(gnovm): use OpCall to run deferred statements #2597
+185
−208
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is an itch that started when noticing something reviewing #2145, and then continued when breaking down #1672, and here we are.
Essentially, currently on
master
usingdefer
will not create a new*Frame
. This results, in #2145, in the deferred function not showing up in the stacktrace.doOpReturnCallDefers
(the function in charge of executing deferred functions) actually has its own copied implementation of OpCall.I haven't been able to fully track down the implications of not creating a new frame (zrealm_std7_stdlibs.gno is an attempt at doing so, but is actually correct on master, so 🤷). But what I do know is that having two copied implementations leads to bug being fixed in one case, and not in another one: to prove this, see
defer10.gno
.defer10's case is fixed on OpCall, as a previous commit moved it from using
copy(b.Values, dfr.Args)
to usingb.Values[i] = pv.Copy(m.Alloc)
over all the values instead. (ie. copying values by reference when calling a function).So, by always using OpCall to do everything, we create the frame correctly, and use a unique implementation to actually call functions.
I also modified the logic to determine whether a
recover()
can correctly recover a panic or not. (cc @deelawn). Instead of keeping a Scope counter in the Machine, theException
now contains a slice of the frame pointers at the time of creation of the exception. The frame will be considered as being run during a panicking sequence only if it is in this array. We use this both for recover(), and for doOpReturnCallDefers, too.@deelawn I tried using your system, but I couldn't get it working on a case like
recover12b
, with the new frame added. And I'm still not 100% sure how the system you had worked. Do you think this is ok?