Repository: bytecodealliance/wasm-tools
Pull request #2086 (2025-03-07 17:24:43)

Disallow `realloc` option on `task.return`
This'll soon be updated in the spec as well, but `task.return` is only lifting values so there's no need for `realloc`, so go ahead and forbid it from being present on the `task.return` intrinsic.


Patch:
diff --git a/crates/wasmparser/src/validator/component.rs b/crates/wasmparser/src/validator/component.rs
index 9271f5d0..4f5cafc1 100644
--- a/crates/wasmparser/src/validator/component.rs
+++ b/crates/wasmparser/src/validator/component.rs
@@ -1206,9 +1206,8 @@ impl ComponentState {
                 CanonicalOption::UTF8
                 | CanonicalOption::UTF16
                 | CanonicalOption::CompactUTF16
-                | CanonicalOption::Memory(_)
-                | CanonicalOption::Realloc(_) => continue,
-
+                | CanonicalOption::Memory(_) => continue,
+                CanonicalOption::Realloc(_) => "realloc",
                 CanonicalOption::PostReturn(_) => "post-return",
                 CanonicalOption::Async => "async",
                 CanonicalOption::Callback(_) => "callback",


Test patch:
diff --git a/tests/local/component-model-async/task-builtins.wast b/tests/local/component-model-async/task-builtins.wast
index d13d5088..45e83755 100644
--- a/tests/local/component-model-async/task-builtins.wast
+++ b/tests/local/component-model-async/task-builtins.wast
@@ -46,17 +46,25 @@
   )
   "cannot specify `post-return` option on `task.return`")
 
+(assert_invalid
+  (component
+    (core module $m
+      (func (export "r") (param i32 i32 i32 i32) (result i32) unreachable)
+    )
+    (core instance $m (instantiate $m))
+    (core func $task-return (canon task.return (result u32) (realloc (func $m "r"))))
+  )
+  "cannot specify `realloc` option on `task.return`")
+
 (component
   (core module $m
     (memory (export "m") 1)
-    (func (export "r") (param i32 i32 i32 i32) (result i32) unreachable)
   )
   (core instance $i (instantiate $m))
   (core func (canon task.return (result u32) string-encoding=utf8))
   (core func (canon task.return (result u32) string-encoding=utf16))
   (core func (canon task.return (result u32) string-encoding=latin1+utf16))
   (core func (canon task.return (result u32) (memory $i "m")))
-  (core func (canon task.return (result u32) (realloc (func $i "r"))))
 )
 
 ;; waitable-set.new
