diff options
author | Alon Zakai <azakai@google.com> | 2022-01-28 12:57:32 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-28 12:57:32 -0800 |
commit | f2d53918155cfe6e7fc333be22f25ae3776b1438 (patch) | |
tree | e7b10cd0def3481928702e83e0f6813a29796fc3 /test/lit/exec | |
parent | 43844d4bf34646aab0a1d575ad815a42e37dfc08 (diff) | |
download | binaryen-f2d53918155cfe6e7fc333be22f25ae3776b1438.tar.gz binaryen-f2d53918155cfe6e7fc333be22f25ae3776b1438.tar.bz2 binaryen-f2d53918155cfe6e7fc333be22f25ae3776b1438.zip |
[NFC] Refactor ModuleInstanceBase+RuntimeExpressionRunner into a single class (#4479)
As recently discussed, the interpreter code is way too complex. Trying to add
ctor-eval stuff I need, I got stuck and ended up spending some time to get rid
of some of the complexity.
We had a ModuleInstanceBase class which was basically an instance of a
module, that is, an execution of it. And internally we have RuntimeExpressionRunner
which is a runner that integrates with the ModuleInstanceBase - basically, it uses
the runtime info to execute code. For example, the MIB has globals info, and the
RER would read it from there.
But these two classes are really just one functionality - an execution of a module.
We get rid of some complexity by removing the separation between them, ending
up with a class that can run a module.
One set of problems we avoid is that we can now extend the single class in a
simple way. Before, we would need to extend both - and inform each other of
those changes. That gets "fun" with CRTP which we use everywhere. In other
words, each of the two classes depended on the other / would need to be
templated on the other. Specifically, MIB.callFunction would need to be given
the RER to run with, and so that would need to be templated on it. This ends up
leading to a bunch more templating all around - all complexity that we just
don't need. See the simplification to the wasm-ctor-eval for some of that (and
even worse complexity would have been needed without this PR in the next
steps for that tool to eval GC stuff).
The final single class is now called ModuleRunner.
Also fixes a pre-existing issue uncovered by this PR. We had the delegate
target on the runner, but it should be tied to a function scope. This happened
to not be a problem if one always created a new runner for each scope, but
this PR makes the runner longer-lived, so the stale data ended up mattering.
The PR moves that data to the proper place.
Note: Diff without whitespace is far, far smaller.
Diffstat (limited to 'test/lit/exec')
-rw-r--r-- | test/lit/exec/delegate-vacuum.wast | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/test/lit/exec/delegate-vacuum.wast b/test/lit/exec/delegate-vacuum.wast new file mode 100644 index 000000000..c92760568 --- /dev/null +++ b/test/lit/exec/delegate-vacuum.wast @@ -0,0 +1,60 @@ +;; NOTE: Assertions have been generated by update_lit_checks.py --output=fuzz-exec and should not be edited. + +;; RUN: wasm-opt %s --vacuum --fuzz-exec -all -q -o /dev/null 2>&1 | filecheck %s +;; Test the effect of vaccum on delegation. The delegate target must not +;; "escape" the current function scope and affect anything external, that is, +;; it must be cleared on function exit. + +(module + (tag $tag$0 (param i32)) + ;; CHECK: [fuzz-exec] calling export-1 + ;; CHECK-NEXT: [exception thrown: tag$0 0] + (func "export-1" + (try + (do + (try + (do + (throw $tag$0 + (i32.const 0) + ) + ) + ;; A delegation that leads to the caller. This sets the delegate field on + ;; this function scope. + (delegate 1) + ) + ) + (catch_all + (nop) + ) + ) + ) + ;; CHECK: [fuzz-exec] calling export-2 + ;; CHECK-NEXT: [trap unreachable] + (func "export-2" + (call $inner) + (unreachable) + ) + (func $inner + ;; This inner function must not notice the delegate field that was set by + ;; the call to the previous export (if it does notice it, it would delegate + ;; to the caller or something else invalid, and the execution results would + ;; differ, causing fuzz-exec to fail). + (try + (do + (throw $tag$0 + (i32.const 0) + ) + ) + (catch_all + (nop) + ) + ) + ) +) +;; CHECK: [fuzz-exec] calling export-1 +;; CHECK-NEXT: [exception thrown: tag$0 0] + +;; CHECK: [fuzz-exec] calling export-2 +;; CHECK-NEXT: [trap unreachable] +;; CHECK-NEXT: [fuzz-exec] comparing export-1 +;; CHECK-NEXT: [fuzz-exec] comparing export-2 |