Repository: bytecodealliance/wasm-tools
Pull request #1715 (2024-08-12 18:39:13)

threads: round out `missing-features` tests
This change attempts to add tests that check that
shared-everything-threads features indeed fail when the proposal is not enabled. In doing this, I realized that a few features fail on other features first (GC, reftypes), which meant the tests couldn't be as exhaustive as I would have liked. This commit also changes the wording of one of the failures to be consistent across the proposal.


Patch:
diff --git a/crates/wasmparser/src/validator/core.rs b/crates/wasmparser/src/validator/core.rs
index 003dbe59..94087a9c 100644
--- a/crates/wasmparser/src/validator/core.rs
+++ b/crates/wasmparser/src/validator/core.rs
@@ -663,7 +663,7 @@ impl Module {
         };
         if !features.shared_everything_threads() && ty.shared {
             return Err(BinaryReaderError::new(
-                "shared composite types are not supported without the shared-everything-threads feature",
+                "shared composite types require the shared-everything-threads proposal",
                 offset,
             ));
         }


Test patch:
diff --git a/tests/local/missing-features/globals.wast b/tests/local/missing-features/globals.wast
index 2439fc28..4d195afb 100644
--- a/tests/local/missing-features/globals.wast
+++ b/tests/local/missing-features/globals.wast
@@ -20,22 +20,3 @@
     (data (offset global.get 0))
   )
   "global.get of locally defined global")
-
-(assert_invalid
-  (module
-    (global (shared i32) (i32.const 0))
-  )
-  "shared globals require the shared-everything-threads proposal")
-
-(assert_invalid
-  (module
-    (global (import "spectest" "global_i64") (shared mut i64))
-  )
-  "shared globals require the shared-everything-threads proposal")
-
-(assert_invalid
-  (module
-    (global $a (import "spectest" "global_i32") i32)
-    (func (result i32) (global.atomic.get seq_cst $a))
-  )
-  "shared-everything-threads support is not enabled")
diff --git a/tests/local/missing-features/shared-everything-threads-arrays.wast b/tests/local/missing-features/shared-everything-threads-arrays.wast
new file mode 100644
index 00000000..06c21e35
--- /dev/null
+++ b/tests/local/missing-features/shared-everything-threads-arrays.wast
@@ -0,0 +1,8 @@
+(assert_invalid
+  (module
+    (type (shared (array i8)))
+  )
+  "shared composite types require the shared-everything-threads proposal")
+
+;; Any uses of `array.atomic.*` are first gated behind the GC feature, which the
+;; `missing-features` test cannot selectively enable.
diff --git a/tests/local/missing-features/shared-everything-threads-globals.wast b/tests/local/missing-features/shared-everything-threads-globals.wast
new file mode 100644
index 00000000..bb23a03b
--- /dev/null
+++ b/tests/local/missing-features/shared-everything-threads-globals.wast
@@ -0,0 +1,18 @@
+(assert_invalid
+  (module
+    (global (shared i32) (i32.const 0))
+  )
+  "shared globals require the shared-everything-threads proposal")
+
+(assert_invalid
+  (module
+    (global (import "spectest" "global_i64") (shared mut i64))
+  )
+  "shared globals require the shared-everything-threads proposal")
+
+(assert_invalid
+  (module
+    (global $a (import "spectest" "global_i32") i32)
+    (func (result i32) (global.atomic.get seq_cst $a))
+  )
+  "shared-everything-threads support is not enabled")
diff --git a/tests/local/missing-features/shared-everything-threads-structs.wast b/tests/local/missing-features/shared-everything-threads-structs.wast
new file mode 100644
index 00000000..67080eed
--- /dev/null
+++ b/tests/local/missing-features/shared-everything-threads-structs.wast
@@ -0,0 +1,8 @@
+(assert_invalid
+  (module
+    (type (shared (struct)))
+  )
+  "shared composite types require the shared-everything-threads proposal")
+
+;; Any uses of `struct.atomic.*` are first gated behind the GC feature, which
+;; the `missing-features` test cannot selectively enable.
diff --git a/tests/local/missing-features/tables.wast b/tests/local/missing-features/shared-everything-threads-tables.wast
similarity index 100%
rename from tests/local/missing-features/tables.wast
rename to tests/local/missing-features/shared-everything-threads-tables.wast
diff --git a/tests/local/missing-features/shared-everything-threads-types.wast b/tests/local/missing-features/shared-everything-threads-types.wast
new file mode 100644
index 00000000..f94fe72f
--- /dev/null
+++ b/tests/local/missing-features/shared-everything-threads-types.wast
@@ -0,0 +1,8 @@
+(assert_invalid
+  (module
+    (type (shared (func)))
+  )
+  "shared composite types require the shared-everything-threads proposal")
+
+;; Other uses of `shared` types are first gated behind the reference types
+;; feature, which the `missing-features` test cannot selectively enable.
diff --git a/tests/snapshots/local/missing-features/globals.wast.json b/tests/snapshots/local/missing-features/globals.wast.json
index f40cbdd0..13107bf6 100644
--- a/tests/snapshots/local/missing-features/globals.wast.json
+++ b/tests/snapshots/local/missing-features/globals.wast.json
@@ -21,27 +21,6 @@
       "filename": "globals.2.wasm",
       "text": "global.get of locally defined global",
       "module_type": "binary"