diff --git a/tests/snapshots/local/component-model-async/task-builtins.wast.json b/tests/snapshots/local/component-model-async/task-builtins.wast.json
index dfe9b963..260e12f3 100644
--- a/tests/snapshots/local/component-model-async/task-builtins.wast.json
+++ b/tests/snapshots/local/component-model-async/task-builtins.wast.json
@@ -42,106 +42,113 @@
       "text": "cannot specify `post-return` option on `task.return`"
     },
     {
-      "type": "module",
-      "line": 49,
+      "type": "assert_invalid",
+      "line": 50,
       "filename": "task-builtins.6.wasm",
-      "module_type": "binary"
+      "module_type": "binary",
+      "text": "cannot specify `realloc` option on `task.return`"
     },
     {
       "type": "module",
-      "line": 63,
+      "line": 59,
       "filename": "task-builtins.7.wasm",
       "module_type": "binary"
     },
     {
-      "type": "assert_invalid",
+      "type": "module",
       "line": 71,
       "filename": "task-builtins.8.wasm",
+      "module_type": "binary"
+    },
+    {
+      "type": "assert_invalid",
+      "line": 79,
+      "filename": "task-builtins.9.wasm",
       "module_type": "binary",
       "text": "type mismatch for export `waitable-set.new` of module instantiation argument ``"
     },
     {
       "type": "module",
-      "line": 80,
-      "filename": "task-builtins.9.wasm",
+      "line": 88,
+      "filename": "task-builtins.10.wasm",
       "module_type": "binary"
     },
     {
       "type": "assert_invalid",
-      "line": 92,
-      "filename": "task-builtins.10.wasm",
+      "line": 100,
+      "filename": "task-builtins.11.wasm",
       "module_type": "binary",
       "text": "type mismatch for export `waitable-set.wait` of module instantiation argument ``"
     },
     {
       "type": "module",
-      "line": 105,
-      "filename": "task-builtins.11.wasm",
+      "line": 113,
+      "filename": "task-builtins.12.wasm",
       "module_type": "binary"
     },
     {
       "type": "assert_invalid",
-      "line": 117,
-      "filename": "task-builtins.12.wasm",
+      "line": 125,
+      "filename": "task-builtins.13.wasm",
       "module_type": "binary",
       "text": "type mismatch for export `waitable-set.poll` of module instantiation argument ``"
     },
     {
       "type": "module",
-      "line": 130,
-      "filename": "task-builtins.13.wasm",
+      "line": 138,
+      "filename": "task-builtins.14.wasm",
       "module_type": "binary"
     },
     {
       "type": "assert_invalid",
-      "line": 138,
-      "filename": "task-builtins.14.wasm",
+      "line": 146,
+      "filename": "task-builtins.15.wasm",
       "module_type": "binary",
       "text": "type mismatch for export `waitable-set.drop` of module instantiation argument ``"
     },
     {
       "type": "module",
-      "line": 147,
-      "filename": "task-builtins.15.wasm",
+      "line": 155,
+      "filename": "task-builtins.16.wasm",
       "module_type": "binary"
     },
     {
       "type": "assert_invalid",
-      "line": 155,
-      "filename": "task-builtins.16.wasm",
+      "line": 163,
+      "filename": "task-builtins.17.wasm",
       "module_type": "binary",
       "text": "type mismatch for export `waitable.join` of module instantiation argument ``"
     },
     {
       "type": "module",
-      "line": 164,
-      "filename": "task-builtins.17.wasm",
+      "line": 172,
+      "filename": "task-builtins.18.wasm",
       "module_type": "binary"
     },
     {
       "type": "assert_invalid",
-      "line": 174,
-      "filename": "task-builtins.18.wasm",
+      "line": 182,
+      "filename": "task-builtins.19.wasm",
       "module_type": "binary",
       "text": "type mismatch for export `yield` of module instantiation argument ``"
     },
     {
       "type": "module",
-      "line": 185,
-      "filename": "task-builtins.19.wasm",
+      "line": 193,
+      "filename": "task-builtins.20.wasm",
       "module_type": "binary"
     },
     {
       "type": "assert_invalid",
-      "line": 195,
-      "filename": "task-builtins.20.wasm",
+      "line": 203,
+      "filename": "task-builtins.21.wasm",
       "module_type": "binary",
       "text": "type mismatch for export `subtask.drop` of module instantiation argument ``"
     },
     {
       "type": "module",
-      "line": 207,
-      "filename": "task-builtins.21.wasm",
+      "line": 215,
+      "filename": "task-builtins.22.wasm",
       "module_type": "binary"
     }
   ]
