diff options
author | Alon Zakai <azakai@google.com> | 2021-07-02 08:29:38 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-02 08:29:38 -0700 |
commit | d2347ff02d807fc38559d5f436eabae694562dae (patch) | |
tree | 74a49461937212ab6c5b58b2af817c0195c03558 /test | |
parent | ea20225d793b6c743703ea04cd9bb46c07384853 (diff) | |
download | binaryen-d2347ff02d807fc38559d5f436eabae694562dae.tar.gz binaryen-d2347ff02d807fc38559d5f436eabae694562dae.tar.bz2 binaryen-d2347ff02d807fc38559d5f436eabae694562dae.zip |
Apply features from the commandline first (#3960)
As suggested in
https://github.com/WebAssembly/binaryen/pull/3955#issuecomment-871016647
This applies commandline features first. If the features section is present, and
disallows some of them, then we warn. Otherwise, the features can combine
(for example, a wasm may enable feature X because it has to use it, and a user
can simply add the flag for feature Y if they want the optimizer to try to use it;
both flags will then be enabled).
This is important because in some cases we need to know the features before
parsing the wasm, in the case that the wasm does not use the features section.
In particular, non-nullable GC locals have an effect during parsing. (Typed
function references also does, but we found a way to apply its effect all the time,
that is, always use the refined type, and that happened to not break the case
where the feature is disabled - but such a workaround is not possible with
non-nullable locals.)
To make this less error-prone, add a FeatureSet input as a parameter to
WasmBinaryBuilder. That is, when building a module, we must give it the
features to use while doing so.
This will unblock #3955 . That PR will also add a test for the actual usage
of a feature during loading (the test can only be added there, after that PR
unbreaks things).
Diffstat (limited to 'test')
-rw-r--r-- | test/unit/test_features.py | 26 |
1 files changed, 9 insertions, 17 deletions
diff --git a/test/unit/test_features.py b/test/unit/test_features.py index a05d4c9b8..79e6d4de0 100644 --- a/test/unit/test_features.py +++ b/test/unit/test_features.py @@ -353,27 +353,19 @@ class TargetFeaturesSectionTest(utils.BinaryenTestCase): '--enable-simd', '--enable-sign-ext', self.input_path('signext_target_feature.wasm')]) - def test_incompatible_features(self): + def test_superset_even_without_detect_features(self): + # It is ok to enable additional features past what is in the section, + # even without passing --detect-features (which is now a no-op). path = self.input_path('signext_target_feature.wasm') - p = shared.run_process( + shared.run_process( shared.WASM_OPT + ['--print', '--enable-simd', '-o', os.devnull, - path], - check=False, capture_output=True - ) - self.assertNotEqual(p.returncode, 0) - self.assertIn('Fatal: features section is not a subset of specified features. ' + - 'Use --detect-features to resolve.', - p.stderr) + path]) - def test_incompatible_features_forced(self): + def test_superset_with_detect_features(self): path = self.input_path('signext_target_feature.wasm') - p = shared.run_process( - shared.WASM_OPT + ['--print', '--detect-features', '-mvp', - '--enable-simd', '-o', os.devnull, path], - check=False, capture_output=True - ) - self.assertNotEqual(p.returncode, 0) - self.assertIn('all used features should be allowed', p.stderr) + shared.run_process( + shared.WASM_OPT + ['--print', '--detect-features', + '--enable-simd', '-o', os.devnull, path]) def test_explicit_detect_features(self): self.check_features('signext_target_feature.wasm', ['simd', 'sign-ext'], |