diff options
author | Alon Zakai <azakai@google.com> | 2022-11-30 15:43:03 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-30 23:43:03 +0000 |
commit | 73b0487709370895cb8f9ac08cb2014143278fd6 (patch) | |
tree | ad48da99895d30f0eeff91cadee83928052834f4 /test/unit/test_passes.py | |
parent | 4f6cb8e54aa073f15f7ce622ea25905283683d5f (diff) | |
download | binaryen-73b0487709370895cb8f9ac08cb2014143278fd6.tar.gz binaryen-73b0487709370895cb8f9ac08cb2014143278fd6.tar.bz2 binaryen-73b0487709370895cb8f9ac08cb2014143278fd6.zip |
[Wasm GC] Implement closed-world flag (#5303)
With this change we default to an open world, that is, we do the safe thing
by default: we no longer assume a closed world. Users that want a closed
world must pass --closed-world.
Atm we just do not run passes that assume a closed world. (We might later
refine them to find which types don't escape and only optimize those.) The
RemoveUnusedModuleElements is an exception in that the closed-world
flag influences one part of its operation, but not the rest.
Fixes #5292
Diffstat (limited to 'test/unit/test_passes.py')
-rw-r--r-- | test/unit/test_passes.py | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/test/unit/test_passes.py b/test/unit/test_passes.py new file mode 100644 index 000000000..2fe7f6263 --- /dev/null +++ b/test/unit/test_passes.py @@ -0,0 +1,49 @@ +import os +import re +import subprocess +from scripts.test import shared +from . import utils + + +class PassesTest(utils.BinaryenTestCase): + # Given some arguments, return the passes that were run. + def get_passes_run(self, args): + os.environ['BINARYEN_PASS_DEBUG'] = '1' + try: + hello_wat = self.input_path('hello_world.wat') + log = shared.run_process(shared.WASM_OPT + [hello_wat] + args, + stderr=subprocess.PIPE).stderr + print(log) + passes = re.findall(r'running pass: ([\w-]+)\.\.\.', log) + return passes + finally: + del os.environ['BINARYEN_PASS_DEBUG'] + + def test_O2(self): + args = ['-O2', '-all'] + for nominal in ['--nominal', False]: + for closed_world in ['--closed-world', False]: + curr_args = args[:] + if nominal: + curr_args.append(nominal) + if closed_world: + curr_args.append(closed_world) + passes = self.get_passes_run(curr_args) + + # dce always runs + self.assertIn('dce', passes) + + # some passes only run in closed world + CLOSED_WORLD_PASSES = [ + 'type-refining', + 'signature-pruning', + 'signature-refining', + 'gto', + 'cfp', + 'gsi', + ] + for pass_ in CLOSED_WORLD_PASSES: + if closed_world: + self.assertIn(pass_, passes) + else: + self.assertNotIn(pass_, passes) |