From 192757772adce7568fc1f3f3e733a4263b6392c6 Mon Sep 17 00:00:00 2001 From: Daniel Wirtz Date: Fri, 11 Sep 2020 03:04:17 +0200 Subject: Add anyref feature and type (#3109) Adds `anyref` type, which is enabled by a new feature `--enable-anyref`. This type is primarily used for testing that passes correctly handle subtype relationships so that the codebase will continue to be prepared for future subtyping. Since `--enable-anyref` is meaningless without also using `--enable-reference-types`, this PR also makes it a validation error to pass only the former (and similarly makes it a validation error to enable exception handling without enabling reference types). --- test/unit/test_features.py | 44 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) (limited to 'test/unit/test_features.py') diff --git a/test/unit/test_features.py b/test/unit/test_features.py index 506fd8809..2b5b00469 100644 --- a/test/unit/test_features.py +++ b/test/unit/test_features.py @@ -42,8 +42,17 @@ class FeatureValidationTest(utils.BinaryenTestCase): self.check_feature(module, error, '--enable-reference-types') def check_multivalue(self, module, error): + self.check_feature(module, error, '--enable-multivalue') + + def check_multivalue_exception_handling(self, module, error): self.check_feature(module, error, '--enable-multivalue', - ['--enable-exception-handling']) + ['--enable-exception-handling', + '--enable-reference-types']) + + def check_anyref(self, module, error): + # Anyref handling implies reference types + self.check_feature(module, error, '--enable-anyref', + ['--enable-reference-types']) def test_v128_signature(self): module = ''' @@ -228,8 +237,8 @@ class FeatureValidationTest(utils.BinaryenTestCase): (event $foo (attr 0) (param i32 i64)) ) ''' - self.check_multivalue(module, 'Multivalue event type ' + - '(multivalue is not enabled)') + self.check_multivalue_exception_handling(module, 'Multivalue event type ' + + '(multivalue is not enabled)') def test_multivalue_block(self): module = ''' @@ -249,6 +258,24 @@ class FeatureValidationTest(utils.BinaryenTestCase): self.check_multivalue(module, 'Multivalue block type ' + '(multivalue is not enabled)') + def test_anyref_global(self): + module = ''' + (module + (global $foo anyref (ref.null any)) + ) + ''' + self.check_anyref(module, 'all used types should be allowed') + + def test_anyref_local(self): + module = ''' + (module + (func $foo + (local $0 anyref) + ) + ) + ''' + self.check_anyref(module, 'all used types should be allowed') + class TargetFeaturesSectionTest(utils.BinaryenTestCase): def test_atomics(self): @@ -303,9 +330,15 @@ class TargetFeaturesSectionTest(utils.BinaryenTestCase): def test_exception_handling(self): filename = 'exception_handling_target_feature.wasm' self.roundtrip(filename) - self.check_features(filename, ['exception-handling']) + self.check_features(filename, ['exception-handling', 'reference-types']) self.assertIn('throw', self.disassemble(filename)) + def test_anyref(self): + filename = 'anyref_target_feature.wasm' + self.roundtrip(filename) + self.check_features(filename, ['reference-types', 'anyref']) + self.assertIn('anyref', self.disassemble(filename)) + def test_incompatible_features(self): path = self.input_path('signext_target_feature.wasm') p = shared.run_process( @@ -353,5 +386,6 @@ class TargetFeaturesSectionTest(utils.BinaryenTestCase): '--enable-exception-handling', '--enable-tail-call', '--enable-reference-types', - '--enable-multivalue' + '--enable-multivalue', + '--enable-anyref' ], p2.stdout.splitlines()) -- cgit v1.2.3