-    },
-    {
-      "type": "assert_invalid",
-      "line": 25,
-      "filename": "globals.3.wasm",
-      "text": "shared globals require the shared-everything-threads proposal",
-      "module_type": "binary"
-    },
-    {
-      "type": "assert_invalid",
-      "line": 31,
-      "filename": "globals.4.wasm",
-      "text": "shared globals require the shared-everything-threads proposal",
-      "module_type": "binary"
-    },
-    {
-      "type": "assert_invalid",
-      "line": 37,
-      "filename": "globals.5.wasm",
-      "text": "shared-everything-threads support is not enabled",
-      "module_type": "binary"
     }
   ]
 }
\ No newline at end of file
diff --git a/tests/snapshots/local/missing-features/shared-everything-threads-arrays.wast.json b/tests/snapshots/local/missing-features/shared-everything-threads-arrays.wast.json
new file mode 100644
index 00000000..3c9e61e8
--- /dev/null
+++ b/tests/snapshots/local/missing-features/shared-everything-threads-arrays.wast.json
@@ -0,0 +1,12 @@
+{
+  "source_filename": "tests/local/missing-features/shared-everything-threads-arrays.wast",
+  "commands": [
+    {
+      "type": "assert_invalid",
+      "line": 2,
+      "filename": "shared-everything-threads-arrays.0.wasm",
+      "text": "shared composite types require the shared-everything-threads proposal",
+      "module_type": "binary"
+    }
+  ]
+}
\ No newline at end of file
diff --git a/tests/snapshots/local/missing-features/shared-everything-threads-globals.wast.json b/tests/snapshots/local/missing-features/shared-everything-threads-globals.wast.json
new file mode 100644
index 00000000..dbec67d4
--- /dev/null
+++ b/tests/snapshots/local/missing-features/shared-everything-threads-globals.wast.json
@@ -0,0 +1,26 @@
+{
+  "source_filename": "tests/local/missing-features/shared-everything-threads-globals.wast",
+  "commands": [
+    {
+      "type": "assert_invalid",
+      "line": 2,
+      "filename": "shared-everything-threads-globals.0.wasm",
+      "text": "shared globals require the shared-everything-threads proposal",
+      "module_type": "binary"
+    },
+    {
+      "type": "assert_invalid",
+      "line": 8,
+      "filename": "shared-everything-threads-globals.1.wasm",
+      "text": "shared globals require the shared-everything-threads proposal",
+      "module_type": "binary"
+    },
+    {
+      "type": "assert_invalid",
+      "line": 14,
+      "filename": "shared-everything-threads-globals.2.wasm",
+      "text": "shared-everything-threads support is not enabled",
+      "module_type": "binary"
+    }
+  ]
+}
\ No newline at end of file
diff --git a/tests/snapshots/local/missing-features/shared-everything-threads-structs.wast.json b/tests/snapshots/local/missing-features/shared-everything-threads-structs.wast.json
new file mode 100644
index 00000000..d75a2756
--- /dev/null
+++ b/tests/snapshots/local/missing-features/shared-everything-threads-structs.wast.json
@@ -0,0 +1,12 @@
+{
+  "source_filename": "tests/local/missing-features/shared-everything-threads-structs.wast",
+  "commands": [
+    {
+      "type": "assert_invalid",
+      "line": 2,
+      "filename": "shared-everything-threads-structs.0.wasm",
+      "text": "shared composite types require the shared-everything-threads proposal",
+      "module_type": "binary"
+    }
+  ]
+}
\ No newline at end of file
diff --git a/tests/snapshots/local/missing-features/tables.wast.json b/tests/snapshots/local/missing-features/shared-everything-threads-tables.wast.json
similarity index 55%
rename from tests/snapshots/local/missing-features/tables.wast.json
rename to tests/snapshots/local/missing-features/shared-everything-threads-tables.wast.json
index 5e06332b..ff452b14 100644
--- a/tests/snapshots/local/missing-features/tables.wast.json
+++ b/tests/snapshots/local/missing-features/shared-everything-threads-tables.wast.json
@@ -1,10 +1,10 @@
 {
-  "source_filename": "tests/local/missing-features/tables.wast",
+  "source_filename": "tests/local/missing-features/shared-everything-threads-tables.wast",
   "commands": [
     {
       "type": "assert_invalid",
       "line": 2,
-      "filename": "tables.0.wasm",
+      "filename": "shared-everything-threads-tables.0.wasm",
       "text": "shared tables require the shared-everything-threads proposal",
       "module_type": "binary"
     }
diff --git a/tests/snapshots/local/missing-features/shared-everything-threads-types.wast.json b/tests/snapshots/local/missing-features/shared-everything-threads-types.wast.json
new file mode 100644
index 00000000..4f4cb69f
--- /dev/null
+++ b/tests/snapshots/local/missing-features/shared-everything-threads-types.wast.json
@@ -0,0 +1,12 @@
+{
+  "source_filename": "tests/local/missing-features/shared-everything-threads-types.wast",
+  "commands": [
+    {
+      "type": "assert_invalid",
+      "line": 2,
+      "filename": "shared-everything-threads-types.0.wasm",
+      "text": "shared composite types require the shared-everything-threads proposal",
+      "module_type": "binary"
+    }
+  ]
+}
\ No newline at end of file