diff --git a/tests/snapshots/local/component-model-async/task-builtins.wast/9.print b/tests/snapshots/local/component-model-async/task-builtins.wast/10.print
similarity index 100%
rename from tests/snapshots/local/component-model-async/task-builtins.wast/9.print
rename to tests/snapshots/local/component-model-async/task-builtins.wast/10.print
diff --git a/tests/snapshots/local/component-model-async/task-builtins.wast/11.print b/tests/snapshots/local/component-model-async/task-builtins.wast/12.print
similarity index 100%
rename from tests/snapshots/local/component-model-async/task-builtins.wast/11.print
rename to tests/snapshots/local/component-model-async/task-builtins.wast/12.print
diff --git a/tests/snapshots/local/component-model-async/task-builtins.wast/13.print b/tests/snapshots/local/component-model-async/task-builtins.wast/14.print
similarity index 100%
rename from tests/snapshots/local/component-model-async/task-builtins.wast/13.print
rename to tests/snapshots/local/component-model-async/task-builtins.wast/14.print
diff --git a/tests/snapshots/local/component-model-async/task-builtins.wast/15.print b/tests/snapshots/local/component-model-async/task-builtins.wast/16.print
similarity index 100%
rename from tests/snapshots/local/component-model-async/task-builtins.wast/15.print
rename to tests/snapshots/local/component-model-async/task-builtins.wast/16.print
diff --git a/tests/snapshots/local/component-model-async/task-builtins.wast/17.print b/tests/snapshots/local/component-model-async/task-builtins.wast/18.print
similarity index 100%
rename from tests/snapshots/local/component-model-async/task-builtins.wast/17.print
rename to tests/snapshots/local/component-model-async/task-builtins.wast/18.print
diff --git a/tests/snapshots/local/component-model-async/task-builtins.wast/19.print b/tests/snapshots/local/component-model-async/task-builtins.wast/20.print
similarity index 100%
rename from tests/snapshots/local/component-model-async/task-builtins.wast/19.print
rename to tests/snapshots/local/component-model-async/task-builtins.wast/20.print
diff --git a/tests/snapshots/local/component-model-async/task-builtins.wast/21.print b/tests/snapshots/local/component-model-async/task-builtins.wast/22.print
similarity index 100%
rename from tests/snapshots/local/component-model-async/task-builtins.wast/21.print
rename to tests/snapshots/local/component-model-async/task-builtins.wast/22.print
diff --git a/tests/snapshots/local/component-model-async/task-builtins.wast/6.print b/tests/snapshots/local/component-model-async/task-builtins.wast/6.print
deleted file mode 100644
index 86207d78..00000000
--- a/tests/snapshots/local/component-model-async/task-builtins.wast/6.print
+++ /dev/null
@@ -1,19 +0,0 @@
-(component
-  (core module $m (;0;)
-    (type (;0;) (func (param i32 i32 i32 i32) (result i32)))
-    (memory (;0;) 1)
-    (export "m" (memory 0))
-    (export "r" (func 0))
-    (func (;0;) (type 0) (param i32 i32 i32 i32) (result i32)
-      unreachable
-    )
-  )
-  (core instance $i (;0;) (instantiate $m))
-  (core func (;0;) (canon task.return (result u32) string-encoding=utf8))
-  (core func (;1;) (canon task.return (result u32) string-encoding=utf16))
-  (core func (;2;) (canon task.return (result u32) string-encoding=latin1+utf16))
-  (alias core export $i "m" (core memory (;0;)))
-  (core func (;3;) (canon task.return (result u32) (memory 0)))
-  (alias core export $i "r" (core func (;4;)))
-  (core func (;5;) (canon task.return (result u32) (realloc 4)))
-)
diff --git a/tests/snapshots/local/component-model-async/task-builtins.wast/7.print b/tests/snapshots/local/component-model-async/task-builtins.wast/7.print
index 967b3b8c..48e7d0ad 100644
--- a/tests/snapshots/local/component-model-async/task-builtins.wast/7.print
+++ b/tests/snapshots/local/component-model-async/task-builtins.wast/7.print
@@ -1,14 +1,12 @@
 (component
   (core module $m (;0;)
-    (type (;0;) (func (result i32)))
-    (import "" "waitable-set.new" (func (;0;) (type 0)))
-  )
-  (core func $waitable-set-new (;0;) (canon waitable-set.new))
-  (core instance (;0;)
-    (export "waitable-set.new" (func $waitable-set-new))
-  )
-  (core instance $i (;1;) (instantiate $m
-      (with "" (instance 0))
-    )
+    (memory (;0;) 1)
+    (export "m" (memory 0))
   )
+  (core instance $i (;0;) (instantiate $m))
+  (core func (;0;) (canon task.return (result u32) string-encoding=utf8))
+  (core func (;1;) (canon task.return (result u32) string-encoding=utf16))
+  (core func (;2;) (canon task.return (result u32) string-encoding=latin1+utf16))
+  (alias core export $i "m" (core memory (;0;)))
+  (core func (;3;) (canon task.return (result u32) (memory 0)))
 )
diff --git a/tests/snapshots/local/component-model-async/task-builtins.wast/8.print b/tests/snapshots/local/component-model-async/task-builtins.wast/8.print
new file mode 100644
index 00000000..967b3b8c
--- /dev/null
+++ b/tests/snapshots/local/component-model-async/task-builtins.wast/8.print
@@ -0,0 +1,14 @@
+(component
+  (core module $m (;0;)
+    (type (;0;) (func (result i32)))
+    (import "" "waitable-set.new" (func (;0;) (type 0)))
+  )
+  (core func $waitable-set-new (;0;) (canon waitable-set.new))
+  (core instance (;0;)
+    (export "waitable-set.new" (func $waitable-set-new))
+  )
+  (core instance $i (;1;) (instantiate $m
+      (with "" (instance 0))
+    )
+  )
+)