diff --git a/test/README.md b/test/README.md index 2ba8be05..b97f7ec8 100644 --- a/test/README.md +++ b/test/README.md @@ -6,12 +6,12 @@ This directory contains Component Model reference tests, grouped by functionalit A single `.wast` test can be run with full backtrace on trap via: ``` -WASMTIME_BACKTRACE_DETAILS=1 WAST_STRICT_COMPONENT_INDICES=1 wasmtime wast -W component-model-more-async-builtins -W component-model-threading -W component-model-async-stackful -W component-model-implements the-test.wast +WASMTIME_BACKTRACE_DETAILS=1 WAST_STRICT_COMPONENT_INDICES=1 wasmtime wast -W component-model-more-async-builtins -W component-model-threading -W component-model-async-stackful -W component-model-implements -W component-model-fixed-length-lists -W component-model-map the-test.wast ``` Sometimes test land ahead of the implementation and fail for a while. These tests are listed in 'nyi.txt' so that they can be filtered out. Thus, a simple way to run all the reference tests is: ``` -find . -name "*.wast" | grep -vxFf nyi.txt | WAST_STRICT_COMPONENT_INDICES=1 xargs wasmtime wast -W component-model-more-async-builtins -W component-model-threading -W component-model-async-stackful -W component-model-implements +find . -name "*.wast" | grep -vxFf nyi.txt | WAST_STRICT_COMPONENT_INDICES=1 xargs wasmtime wast -W component-model-more-async-builtins -W component-model-threading -W component-model-async-stackful -W component-model-implements -W component-model-fixed-length-lists -W component-model-map ``` diff --git a/test/async/cancellable.wast b/test/async/cancellable.wast index 3de95290..a24acc85 100644 --- a/test/async/cancellable.wast +++ b/test/async/cancellable.wast @@ -199,9 +199,6 @@ ;; cancel; completes immediately (C is in cancellable yield) (local.set $ret (call $subtask.cancel (local.get $subtask))) (if (i32.ne (i32.const 4 (; CANCELLED_BEFORE_RETURNED ;)) (local.get $ret)) - ;; TODO: this currently fails in Wasmtime due to cancellable - ;; thread.yield not being directly resumed by subtask.cancel, but it - ;; seems like it should pass: (then unreachable)) (call $subtask.drop (local.get $subtask)) diff --git a/test/async/trap-if-block-and-sync.wast b/test/async/trap-if-block-and-sync.wast index d196b393..8b7b30ae 100644 --- a/test/async/trap-if-block-and-sync.wast +++ b/test/async/trap-if-block-and-sync.wast @@ -50,9 +50,9 @@ (import "" "task.return" (func $task.return (param i32))) (import "" "subtask.cancel" (func $subtask.cancel (param i32) (result i32))) (import "" "thread.yield" (func $thread.yield (result i32))) - ;;(import "" "thread.yield-to" (func $thread.yield-to (param i32) (result i32))) - ;;(import "" "thread.switch-to" (func $thread.switch-to (param i32) (result i32))) - ;;(import "" "thread.resume-later" (func $thread.resume-later (param i32))) + (import "" "thread.yield-then-resume" (func $thread.yield-then-resume (param i32) (result i32))) + (import "" "thread.suspend-then-resume" (func $thread.suspend-then-resume (param i32) (result i32))) + (import "" "thread.resume-later" (func $thread.resume-later (param i32))) (import "" "thread.index" (func $thread-index (result i32))) (import "" "thread.suspend" (func $thread.suspend (result i32))) (import "" "thread.new-indirect" (func $thread.new-indirect (param i32 i32) (result i32))) @@ -126,23 +126,20 @@ ) (func $thread-start-noop (param i32)) (elem (table $indirect-function-table) (i32.const 0) func $thread-start-noop) - (func (export "yield-to-is-fine") (result i32) - ;; TODO: rename and reenable - ;;(drop (call $thread.yield-to (call $thread.new-indirect (i32.const 0) (i32.const 0)))) + (func (export "yield-then-resume-is-fine") (result i32) + (drop (call $thread.yield-then-resume (call $thread.new-indirect (i32.const 0) (i32.const 0)))) (i32.const 42) ) - (func $thread-start-switch-back (param i32) - ;;(drop (call $thread.switch-to (local.get 0))) + (func $thread-start-resume-back (param i32) + (drop (call $thread.suspend-then-resume (local.get 0))) ) - (elem (table $indirect-function-table) (i32.const 1) func $thread-start-switch-back) - (func (export "switch-to-is-fine") (result i32) - ;; TODO: rename and reenable - ;;(drop (call $thread.switch-to (call $thread.new-indirect (i32.const 1) (call $thread-index)))) + (elem (table $indirect-function-table) (i32.const 1) func $thread-start-resume-back) + (func (export "suspend-then-resume-is-fine") (result i32) + (drop (call $thread.suspend-then-resume (call $thread.new-indirect (i32.const 1) (call $thread-index)))) (i32.const 42) ) (func (export "resume-later-is-fine") (result i32) - ;; TODO: rename and reenable - ;;(call $thread.resume-later (call $thread.new-indirect (i32.const 0) (i32.const 0))) + (call $thread.resume-later (call $thread.new-indirect (i32.const 0) (i32.const 0))) (i32.const 42) ) (func (export "trap-if-sync-cancel") @@ -192,9 +189,9 @@ (canon subtask.cancel (core func $subtask.cancel)) (canon thread.yield (core func $thread.yield)) (canon thread.suspend (core func $thread.suspend)) - ;;(canon thread.yield-to (core func $thread.yield-to)) - ;;(canon thread.switch-to (core func $thread.switch-to)) - ;;(canon thread.resume-later (core func $thread.resume-later)) + (canon thread.yield-then-resume (core func $thread.yield-then-resume)) + (canon thread.suspend-then-resume (core func $thread.suspend-then-resume)) + (canon thread.resume-later (core func $thread.resume-later)) (canon thread.index (core func $thread.index)) (canon waitable.join (core func $waitable.join)) (canon waitable-set.new (core func $waitable-set.new)) @@ -217,9 +214,9 @@ (export "subtask.cancel" (func $subtask.cancel)) (export "thread.yield" (func $thread.yield)) (export "thread.suspend" (func $thread.suspend)) - ;;(export "thread.yield-to" (func $thread.yield-to)) - ;;(export "thread.switch-to" (func $thread.switch-to)) - ;;(export "thread.resume-later" (func $thread.resume-later)) + (export "thread.yield-then-resume" (func $thread.yield-then-resume)) + (export "thread.suspend-then-resume" (func $thread.suspend-then-resume)) + (export "thread.resume-later" (func $thread.resume-later)) (export "thread.index" (func $thread.index)) (export "thread.new-indirect" (func $thread.new-indirect)) (export "waitable.join" (func $waitable.join)) @@ -245,8 +242,8 @@ (func (export "trap-if-invalid-callback-code") async (param "invalid-code" u32) (canon lift (core func $core "trap-if-invalid-callback-code") async (callback (core func $core "unreachable-cb")))) (func (export "yield-is-fine") (result u32) (canon lift (core func $core "yield-is-fine"))) (func (export "yield-is-fine-cb") async (result u32) (canon lift (core func $core "yield-is-fine-cb") async (callback (core func $core "return-42-cb")))) - (func (export "yield-to-is-fine") (result u32) (canon lift (core func $core "yield-to-is-fine"))) - (func (export "switch-to-is-fine") (result u32) (canon lift (core func $core "switch-to-is-fine"))) + (func (export "yield-then-resume-is-fine") (result u32) (canon lift (core func $core "yield-then-resume-is-fine"))) + (func (export "suspend-then-resume-is-fine") (result u32) (canon lift (core func $core "suspend-then-resume-is-fine"))) (func (export "resume-later-is-fine") (result u32) (canon lift (core func $core "resume-later-is-fine"))) (func (export "trap-if-sync-call-async1") (canon lift (core func $core "trap-if-sync-call-async1"))) (func (export "trap-if-sync-call-async2") (canon lift (core func $core "trap-if-sync-call-async2"))) @@ -272,8 +269,8 @@ (func (export "trap-if-invalid-callback-code") (alias export $d "trap-if-invalid-callback-code")) (func (export "yield-is-fine") (alias export $d "yield-is-fine")) (func (export "yield-is-fine-cb") (alias export $d "yield-is-fine-cb")) - (func (export "yield-to-is-fine") (alias export $d "yield-to-is-fine")) - (func (export "switch-to-is-fine") (alias export $d "switch-to-is-fine")) + (func (export "yield-then-resume-is-fine") (alias export $d "yield-then-resume-is-fine")) + (func (export "suspend-then-resume-is-fine") (alias export $d "suspend-then-resume-is-fine")) (func (export "resume-later-is-fine") (alias export $d "resume-later-is-fine")) (func (export "trap-if-sync-cancel") (alias export $d "trap-if-sync-cancel")) (func (export "trap-if-sync-stream-read") (alias export $d "trap-if-sync-stream-read")) @@ -309,9 +306,9 @@ (component instance $i $Tester) (assert_return (invoke "yield-is-fine-cb") (u32.const 42)) (component instance $i $Tester) -(assert_return (invoke "yield-to-is-fine") (u32.const 42)) +(assert_return (invoke "yield-then-resume-is-fine") (u32.const 42)) (component instance $i $Tester) -(assert_return (invoke "switch-to-is-fine") (u32.const 42)) +(assert_return (invoke "suspend-then-resume-is-fine") (u32.const 42)) (component instance $i $Tester) (assert_return (invoke "resume-later-is-fine") (u32.const 42)) (component instance $i $Tester) diff --git a/test/binary/binary.wast b/test/binary/binary.wast new file mode 100644 index 00000000..d8ea2725 --- /dev/null +++ b/test/binary/binary.wast @@ -0,0 +1,1531 @@ +;; Binary format tests. See design/mvp/Binary.md +;; Note that 0xD is used as the version throughout, but this will be changed to +;; 1 when the component model is fully standardized. + +;; preamble: magic, version (0x0d 0x00) and layer (0x01 0x00) + +(component binary "\00asm\0d\00\01\00") +(component binary "\00asm" "\0d\00\01\00") +(component $B1 binary "\00asm" "\0d\00\01\00") +(assert_malformed (component binary "") "unexpected end") +(assert_malformed (component binary "\00") "unexpected end") +(assert_malformed (component binary "\00as") "unexpected end") +(assert_malformed (component binary "\00asm") "unexpected end") +(assert_malformed (component binary "\00asm" "\0d") "unexpected end") +(assert_malformed (component binary "\00asm" "\0d\00") "unexpected end") +(assert_malformed (component binary "\00asm" "\0d\00\01") "unexpected end") +(assert_malformed (component binary "asm\00" "\0d\00\01\00") "magic header not detected") +(assert_malformed (component binary "msa\00" "\0d\00\01\00") "magic header not detected") +(assert_malformed (component binary "\00ASM" "\0d\00\01\00") "magic header not detected") +(assert_malformed (component binary "\ffasm" "\0d\00\01\00") "magic header not detected") +(assert_malformed (component binary "\00asm" "\0c\00\01\00") "unknown binary version") +(assert_malformed (component binary "\00asm" "\0e\00\01\00") "unknown binary version") +(assert_malformed (component binary "\00asm" "\00\0d\01\00") "unknown binary version") +(assert_malformed (component binary "\00asm" "\0d\00\02\00") "unknown binary version") +(assert_malformed (component binary "\00asm" "\0d\00\01\01") "unknown binary version") +(assert_malformed (component binary "\00asm" "\0d\00\00\00") "unknown binary version") + +;; custom sections (id 0) + +(component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\00\03" ;; custom section (3 bytes) + "\02hi" ;; name "hi" +) +(component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\00\12" ;; custom section (18 bytes) + "\0ecomponent-name" ;; name "component-name" + "\ff\fe\01" ;; garbage: validity is not required + "\00\10" ;; custom section (16 bytes) + "\0ecomponent-name" ;; name "component-name" + "\99" ;; more garbage, repeated name is fine +) +(assert_malformed + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\00\03" ;; custom section (3 bytes) + "\05\61\62" ;; name length 5, only 2 bytes + ) + "unexpected end-of-file" +) +(assert_malformed + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\00\03" ;; custom section (3 bytes) + "\02\ff\fe" ;; name is not valid UTF-8 + ) + "malformed UTF-8 encoding" +) + +;; non-custom sections + +(assert_malformed + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\0d\00" ;; section id 13, empty + ) + "malformed section id" +) +(assert_malformed + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\3c\00" ;; section id 60, empty + ) + "malformed section id" +) +(assert_malformed + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\ff" ;; malformed section id byte + ) + "malformed section id" +) + +(assert_malformed + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\07\03\00" ;; type section: size 3, one byte of contents + ) + "unexpected end-of-file" +) +(assert_malformed + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\07\01\01\73" ;; type section: size 1, two bytes of contents + ) + "section size mismatch" +) +(assert_malformed + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\00\80\80" ;; custom section: size LEB runs past EOF + ) + "unexpected end-of-file" +) +(assert_malformed + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\00" ;; section id with no size + ) + "unexpected end-of-file" +) + +(component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\07\01" ;; type section (1 bytes) + "\00" ;; 0 types +) +(component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\05\01" ;; instance section (1 bytes) + "\00" ;; 0 instances + "\08\01" ;; canon section (1 bytes) + "\00" ;; 0 canons +) + +(component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\07\02" ;; type section (2 bytes) + "\01" ;; 1 type + "\73" ;; string + "\06\05" ;; alias section (5 bytes) + "\01" ;; 1 alias + "\03\02\00\00" ;; outer alias: type, ct=0, idx=0 + "\00\08" ;; custom section (8 bytes) + "\07between" ;; name "between" + "\07\03" ;; type section (3 bytes) + "\01" ;; 1 type + "\70\01" ;; (list ), the alias +) + +;; LEB128: overlong-but-zero-padded u32 encodings are valid; set bits past +;; the 32nd are not. Vector counts larger than the remaining input fail. + +(component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\07\81\80\80\80\00" ;; type section, 5-byte LEB size 1 + "\00" ;; 0 types +) +(assert_malformed + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\07\81\80\80\80\70" ;; type section: size LEB with bits >u32 + "\00" ;; 0 types + ) + "integer too large" +) +(assert_malformed + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\07\04" ;; type section (4 bytes) + "\bf\84\3d" ;; vec count 999999 + "\73" ;; string + ) + "unexpected end-of-file" +) +(assert_malformed + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\07\02" ;; type section (2 bytes) + "\02" ;; 2 types + "\73" ;; only one given + ) + "unexpected end-of-file" +) + +;; core module section (id 1) + +(component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\01\08" ;; core module section: empty module (8 bytes) + "\00asm" "\01\00\00\00" ;; core module preamble +) +(component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\01\1f" ;; core module section (31 bytes) + "\00asm" "\01\00\00\00" ;; core module preamble + "\01\04\01\60\00\00" ;; type section: (func) + "\03\02\01\00" ;; func section: 1 func of type 0 + "\07\05\01" ;; export section, 1 export + "\01f" ;; name "f" + "\00\00" ;; func 0 + "\0a\04\01\02\00\0b" ;; code section: 1 empty body + "\02\04" ;; core instance section (4 bytes) + "\01" ;; 1 core instance + "\00\00\00" ;; instantiate module 0, 0 args +) + +(assert_malformed + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\01\11" ;; core module section (17 bytes) + "\00asm" "\01\00\00\00" ;; core module preamble + "\01\01\00" ;; type section, 0 types + "\0b\01\00" ;; data section, 0 segments + "\01\01\00" ;; type section again: out of order + ) + "section out of order" +) + +(assert_malformed + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\01\08" ;; core module section (8 bytes) + "\00asm" "\0d\00\01\00" ;; a component preamble, not a core module + ) + "unknown binary version" +) + +;; core instance section (id 2) + +(component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\01\1f" ;; core module section (31 bytes) + "\00asm" "\01\00\00\00" ;; core module preamble + "\01\04\01\60\00\00" ;; type section: (func) + "\03\02\01\00" ;; func section: 1 func of type 0 + "\07\05\01" ;; export section, 1 export + "\01f" ;; name "f" + "\00\00" ;; func 0 + "\0a\04\01\02\00\0b" ;; code section: 1 empty body + "\02\06" ;; core instance section (6 bytes) + "\02" ;; 2 core instances + "\00\00\00" ;; 0x00 instantiate module 0, 0 args + "\01\00" ;; 0x01 inline exports, 0 exports + "\06\07" ;; alias section (7 bytes) + "\01" ;; 1 aliases + "\00\00\01\00" ;; core func, core export alias, instance 0 + "\01f" ;; name "f" + "\02\08" ;; core instance section (8 bytes) + "\01" ;; 1 core instance + "\01\01" ;; 0x01 inline exports, 1 export: + "\02f2" ;; name "f2" + "\00\00" ;; core:sortidx func 0 (the alias) +) +(component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\01\14" ;; core module section: imports ("i" "mem") (20 bytes) + "\00asm" "\01\00\00\00" ;; core module preamble + "\02\0a" ;; import section (10 bytes) + "\01" ;; 1 import + "\01i" ;; name "i" + "\03mem" ;; name "mem" + "\02\00\01" ;; memory, limits {min 1} + "\01\16" ;; core module section: exports "mem" (22 bytes) + "\00asm" "\01\00\00\00" ;; core module preamble + "\05\03\01\00\01" ;; memory section: 1 memory + "\07\07" ;; export section (7 bytes) + "\01" ;; 1 export + "\03mem" ;; name "mem" + "\02\00" ;; memory 0 + "\02\0b" ;; core instance section (11 bytes) + "\02" ;; 2 core instances + "\00\01\00" ;; instantiate module 1, 0 args + "\00\00\01" ;; instantiate module 0, 1 arg: + "\01i" ;; name "i" + "\12\00" ;; 0x12 (instance sort) instance 0 +) +(assert_malformed + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\01\08" ;; core module section (8 bytes) + "\00asm" "\01\00\00\00" ;; core module preamble + "\02\04" ;; core instance section (4 bytes) + "\01" ;; 1 core instance + "\02\00\00" ;; 0x02 is not a core:instanceexpr + ) + "invalid leading byte (0x2) for core instance" +) +(assert_malformed + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\01\08" ;; core module section (8 bytes) + "\00asm" "\01\00\00\00" ;; core module preamble + "\02\04" ;; core instance section (4 bytes) + "\01" ;; 1 core instance + "\00\00\00" ;; instantiate module 0, 0 args + "\01\08" ;; core module section (8 bytes) + "\00asm" "\01\00\00\00" ;; core module preamble + "\02\08" ;; core instance section (8 bytes) + "\01" ;; 1 core instance + "\00\01\01" ;; instantiate module 1, 1 arg: + "\01i" ;; name "i" + "\00\00" ;; arg sort must be 0x12 (instance), not 0x00 (func) + ) + "invalid leading byte (0x0) for instantiation arg kind" +) + +;; instance section (id 5) + +(component definition binary + "\00asm" "\0d\00\01\00" ;; preamble + "\07\05" ;; type section (5 bytes) + "\01" ;; 1 type + "\40\00\01\00" ;; (func) + "\0a\06" ;; import section (6 bytes) + "\01" ;; 1 import + "\00" ;; plain externname + "\01f" ;; name "f" + "\01\00" ;; func (type 0) + "\04\17" ;; component section: nested component (23 bytes) + "\00asm" "\0d\00\01\00" ;; preamble + "\07\05" ;; type section (5 bytes) + "\01" ;; 1 type + "\40\00\01\00" ;; (func) + "\0a\06" ;; import section (6 bytes) + "\01" ;; 1 import + "\00" ;; plain externname + "\01x" ;; name "x" + "\01\00" ;; func (type 0) + "\05\11" ;; instance section (17 bytes) + "\03" ;; 3 instances + "\00\00\01" ;; 0x00 instantiate component 0, 1 arg: + "\01x" ;; name "x" + "\01\00" ;; sortidx func 0 + "\01\00" ;; 0x01 inline exports, 0 exports + "\01\01" ;; 0x01 inline exports, 1 export: + "\00" ;; plain externname + "\01g" ;; name "g" + "\01\00" ;; sortidx func 0 + "\06\06" ;; alias section (6 bytes) + "\01" ;; 1 alias + "\01\00\02" ;; func, 0x00 export alias, instance 2 + "\01g" ;; name "g" +) +(assert_malformed + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\05\04" ;; instance section (4 bytes) + "\01" ;; 1 instance + "\02\00\00" ;; 0x02 is not an instanceexpr + ) + "invalid leading byte (0x2) for instance" +) + +;; alias section (id 6) + +(component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\01\51" ;; core module section (81 bytes) + "\00asm" "\01\00\00\00" ;; core module preamble + "\01\08\02\60\00\00\60\01\7f\00" ;; type section: (func), (func (param i32)) + "\03\03\02\00\01" ;; func section: 2 funcs + "\04\04\01\70\00\01" ;; table section: funcref table + "\05\03\01\00\01" ;; memory section: 1 memory + "\06\06\01\7f\00\41\00\0b" ;; global section: i32 global + "\07\1c\05" ;; export section, 5 exports + "\01f" ;; name "f" + "\00\00" ;; func 0 + "\01g" ;; name "g" + "\00\01" ;; func 1 + "\03mem" ;; name "mem" + "\02\00" ;; memory 0 + "\03tbl" ;; name "tbl" + "\01\00" ;; table 0 + "\04glob" ;; name "glob" + "\03\00" ;; global 0 + "\0a\07\02\02\00\0b\02\00\0b" ;; code section: 2 empty bodies + "\02\04" ;; core instance section (4 bytes) + "\01" ;; 1 core instance + "\00\00\00" ;; instantiate module 0, 0 args + "\06\20" ;; alias section (32 bytes) + "\04" ;; 4 aliases + "\00\00\01\00" ;; core func, 0x01 core export alias, instance 0 + "\01f" ;; name "f" + "\00\01\01\00" ;; core table, core export alias, instance 0 + "\03tbl" ;; name "tbl" + "\00\02\01\00" ;; core memory, core export alias, instance 0 + "\03mem" ;; name "mem" + "\00\03\01\00" ;; core global, core export alias, instance 0 + "\04glob" ;; name "glob" +) + +(component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\01\08" ;; core module section (8 bytes) + "\00asm" "\01\00\00\00" ;; core module preamble + "\03\04" ;; core type section (4 bytes) + "\01" ;; 1 core type + "\60\00\00" ;; core functype ()->() + "\07\02" ;; type section (2 bytes) + "\01" ;; 1 type + "\73" ;; string + "\04\08" ;; component section: nested component (8 bytes) + "\00asm" "\0d\00\01\00" ;; preamble + "\06\13" ;; alias section (19 bytes) + "\04" ;; 4 aliases + "\00\11\02\00\00" ;; core module, 0x02 outer alias, ct=0, idx=0 + "\00\10\02\00\00" ;; core type, outer alias, ct=0, idx=0 + "\03\02\00\00" ;; type, outer alias, ct=0, idx=0 + "\04\02\00\00" ;; component, outer alias, ct=0, idx=0 +) + +(component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\07\02" ;; type section (2 bytes) + "\01" ;; 1 type + "\73" ;; string + "\05\08" ;; instance section (8 bytes) + "\01" ;; 1 instance + "\01\01" ;; inline exports, 1 export: + "\00" ;; plain externname + "\01t" ;; name "t" + "\03\00" ;; sortidx type 0 + "\06\06" ;; alias section (6 bytes) + "\01" ;; 1 alias + "\03\00\00" ;; type, 0x00 export alias, instance 0 + "\01t" ;; name "t" +) + +(assert_malformed + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\07\02" ;; type section (2 bytes) + "\01" ;; 1 type + "\73" ;; string + "\06\05" ;; alias section (5 bytes) + "\01" ;; 1 alias + "\03\03\00\00" ;; 0x03 is not an alias target + ) + "invalid leading byte (0x3) for alias" +) +(assert_malformed + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\06\05" ;; alias section (5 bytes) + "\01" ;; 1 alias + "\06\02\00\00" ;; 0x06 is not a sort + ) + "invalid leading byte (0x6) for component outer alias kind" +) +(assert_malformed + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\06\06" ;; alias section (6 bytes) + "\01" ;; 1 alias + "\00\05\02\00\00" ;; 0x05 is not a core:sort + ) + "invalid leading byte (0x5) for component outer alias kind" +) +(assert_malformed + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\06\06" ;; alias section (6 bytes) + "\01" ;; 1 alias + "\00\13\02\00\00" ;; 0x13 is not a core:sort + ) + "invalid leading byte (0x13) for component outer alias kind" +) + +(assert_malformed + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\05\03" ;; instance section (3 bytes) + "\01" ;; 1 instance + "\01\00" ;; inline exports, 0 exports + "\06\05" ;; alias section (5 bytes) + "\01" ;; 1 alias + "\05\02\00\00" ;; instance is not in outeraliassort + ) + "invalid leading byte (0x5) for component outer alias kind" +) +(assert_malformed + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\06\05" ;; alias section (5 bytes) + "\01" ;; 1 alias + "\01\02\00\00" ;; func is not in outeraliassort + ) + "invalid leading byte (0x1) for component outer alias kind" +) + +(assert_invalid + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\07\02" ;; type section (2 bytes) + "\01" ;; 1 type + "\73" ;; string + "\06\05" ;; alias section (5 bytes) + "\01" ;; 1 alias + "\03\02\02\00" ;; outer alias ct=2: only 1 enclosing scope + ) + "invalid outer alias count of 2" +) +(assert_invalid + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\05\03" ;; instance section (3 bytes) + "\01" ;; 1 instance + "\01\00" ;; inline exports, 0 exports + "\06\06" ;; alias section (6 bytes) + "\01" ;; 1 alias + "\03\00\00" ;; type export alias, instance 0 + "\01t" ;; name "t": no such export + ) + "instance 0 has no export named `t`" +) +(assert_invalid + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\01\08" ;; core module section (8 bytes) + "\00asm" "\01\00\00\00" ;; core module preamble + "\02\04" ;; core instance section (4 bytes) + "\01" ;; 1 core instance + "\00\00\00" ;; instantiate module 0, 0 args + "\06\07" ;; alias section (7 bytes) + "\01" ;; 1 alias + "\00\00\01\00" ;; core func export alias, core instance 0 + "\01f" ;; name "f": no such export + ) + "core instance 0 has no export named `f`" +) + +;; type section (id 7): primitive value types + +(component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\07\0e" ;; type section (14 bytes) + "\0d" ;; 13 types + "\7f" ;; bool + "\7e" ;; s8 + "\7d" ;; u8 + "\7c" ;; s16 + "\7b" ;; u16 + "\7a" ;; s32 + "\79" ;; u32 + "\78" ;; s64 + "\77" ;; u64 + "\76" ;; f32 + "\75" ;; f64 + "\74" ;; char + "\73" ;; string +) + +(component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\07\4f" ;; type section (79 bytes) + "\13" ;; 19 types + "\3f\7f\00" ;; (resource (rep i32)), no dtor + "\72\02" ;; 0x72 record, 2 fields + "\01a" ;; name "a" + "\7f" ;; bool + "\01b" ;; name "b" + "\7d" ;; u8 + "\71\02" ;; 0x71 variant, 2 cases + "\01x" ;; name "x" + "\01\7e" ;; payload present: s8 + "\00" ;; case immediate (must be zero) + "\01y" ;; name "y" + "\00" ;; no payload + "\00" ;; case immediate (must be zero) + "\70\7b" ;; 0x70 (list u16) + "\6f\02\7c\79" ;; 0x6f (tuple s16 u32) + "\6e\02" ;; 0x6e flags, 2 labels + "\02f1" ;; name "f1" + "\02f2" ;; name "f2" + "\6d\02" ;; 0x6d enum, 2 labels + "\02e1" ;; name "e1" + "\02e2" ;; name "e2" + "\6b\7a" ;; 0x6b (option s32) + "\6a\00\00" ;; 0x6a (result) + "\6a\01\77\00" ;; (result u64) + "\6a\00\01\78" ;; (result (error s64)) + "\6a\01\76\01\75" ;; (result f32 (error f64)) + "\69\00" ;; 0x69 (own 0) + "\68\00" ;; 0x68 (borrow 0) + "\66\01\7d" ;; 0x66 (stream u8) + "\66\00" ;; (stream) + "\65\01\73" ;; 0x65 (future string) + "\65\00" ;; (future) + "\70\02" ;; (list ): valtype as typeidx +) + +(assert_malformed + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\07\02" ;; type section (2 bytes) + "\01" ;; 1 type + "\62" ;; 0x62 is unallocated + ) + "invalid leading byte (0x62) for component defined type" +) +(assert_malformed + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\07\02" ;; type section (2 bytes) + "\01" ;; 1 type + "\44" ;; 0x44 is unallocated + ) + "invalid leading byte (0x44) for component defined type" +) +(assert_malformed + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\07\02" ;; type section (2 bytes) + "\01" ;; 1 type + "\3e" ;; 0x3e is unallocated + ) + "invalid leading byte (0x3e) for component defined type" +) + +(assert_malformed + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\07\07" ;; type section (7 bytes) + "\01" ;; 1 type + "\71\01" ;; variant, 1 case + "\01c" ;; name "c" + "\00" ;; no payload + "\01" ;; nonzero case immediate + ) + "invalid leading byte (0x1) for zero byte required" +) + +(assert_invalid + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\07\03" ;; type section (3 bytes) + "\01" ;; 1 type + "\72\00" ;; record, 0 fields + ) + "record type must have at least one field" +) +(assert_invalid + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\07\03" ;; type section (3 bytes) + "\01" ;; 1 type + "\71\00" ;; variant, 0 cases + ) + "variant type must have at least one case" +) +(assert_invalid + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\07\03" ;; type section (3 bytes) + "\01" ;; 1 type + "\6f\00" ;; tuple, 0 types + ) + "tuple type must have at least one type" +) +(assert_invalid + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\07\03" ;; type section (3 bytes) + "\01" ;; 1 type + "\6e\00" ;; flags, 0 labels + ) + "flags must have at least one entry" +) +(assert_invalid + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\07\03" ;; type section (3 bytes) + "\01" ;; 1 type + "\6d\00" ;; enum, 0 labels + ) + "enum type must have at least one variant" +) +(assert_invalid + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\07\87\01" ;; type section (135 bytes) + "\01" ;; 1 type + "\6e\21" ;; flags, 33 labels + "\03f00" ;; name "f00" + "\03f01" ;; name "f01" + "\03f02" ;; name "f02" + "\03f03" ;; name "f03" + "\03f04" ;; name "f04" + "\03f05" ;; name "f05" + "\03f06" ;; name "f06" + "\03f07" ;; name "f07" + "\03f08" ;; name "f08" + "\03f09" ;; name "f09" + "\03f10" ;; name "f10" + "\03f11" ;; name "f11" + "\03f12" ;; name "f12" + "\03f13" ;; name "f13" + "\03f14" ;; name "f14" + "\03f15" ;; name "f15" + "\03f16" ;; name "f16" + "\03f17" ;; name "f17" + "\03f18" ;; name "f18" + "\03f19" ;; name "f19" + "\03f20" ;; name "f20" + "\03f21" ;; name "f21" + "\03f22" ;; name "f22" + "\03f23" ;; name "f23" + "\03f24" ;; name "f24" + "\03f25" ;; name "f25" + "\03f26" ;; name "f26" + "\03f27" ;; name "f27" + "\03f28" ;; name "f28" + "\03f29" ;; name "f29" + "\03f30" ;; name "f30" + "\03f31" ;; name "f31" + "\03f32" ;; name "f32" + ) + "cannot have more than 32 flags" +) +(assert_invalid + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\07\03" ;; type section (3 bytes) + "\01" ;; 1 type + "\70\05" ;; (list ): no such type + ) + "type index out of bounds" +) +(assert_invalid + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\07\04" ;; type section (4 bytes) + "\02" ;; 2 types + "\73" ;; string + "\69\00" ;; (own 0): not a resource type + ) + "type index 0 is not a resource type" +) +(assert_invalid + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\07\04" ;; type section (4 bytes) + "\01" ;; 1 type + "\66\01\74" ;; (stream char) + ) + "is not valid at this time" +) + +;; function types + +(component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\07\10" ;; type section (16 bytes) + "\03" ;; 3 types + "\40\00\01\00" ;; 0x40 (func): 0 params, resultlist 0x01 0x00 + "\40\01" ;; (func): 1 param: + "\01p" ;; name "p" + "\7f" ;; bool + "\00\79" ;; resultlist: 0x00 u32 + "\43\00\01\00" ;; 0x43 (func async) +) +(assert_malformed + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\07\05" ;; type section (5 bytes) + "\01" ;; 1 type + "\40\00" ;; (func): 0 params + "\01\01" ;; resultlist 0x01 must be followed by 0x00 + ) + "invalid leading byte (0x1) for number of results" +) +(assert_malformed + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\07\05" ;; type section (5 bytes) + "\01" ;; 1 type + "\40\00" ;; (func): 0 params + "\02\00" ;; 0x02 is not a resultlist + ) + "invalid leading byte (0x2) for component function results" +) + +;; resource types + +(component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\01\51" ;; core module section (81 bytes) + "\00asm" "\01\00\00\00" ;; core module preamble + "\01\08\02\60\00\00\60\01\7f\00" ;; type section: (func), (func (param i32)) + "\03\03\02\00\01" ;; func section: 2 funcs + "\04\04\01\70\00\01" ;; table section: funcref table + "\05\03\01\00\01" ;; memory section: 1 memory + "\06\06\01\7f\00\41\00\0b" ;; global section: i32 global + "\07\1c\05" ;; export section, 5 exports + "\01f" ;; name "f" + "\00\00" ;; func 0 + "\01g" ;; name "g" + "\00\01" ;; func 1 + "\03mem" ;; name "mem" + "\02\00" ;; memory 0 + "\03tbl" ;; name "tbl" + "\01\00" ;; table 0 + "\04glob" ;; name "glob" + "\03\00" ;; global 0 + "\0a\07\02\02\00\0b\02\00\0b" ;; code section: 2 empty bodies + "\02\04" ;; core instance section (4 bytes) + "\01" ;; 1 core instance + "\00\00\00" ;; instantiate module 0, 0 args + "\06\0d" ;; alias section (13 bytes) + "\02" ;; 2 aliases + "\00\00\01\00" ;; core func, core export alias, instance 0 + "\01f" ;; name "f" + "\00\00\01\00" ;; core func, core export alias, instance 0 + "\01g" ;; name "g" + "\07\08" ;; type section (8 bytes) + "\02" ;; 2 types + "\3f\7f\00" ;; (resource (rep i32)), no dtor + "\3f\7f\01\01" ;; (resource (rep i32) (dtor )) +) + +;; component types and instance types + +(component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\07\17" ;; type section (23 bytes) + "\01" ;; 1 type + "\41\04" ;; 0x41 componenttype, 4 decls + "\01\73" ;; 0x01 type: string + "\03\00" ;; 0x03 importdecl, plain externname: + "\01a" ;; name "a" + "\03\00\00" ;; (type (eq 0)) + "\01\40\00\01\00" ;; 0x01 type: (func) + "\04\00" ;; 0x04 exportdecl, plain externname: + "\01b" ;; name "b" + "\01\02" ;; (func (type 2)) +) +(component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\07\02" ;; type section (2 bytes) + "\01" ;; 1 type + "\73" ;; string + "\07\13" ;; type section (19 bytes) + "\01" ;; 1 type + "\42\03" ;; 0x42 instancetype, 3 decls + "\00\60\00\00" ;; 0x00 core type: functype ()->() + "\02\03\02\01\00" ;; 0x02 alias: type, outer, ct=1, idx=0 + "\04\00" ;; 0x04 exportdecl, plain externname: + "\01t" ;; name "t" + "\03\00\00" ;; (type (eq 0)) +) +(assert_malformed + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\07\05" ;; type section (5 bytes) + "\01" ;; 1 type + "\41\01" ;; componenttype, 1 decl + "\05\73" ;; 0x05 is not a declarator + ) + "invalid leading byte (0x5) for component or instance type declaration" +) +(assert_malformed + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\07\09" ;; type section (9 bytes) + "\01" ;; 1 type + "\42\01" ;; instancetype, 1 decl + "\03\00" ;; 0x03 importdecl is not an instancedecl: + "\01a" ;; name "a" + "\03\01" ;; (type (sub resource)) + ) + "invalid leading byte (0x3) for component or instance type declaration" +) +(assert_invalid + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\07\07" ;; type section (7 bytes) + "\01" ;; 1 type + "\41\01" ;; componenttype, 1 decl + "\01\3f\7f\00" ;; 0x01 type: resource type + ) + "resources can only be defined within a concrete component" +) + +;; core type section (id 3): core functypes and core module types. Because +;; the 0x50 opcode is shared with a non-final core:subtype, a non-final +;; `sub` in this position takes a 0x00 prefix (`0x00 0x50 ...`) while a bare +;; 0x50 is a core:moduletype (pre-1.0 wart). +(component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\03\04" ;; core type section (4 bytes) + "\01" ;; 1 core type + "\60\00\00" ;; core functype ()->() + "\03\07" ;; core type section (7 bytes) + "\01" ;; 1 core type + "\00\50" ;; 0x00-prefixed non-final subtype + "\00" ;; 0 supertypes + "\60\00\00" ;; core functype ()->() + "\03\18" ;; core type section (24 bytes) + "\01" ;; 1 core type + "\50\04" ;; 0x50 core:moduletype, 4 decls + "\01\60\00\00" ;; 0x01 type: core functype ()->() + "\00" ;; 0x00 import: + "\01a" ;; name "a" + "\01b" ;; name "b" + "\00\00" ;; (func (type 0)) + "\02\10\01\01\00" ;; 0x02 alias: 0x10 type, 0x01 outer, ct=1, idx=0 + "\03" ;; 0x03 exportdecl: + "\01e" ;; name "e" + "\00\00" ;; (func (type 0)) +) +(assert_malformed + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\03\07" ;; core type section (7 bytes) + "\01" ;; 1 core type + "\50\01" ;; core:moduletype, 1 decl + "\04\60\00\00" ;; 0x04 is not a core:moduledecl + ) + "invalid leading byte (0x4) for type definition" +) +(assert_malformed + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\03\08" ;; core type section (8 bytes) + "\01" ;; 1 core type + "\50\01" ;; core:moduletype, 1 decl + "\02\00\01\01\00" ;; core:alias sort must be 0x10 (type) + ) + "invalid leading byte (0x0) for outer alias kind" +) +(assert_malformed + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\03\08" ;; core type section (8 bytes) + "\01" ;; 1 core type + "\50\01" ;; core:moduletype, 1 decl + "\02\10\00\01\00" ;; core:alias target must be 0x01 (outer) + ) + "invalid leading byte (0x0) for outer alias target" +) + +(assert_invalid + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\03\0a" ;; core type section (10 bytes) + "\01" ;; 1 core type + "\50\02" ;; core:moduletype, 2 decls + "\01\50\00" ;; 0x01 type: nested core:moduletype + "\01\60\00\00" ;; 0x01 type: core functype + ) + "invalid leading byte" +) + +(component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\07\04" ;; type section (4 bytes) + "\01" ;; 1 type + "\67\7d\03" ;; (list u8 3) +) + +(component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\07\04" ;; type section (4 bytes) + "\01" ;; 1 type + "\63\73\79" ;; (map string u32) +) + +;; canonical section (id 8) + +(component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\01\9b\01" ;; core module section: f, g, run, cb, dtor, realloc, mem, tbl (155 bytes) + "\00asm" "\01\00\00\00" ;; core module preamble + "\01\20\06" ;; type section, 6 types + "\60\00\00" ;; ()->() + "\60\02\7f\7f\00" ;; (i32,i32)->() + "\60\00\01\7f" ;; ()->(i32) + "\60\03\7f\7f\7f\01\7f" ;; (i32,i32,i32)->(i32) + "\60\01\7f\00" ;; (i32)->() + "\60\04\7f\7f\7f\7f\01\7f" ;; (i32,i32,i32,i32)->(i32) + "\03\07\06\00\01\02\03\04\05" ;; func section: 6 funcs + "\04\04\01\70\00\01" ;; table section: funcref table + "\05\03\01\00\01" ;; memory section: 1 memory + "\06\06\01\7f\00\41\00\0b" ;; global section: i32 global + "\07\38\09" ;; export section, 9 exports + "\01f" ;; name "f" + "\00\00" ;; func 0 + "\01g" ;; name "g" + "\00\01" ;; func 1 + "\03run" ;; name "run" + "\00\02" ;; func 2 + "\02cb" ;; name "cb" + "\00\03" ;; func 3 + "\04dtor" ;; name "dtor" + "\00\04" ;; func 4 + "\07realloc" ;; name "realloc" + "\00\05" ;; func 5 + "\03mem" ;; name "mem" + "\02\00" ;; memory 0 + "\03tbl" ;; name "tbl" + "\01\00" ;; table 0 + "\04glob" ;; name "glob" + "\03\00" ;; global 0 + "\0a\19\06" ;; code section, 6 bodies + "\02\00\0b" ;; f + "\02\00\0b" ;; g + "\04\00\41\00\0b" ;; run: i32.const 0 + "\04\00\41\00\0b" ;; cb: i32.const 0 + "\02\00\0b" ;; dtor + "\04\00\41\00\0b" ;; realloc: i32.const 0 + "\02\04" ;; core instance section (4 bytes) + "\01" ;; 1 core instance + "\00\00\00" ;; instantiate module 0, 0 args + "\06\41" ;; alias section (65 bytes) + "\08" ;; 8 aliases + "\00\00\01\00" ;; core func f: ()->() + "\01f" ;; name "f" + "\00\00\01\00" ;; core func g: (i32,i32)->() + "\01g" ;; name "g" + "\00\00\01\00" ;; core func run: ()->(i32) + "\03run" ;; name "run" + "\00\00\01\00" ;; core func cb: (i32,i32,i32)->(i32) + "\02cb" ;; name "cb" + "\00\00\01\00" ;; core func dtor: (i32)->() + "\04dtor" ;; name "dtor" + "\00\00\01\00" ;; core func realloc + "\07realloc" ;; name "realloc" + "\00\02\01\00" ;; core memory + "\03mem" ;; name "mem" + "\00\01\01\00" ;; core table + "\03tbl" ;; name "tbl" + "\07\19" ;; type section (25 bytes) + "\06" ;; 6 types + "\40\00\01\00" ;; type 0: (func) + "\40\01" ;; type 1: (func (param "p" string)): + "\01p" ;; name "p" + "\73" ;; string + "\01\00" ;; no result + "\43\00\01\00" ;; type 2: (func async) + "\66\01\7d" ;; type 3: (stream u8) + "\65\00" ;; type 4: (future) + "\3f\7f\01\04" ;; type 5: (resource (rep i32) (dtor )) + "\03\05" ;; core type section (5 bytes) + "\01" ;; 1 core type + "\60\01\7f\00" ;; core functype (i32)->() + "\08\93\01" ;; canon section (147 bytes) + "\2f" ;; 47 canons + "\00\00\00\00\00" ;; lift core func 0 (f), no opts, type 0 + "\00\00\01\03\00\03\00\04\05\01" ;; lift core func 1 (g), utf8 + (memory 0) + (realloc 5), type 1 + "\00\00\02\02\06\07\03\02" ;; lift core func 2 (run), async + (callback 3), type 2 + "\00\00\00\01\05\00\00" ;; lift core func 0, (post-return 0), type 0 + "\01\00\00\01\01" ;; lower func 0, string-encoding=utf16 + "\01\00\00\01\02" ;; lower func 0, string-encoding=latin1+utf16 + "\02\05" ;; 0x02 resource.new (type 5) + "\03\05" ;; 0x03 resource.drop (type 5) + "\04\05" ;; 0x04 resource.rep (type 5) + "\24" ;; 0x24 backpressure.inc + "\25" ;; 0x25 backpressure.dec + "\09\01\00\00" ;; 0x09 task.return, no result, no opts + "\09\00\79\00" ;; task.return (result u32), no opts + "\05" ;; 0x05 task.cancel + "\0a\7f\00" ;; 0x0a context.get i32 0 + "\0b\7f\00" ;; 0x0b context.set i32 0 + "\06\00" ;; 0x06 subtask.cancel + "\06\01" ;; subtask.cancel async + "\0d" ;; 0x0d subtask.drop + "\0e\03" ;; 0x0e stream.new (type 3) + "\0f\03\02\03\00\04\05" ;; 0x0f stream.read, (memory 0) (realloc 5) + "\10\03\02\03\00\04\05" ;; 0x10 stream.write, (memory 0) (realloc 5) + "\11\03\00" ;; 0x11 stream.cancel-read + "\12\03\01" ;; 0x12 stream.cancel-write async + "\13\03" ;; 0x13 stream.drop-readable + "\14\03" ;; 0x14 stream.drop-writable + "\15\04" ;; 0x15 future.new (type 4) + "\16\04\02\03\00\04\05" ;; 0x16 future.read, (memory 0) (realloc 5) + "\17\04\02\03\00\04\05" ;; 0x17 future.write, (memory 0) (realloc 5) + "\18\04\00" ;; 0x18 future.cancel-read + "\19\04\01" ;; 0x19 future.cancel-write async + "\1a\04" ;; 0x1a future.drop-readable + "\1b\04" ;; 0x1b future.drop-writable + "\1f" ;; 0x1f waitable-set.new + "\20\00\00" ;; 0x20 waitable-set.wait (memory 0) + "\21\01\00" ;; 0x21 waitable-set.poll cancellable (memory 0) + "\22" ;; 0x22 waitable-set.drop + "\23" ;; 0x23 waitable.join + "\26" ;; 0x26 thread.index + "\27\00\00" ;; 0x27 thread.new-indirect (core type 0) (table 0) + "\28" ;; 0x28 thread.resume-later + "\29\00" ;; 0x29 thread.suspend + "\0c\01" ;; 0x0c thread.yield cancellable + "\2a\00" ;; 0x2a thread.suspend-then-resume + "\2b\00" ;; 0x2b thread.yield-then-resume + "\2c\00" ;; 0x2c thread.suspend-then-promote + "\2d\01" ;; 0x2d thread.yield-then-promote cancellable +) + +(assert_malformed + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\08\02" ;; canon section (2 bytes) + "\01" ;; 1 canon + "\07" ;; 0x07 is unallocated + ) + "invalid leading byte (0x7) for canonical function" +) +(assert_malformed + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\08\02" ;; canon section (2 bytes) + "\01" ;; 1 canon + "\2e" ;; 0x2e is unallocated + ) + "invalid leading byte (0x2e) for canonical function" +) +(assert_malformed + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\08\02" ;; canon section (2 bytes) + "\01" ;; 1 canon + "\43" ;; 0x43 is unallocated + ) + "invalid leading byte (0x43) for canonical function" +) + +(assert_malformed + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\08\06" ;; canon section (6 bytes) + "\01" ;; 1 canon + "\00\01\00\00\00" ;; lift with sort byte 0x01 + ) + "invalid leading byte (0x1) for canonical function lift" +) +(assert_malformed + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\08\05" ;; canon section (5 bytes) + "\01" ;; 1 canon + "\01\01\00\00" ;; lower with sort byte 0x01 + ) + "invalid leading byte (0x1) for canonical function lower" +) + +(assert_malformed + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\07\05" ;; type section (5 bytes) + "\01" ;; 1 type + "\40\00\01\00" ;; (func) + "\0a\06" ;; import section (6 bytes) + "\01" ;; 1 import + "\00" ;; plain externname + "\01f" ;; name "f" + "\01\00" ;; func (type 0) + "\08\06" ;; canon section (6 bytes) + "\01" ;; 1 canon + "\01\00\00\01\0a" ;; lower func 0, 1 opt: 0x0a is unallocated + ) + "invalid leading byte (0xa) for canonical option" +) + +(assert_malformed + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\08\03" ;; canon section (3 bytes) + "\01" ;; 1 canon + "\0c\02" ;; thread.yield with flag 0x02 + ) + "invalid boolean value" +) +(assert_malformed + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\08\04" ;; canon section (4 bytes) + "\01" ;; 1 canon + "\20\02\00" ;; waitable-set.wait with flag 0x02 + ) + "invalid boolean value" +) + +;; import section (id 10) and export section (id 11) + +(component definition binary + "\00asm" "\0d\00\01\00" ;; preamble + "\07\05" ;; type section (5 bytes) + "\01" ;; 1 type + "\40\00\01\00" ;; (func) + "\0a\11" ;; import section (17 bytes) + "\03" ;; 3 imports + "\00" ;; 0x00-prefixed externname + "\01a" ;; name "a" + "\01\00" ;; func (type 0) + "\01" ;; 0x01-prefixed externname: same meaning + "\01b" ;; name "b" + "\01\00" ;; func (type 0) + "\02" ;; 0x02-prefixed externname + "\01c" ;; name "c" + "\00" ;; 0 attributes + "\01\00" ;; func (type 0) +) + +(component definition binary + "\00asm" "\0d\00\01\00" ;; preamble + "\07\03" ;; type section (3 bytes) + "\01" ;; 1 type + "\42\00" ;; empty instancetype + "\0a\2f" ;; import section (47 bytes) + "\02" ;; 2 imports + "\02" ;; externname with attributes + "\02i1" ;; name "i1" + "\01" ;; 1 attribute: + "\00" ;; 0x00 implements: + "\0cmy:dep/iface" ;; name "my:dep/iface" + "\05\00" ;; instance (type 0) + "\02" ;; externname with attributes + "\02i2" ;; name "i2" + "\01" ;; 1 attribute: + "\02" ;; 0x02 external-id: + "\10some-external-id" ;; name "some-external-id" + "\05\00" ;; instance (type 0) +) + +(component definition binary + "\00asm" "\0d\00\01\00" ;; preamble + "\03\03" ;; core type section (3 bytes) + "\01" ;; 1 core type + "\50\00" ;; empty core:moduletype + "\07\08" ;; type section (8 bytes) + "\03" ;; 3 types + "\40\00\01\00" ;; (func) + "\42\00" ;; empty instancetype + "\73" ;; string + "\0a\1e" ;; import section (30 bytes) + "\05" ;; 5 imports + "\00" ;; plain externname + "\01m" ;; name "m" + "\00\11\00" ;; 0x00 0x11 core module (core type 0) + "\00" ;; plain externname + "\01f" ;; name "f" + "\01\00" ;; 0x01 func (type 0) + "\00" ;; plain externname + "\02t1" ;; name "t1" + "\03\00\02" ;; 0x03 type, bound 0x00: (eq 2) + "\00" ;; plain externname + "\02t2" ;; name "t2" + "\03\01" ;; 0x03 type, bound 0x01: (sub resource) + "\00" ;; plain externname + "\01i" ;; name "i" + "\05\01" ;; 0x05 instance (type 1) +) + +(component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\04\15" ;; component section: nested component (21 bytes) + "\00asm" "\0d\00\01\00" ;; preamble + "\07\03" ;; type section (3 bytes) + "\01" ;; 1 type + "\41\00" ;; empty componenttype + "\0a\06" ;; import section (6 bytes) + "\01" ;; 1 import + "\00" ;; plain externname + "\01c" ;; name "c" + "\04\00" ;; 0x04 component (type 0) +) + +(assert_malformed + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\0a\06" ;; import section (6 bytes) + "\01" ;; 1 import + "\03" ;; 0x03 is not a nameattributes prefix + "\01a" ;; name "a" + "\01\00" ;; func (type 0) + ) + "invalid leading byte (0x3) for component name" +) +(assert_malformed + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\0a\0a" ;; import section (10 bytes) + "\01" ;; 1 import + "\02" ;; externname with attributes + "\01a" ;; name "a" + "\01" ;; 1 attribute: + "\03" ;; 0x03 is not an attribute + "\01x" ;; name "x" + "\01\00" ;; func (type 0) + ) + "invalid leading byte (0x3) for name option" +) +(assert_malformed + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\0a\06" ;; import section (6 bytes) + "\01" ;; 1 import + "\00" ;; plain externname + "\01t" ;; name "t" + "\03\02" ;; 0x02 is not a typebound + ) + "invalid leading byte (0x2) for type bound" +) +(assert_malformed + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\0a\06" ;; import section (6 bytes) + "\01" ;; 1 import + "\00" ;; plain externname + "\01x" ;; name "x" + "\06\00" ;; 0x06 is not an externtype + ) + "invalid leading byte (0x6) for component external kind" +) +(assert_malformed + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\0a\06" ;; import section (6 bytes) + "\01" ;; 1 import + "\00" ;; plain externname + "\01m" ;; name "m" + "\00\00" ;; externtype 0x00 must be followed by 0x11 + ) + "invalid leading byte (0x0) for component external kind" +) + +(assert_malformed + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\0a\05" ;; import section (5 bytes) + "\01" ;; 1 import + "\00" ;; plain externname + "\7f\61\62" ;; name length 127, only 2 bytes follow + ) + "unexpected end-of-file" +) +(assert_malformed + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\0a\07" ;; import section (7 bytes) + "\01" ;; 1 import + "\00" ;; plain externname + "\02\ff\fe" ;; name is not valid UTF-8 + "\01\00" ;; func (type 0) + ) + "malformed UTF-8 encoding" +) + +(assert_invalid + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\07\05" ;; type section (5 bytes) + "\01" ;; 1 type + "\40\00\01\00" ;; (func) + "\0a\08" ;; import section (8 bytes) + "\01" ;; 1 import + "\00" ;; plain externname + "\03Foo" ;; name "Foo": not kebab-case + "\01\00" ;; func (type 0) + ) + "is not a valid extern name" +) +(assert_invalid + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\07\05" ;; type section (5 bytes) + "\01" ;; 1 type + "\40\00\01\00" ;; (func) + "\0a\05" ;; import section (5 bytes) + "\01" ;; 1 import + "\00" ;; plain externname + "\00" ;; empty name + "\01\00" ;; func (type 0) + ) + "is not a valid extern name" +) +(assert_invalid + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\07\03" ;; type section (3 bytes) + "\01" ;; 1 type + "\42\00" ;; empty instancetype + "\0a\15" ;; import section (21 bytes) + "\01" ;; 1 import + "\02" ;; externname with attributes + "\01i" ;; name "i" + "\02" ;; 2 attributes: + "\00" ;; implements: + "\05a:b/x" ;; name "a:b/x" + "\00" ;; implements again: at most one of each kind + "\05a:b/y" ;; name "a:b/y" + "\05\00" ;; instance (type 0) + ) + "duplicate 'implements' option in name" +) + +(component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\01\1f" ;; core module section (31 bytes) + "\00asm" "\01\00\00\00" ;; core module preamble + "\01\04\01\60\00\00" ;; type section: (func) + "\03\02\01\00" ;; func section: 1 func of type 0 + "\07\05\01" ;; export section, 1 export + "\01f" ;; name "f" + "\00\00" ;; func 0 + "\0a\04\01\02\00\0b" ;; code section: 1 empty body + "\02\04" ;; core instance section (4 bytes) + "\01" ;; 1 core instance + "\00\00\00" ;; instantiate module 0, 0 args + "\06\07" ;; alias section (7 bytes) + "\01" ;; 1 aliases + "\00\00\01\00" ;; core func, core export alias, instance 0 + "\01f" ;; name "f" + "\07\05" ;; type section (5 bytes) + "\01" ;; 1 type + "\40\00\01\00" ;; (func) + "\08\06" ;; canon section (6 bytes) + "\01" ;; 1 canon + "\00\00\00\00\00" ;; lift core func 0, no opts, type 0 + "\0b\11" ;; export section (17 bytes) + "\02" ;; 2 exports + "\00" ;; plain externname + "\02e1" ;; name "e1" + "\01\00" ;; sortidx func 0 + "\00" ;; no ascribed type + "\00" ;; plain externname + "\02e2" ;; name "e2" + "\01\00" ;; sortidx func 0 + "\01\01\00" ;; ascribed type: func (type 0) +) +(component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\01\08" ;; core module section (8 bytes) + "\00asm" "\01\00\00\00" ;; core module preamble + "\0b\08" ;; export section (8 bytes) + "\01" ;; 1 export + "\00" ;; plain externname + "\01m" ;; name "m" + "\00\11\00" ;; sortidx core module 0 + "\00" ;; no ascribed type +) +(assert_malformed + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\01\1f" ;; core module section (31 bytes) + "\00asm" "\01\00\00\00" ;; core module preamble + "\01\04\01\60\00\00" ;; type section: (func) + "\03\02\01\00" ;; func section: 1 func of type 0 + "\07\05\01" ;; export section, 1 export + "\01f" ;; name "f" + "\00\00" ;; func 0 + "\0a\04\01\02\00\0b" ;; code section: 1 empty body + "\02\04" ;; core instance section (4 bytes) + "\01" ;; 1 core instance + "\00\00\00" ;; instantiate module 0, 0 args + "\06\07" ;; alias section (7 bytes) + "\01" ;; 1 aliases + "\00\00\01\00" ;; core func, core export alias, instance 0 + "\01f" ;; name "f" + "\07\05" ;; type section (5 bytes) + "\01" ;; 1 type + "\40\00\01\00" ;; (func) + "\08\06" ;; canon section (6 bytes) + "\01" ;; 1 canon + "\00\00\00\00\00" ;; lift core func 0, no opts, type 0 + "\0b\07" ;; export section (7 bytes) + "\01" ;; 1 export + "\00" ;; plain externname + "\01e" ;; name "e" + "\01\00" ;; sortidx func 0 + "\02" ;; optional-externtype byte must be 0x00 or 0x01 + ) + "invalid leading byte (0x2) for optional component export type" +) +(assert_malformed + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\01\1f" ;; core module section (31 bytes) + "\00asm" "\01\00\00\00" ;; core module preamble + "\01\04\01\60\00\00" ;; type section: (func) + "\03\02\01\00" ;; func section: 1 func of type 0 + "\07\05\01" ;; export section, 1 export + "\01f" ;; name "f" + "\00\00" ;; func 0 + "\0a\04\01\02\00\0b" ;; code section: 1 empty body + "\02\04" ;; core instance section (4 bytes) + "\01" ;; 1 core instance + "\00\00\00" ;; instantiate module 0, 0 args + "\06\07" ;; alias section (7 bytes) + "\01" ;; 1 aliases + "\00\00\01\00" ;; core func, core export alias, instance 0 + "\01f" ;; name "f" + "\07\05" ;; type section (5 bytes) + "\01" ;; 1 type + "\40\00\01\00" ;; (func) + "\08\06" ;; canon section (6 bytes) + "\01" ;; 1 canon + "\00\00\00\00\00" ;; lift core func 0, no opts, type 0 + "\0b\07" ;; export section (7 bytes) + "\01" ;; 1 export + "\00" ;; plain externname + "\01e" ;; name "e" + "\06\00" ;; 0x06 is not a sort + "\00" ;; no ascribed type + ) + "invalid leading byte (0x6) for component external kind" +) + +;; component section (id 4) + +(component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\04\08" ;; component section (8 bytes) + "\00asm" "\0d\00\01\00" ;; preamble +) +(component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\04\16" ;; component section (22 bytes) + "\00asm" "\0d\00\01\00" ;; preamble + "\04\0c" ;; component section (nested twice) (12 bytes) + "\00asm" "\0d\00\01\00" ;; preamble + "\07\02" ;; type section (2 bytes) + "\01" ;; 1 type + "\73" ;; string +) +(assert_malformed + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\04\08" ;; component section (8 bytes) + "\00asm" "\0c\00\01\00" ;; nested preamble with bad version + ) + "unknown binary version" +) +(assert_malformed + (component binary + "\00asm" "\0d\00\01\00" ;; preamble + "\04\08" ;; component section (8 bytes) + "\00asm" "\01\00\00\00" ;; a core module preamble, not a component + ) + "expected a version header for a component" +) diff --git a/test/linking/tags.wast b/test/linking/tags.wast new file mode 100644 index 00000000..e3f5b5c3 --- /dev/null +++ b/test/linking/tags.wast @@ -0,0 +1,150 @@ +;; Linking tests for core tags: satisfying tag imports from real and +;; synthesized core instances, aliasing tags out of instances, and +;; per-instance generativity of tags. + +;; A tag defined in its own module and imported by a thrower and a catcher +;; via whole-instance arguments: the catch matches exactly the thrower's tag. +(component + (core module $Tag (tag (export "t") (param i32))) + (core module $Thrower + (import "tag" "t" (tag $t (param i32))) + (func (export "throw-if") (param i32) + (if (local.get 0) + (then (throw $t (local.get 0)))))) + (core module $Catcher + (import "tag" "t" (tag $t (param i32))) + (import "thrower" "throw-if" (func $throw-if (param i32))) + (func (export "run") (param i32) (result i32) + (block $h (result i32) + (try_table (catch $t $h) + (call $throw-if (local.get 0))) + (return (i32.const 99))))) + (core instance $tag (instantiate $Tag)) + (core instance $thrower (instantiate $Thrower (with "tag" (instance $tag)))) + (core instance $catcher (instantiate $Catcher + (with "tag" (instance $tag)) + (with "thrower" (instance $thrower)))) + (func (export "run") (param "x" u32) (result u32) + (canon lift (core func $catcher "run"))) +) + +(assert_return (invoke "run" (u32.const 42)) (u32.const 42)) +(assert_return (invoke "run" (u32.const 0)) (u32.const 99)) + +;; Renaming a tag export to satisfy an import: synthesized instances alias +;; the same underlying tag "t" as "exn", so the catch still matches. +(component + (core module $Tag (tag (export "t") (param i32))) + (core module $Thrower + (import "env" "exn" (tag $t (param i32))) + (func (export "throw") (param i32) + (throw $t (local.get 0)))) + (core module $Catcher + (import "env" "exn" (tag $t (param i32))) + (import "thrower" "throw" (func $throw (param i32))) + (func (export "run") (param i32) (result i32) + (block $h (result i32) + (try_table (catch $t $h) + (call $throw (local.get 0))) + (return (i32.const 99))))) + (core instance $tag (instantiate $Tag)) + (core instance $thrower (instantiate $Thrower + (with "env" (instance (export "exn" (tag $tag "t")))))) + (core instance $catcher (instantiate $Catcher + (with "env" (instance (export "exn" (tag $tag "t")))) + (with "thrower" (instance $thrower)))) + (func (export "run") (param "x" u32) (result u32) + (canon lift (core func $catcher "run"))) +) + +(assert_return (invoke "run" (u32.const 7)) (u32.const 7)) + +;; Aliasing a core tag out of an instance and tupling it into a synthesized +;; instance: the tag still identifies the original. +(component + (core module $Tag (tag (export "t") (param i32))) + (core module $Thrower + (import "tag" "t" (tag $t (param i32))) + (func (export "throw") (param i32) + (throw $t (local.get 0)))) + (core module $Catcher + (import "tag" "t" (tag $t (param i32))) + (import "thrower" "throw" (func $throw (param i32))) + (func (export "run") (param i32) (result i32) + (block $h (result i32) + (try_table (catch $t $h) + (call $throw (local.get 0))) + (return (i32.const 99))))) + (core instance $tag (instantiate $Tag)) + (alias core export $tag "t" (core tag $t)) + (core instance $syn (export "t" (tag $t))) + (core instance $thrower (instantiate $Thrower (with "tag" (instance $syn)))) + (core instance $catcher (instantiate $Catcher + (with "tag" (instance $syn)) + (with "thrower" (instance $thrower)))) + (func (export "run") (param "x" u32) (result u32) + (canon lift (core func $catcher "run"))) +) + +(assert_return (invoke "run" (u32.const 13)) (u32.const 13)) + +;; Tags are generative per instance: two instances of one tag module define +;; distinct tags, so a catch only matches throws of the tag it imported. +(component + (core module $Tag (tag (export "t") (param i32))) + (core module $Thrower + (import "tag" "t" (tag $t (param i32))) + (func (export "throw") (param i32) + (throw $t (local.get 0)))) + (core module $Catcher + (import "tag" "t" (tag $t (param i32))) + (import "a" "throw" (func $throw-a (param i32))) + (import "b" "throw" (func $throw-b (param i32))) + (func (export "run-a") (param i32) (result i32) + (block $all + (block $h (result i32) + (try_table (catch $t $h) (catch_all $all) + (call $throw-a (local.get 0))) + (return (i32.const 99))) + (return)) + (i32.const 77)) + (func (export "run-b") (param i32) (result i32) + (block $all + (block $h (result i32) + (try_table (catch $t $h) (catch_all $all) + (call $throw-b (local.get 0))) + (return (i32.const 99))) + (return)) + (i32.const 77))) + (core instance $tag-a (instantiate $Tag)) + (core instance $tag-b (instantiate $Tag)) + (core instance $ta (instantiate $Thrower (with "tag" (instance $tag-a)))) + (core instance $tb (instantiate $Thrower (with "tag" (instance $tag-b)))) + (core instance $c (instantiate $Catcher + (with "tag" (instance $tag-a)) + (with "a" (instance $ta)) + (with "b" (instance $tb)))) + (func (export "run-a") (param "x" u32) (result u32) + (canon lift (core func $c "run-a"))) + (func (export "run-b") (param "x" u32) (result u32) + (canon lift (core func $c "run-b"))) +) + +(assert_return (invoke "run-a" (u32.const 42)) (u32.const 42)) +(assert_return (invoke "run-b" (u32.const 42)) (u32.const 77)) + +;; Aliasing a non-tag export as a core tag is a sort mismatch. +(assert_invalid + (component + (core module $M (func (export "f"))) + (core instance $i (instantiate $M)) + (alias core export $i "f" (core tag $t))) + "export `f` for core instance 0 is not a tag") + +;; A synthesized core instance cannot export an out-of-bounds tag index. +(assert_invalid + (component + (core module $M (func (export "f"))) + (core instance $i (instantiate $M)) + (core instance (export "t" (tag 0)))) + "unknown tag 0: tag index out of bounds") diff --git a/test/linking/unit.wast b/test/linking/unit.wast index da76b5b9..17ebc7c4 100644 --- a/test/linking/unit.wast +++ b/test/linking/unit.wast @@ -1945,3 +1945,171 @@ (assert_return (invoke "direct") (u32.const 1)) (assert_return (invoke "wrapped") (u32.const 2)) (assert_return (invoke "direct") (u32.const 3)) + +;; Linking a core funcref table two ways: a client's table import is +;; satisfied once by a whole provider instance and once by a synthesized +;; instance renaming a second provider's table. Indirect calls land in the +;; linked table, and a table.set through one client is invisible to the other. +(component + (core module $T40 + (func $f (result i32) (i32.const 40)) + (table (export "tbl") 1 funcref) + (elem (i32.const 0) func $f)) + (core module $T50 + (func $f (result i32) (i32.const 50)) + (table (export "funcs") 1 funcref) + (elem (i32.const 0) func $f)) + (core module $Client + (type $t (func (result i32))) + (import "env" "tbl" (table 1 funcref)) + (func $sixty (result i32) (i32.const 60)) + (elem declare func $sixty) + (func (export "set-sixty") + (table.set (i32.const 0) (ref.func $sixty))) + (func (export "call") (result i32) + (call_indirect (type $t) (i32.const 0)))) + (core instance $t40 (instantiate $T40)) + (core instance $t50 (instantiate $T50)) + (core instance $a (instantiate $Client (with "env" (instance $t40)))) + (core instance $b (instantiate $Client + (with "env" (instance (export "tbl" (table $t50 "funcs")))))) + (func (export "call-a") (result u32) (canon lift (core func $a "call"))) + (func (export "call-b") (result u32) (canon lift (core func $b "call"))) + (func (export "set-sixty-a") (canon lift (core func $a "set-sixty"))) +) + +(assert_return (invoke "call-a") (u32.const 40)) +(assert_return (invoke "call-b") (u32.const 50)) +(assert_return (invoke "set-sixty-a")) +(assert_return (invoke "call-a") (u32.const 60)) +(assert_return (invoke "call-b") (u32.const 50)) + +;; Aliasing core globals out of an instance and feeding them to another +;; module through a synthesized instance: the immutable global's value and +;; live updates to the mutable i64 global both flow through the alias. +(component + (core module $P + (global (export "gi") i32 (i32.const 30)) + (global $g64 (export "g64") (mut i64) (i64.const 7)) + (func (export "bump64") + (global.set $g64 (i64.add (global.get $g64) (i64.const 1))))) + (core instance $p (instantiate $P)) + (alias core export $p "gi" (core global $gi)) + (core module $User + (import "env" "base" (global $base i32)) + (import "env" "big" (global $big (mut i64))) + (func (export "read") (result i32) + (i32.add (global.get $base) (i32.wrap_i64 (global.get $big))))) + (core instance $u (instantiate $User + (with "env" (instance + (export "base" (global $gi)) + (export "big" (global $p "g64")))))) + (func (export "bump64") (canon lift (core func $p "bump64"))) + (func (export "read") (result u32) (canon lift (core func $u "read"))) +) + +(assert_return (invoke "read") (u32.const 37)) +(assert_return (invoke "bump64")) +(assert_return (invoke "read") (u32.const 38)) + +;; Renaming memory, global, and table exports in a synthesized core instance: +;; a client's differently-named imports of every non-func kind are satisfied +;; by renaming one provider instance's exports. +(component + (core module $P + (memory (export "1") 1) + (data (i32.const 0) "\05") + (global (export "2") i32 (i32.const 300)) + (func $forty (result i32) (i32.const 40)) + (table (export "3") 1 funcref) + (elem (i32.const 0) func $forty)) + (core instance $p (instantiate $P)) + (core module $Client + (type $t (func (result i32))) + (import "env" "mem" (memory 1)) + (import "env" "glob" (global $g i32)) + (import "env" "tab" (table 1 funcref)) + (func (export "sum") (result i32) + (i32.add + (i32.add (i32.load8_u (i32.const 0)) (global.get $g)) + (call_indirect (type $t) (i32.const 0))))) + (core instance $c (instantiate $Client + (with "env" (instance + (export "mem" (memory $p "1")) + (export "glob" (global $p "2")) + (export "tab" (table $p "3")))))) + (func (export "sum") (result u32) (canon lift (core func $c "sum"))) +) + +(assert_return (invoke "sum") (u32.const 345)) + +;; TODO: maybe disallow in the spec? +;; A nested component captures its parent's instantiation argument: the inner +;; component outer-aliases the module import its parent received, so each +;; captured copy of the inner component keeps using the module supplied to +;; that parent instantiation. +(component + (component $C + (import "m" (core module $M (export "get" (func (result i32))))) + (component $Inner + (core instance $m (instantiate $M)) + (func (export "get") (result u32) (canon lift (core func $m "get")))) + (export "inner" (component $Inner))) + (core module $M1 (func (export "get") (result i32) (i32.const 410))) + (core module $M2 (func (export "get") (result i32) (i32.const 420))) + (instance $c1 (instantiate $C (with "m" (core module $M1)))) + (instance $c2 (instantiate $C (with "m" (core module $M2)))) + (alias export $c1 "inner" (component $I1)) + (alias export $c2 "inner" (component $I2)) + (instance $i1 (instantiate $I1)) + (instance $i2 (instantiate $I2)) + (func (export "get-1") (alias export $i1 "get")) + (func (export "get-2") (alias export $i2 "get")) +) + +(assert_return (invoke "get-1") (u32.const 410)) +(assert_return (invoke "get-2") (u32.const 420)) + +;; An instance-typed argument to an imported component: the wrapper imports +;; both a service instance and a component whose declared import is that +;; instance type, then instantiates the imported component twice with the +;; same instance argument, so both copies share the service's state. +(component + (component $Svc + (core module $M + (global $g (mut i32) (i32.const 100)) + (func (export "next") (result i32) + (global.set $g (i32.add (global.get $g) (i32.const 1))) + (global.get $g))) + (core instance $m (instantiate $M)) + (func (export "next") (result u32) (canon lift (core func $m "next")))) + (component $User + (import "svc" (instance $svc (export "next" (func (result u32))))) + (core func $next_l (canon lower (func $svc "next"))) + (core module $M + (import "e" "next" (func $next (result i32))) + (func (export "run") (result i32) + (i32.add (i32.mul (call $next) (i32.const 10)) (call $next)))) + (core instance $m (instantiate $M + (with "e" (instance (export "next" (func $next_l)))))) + (func (export "run") (result u32) (canon lift (core func $m "run")))) + (component $Wrap + (import "svc" (instance $svc (export "next" (func (result u32))))) + (import "u" (component $U + (import "svc" (instance (export "next" (func (result u32))))) + (export "run" (func (result u32))))) + (instance $u1 (instantiate $U (with "svc" (instance $svc)))) + (instance $u2 (instantiate $U (with "svc" (instance $svc)))) + (func (export "run-1") (alias export $u1 "run")) + (func (export "run-2") (alias export $u2 "run"))) + (instance $svc (instantiate $Svc)) + (instance $w (instantiate $Wrap + (with "svc" (instance $svc)) + (with "u" (component $User)))) + (func (export "run-1") (alias export $w "run-1")) + (func (export "run-2") (alias export $w "run-2")) +) + +(assert_return (invoke "run-1") (u32.const 1112)) +(assert_return (invoke "run-2") (u32.const 1134)) +(assert_return (invoke "run-1") (u32.const 1156)) diff --git a/test/resources/borrows.wast b/test/resources/borrows.wast new file mode 100644 index 00000000..b68e6369 --- /dev/null +++ b/test/resources/borrows.wast @@ -0,0 +1,162 @@ +;; Passing owns and borrows of a resource type R from a client component $D +;; back to the defining component $C: borrows leave the lender's own handle +;; usable after the call returns, but lifting an own traps while it is lent. +(component definition $BorrowTester + (component $C + (core module $Indirect + (table (export "ftbl") 1 funcref) + (type $FT (func (param i32))) + (func (export "R-dtor") (param i32) + (call_indirect (type $FT) (local.get 0) (i32.const 0)) + ) + ) + (core instance $indirect (instantiate $Indirect)) + (type $R' (resource (rep i32) (dtor (core func $indirect "R-dtor")))) + (export $R "R" (type $R')) + (canon resource.new $R' (core func $resource.new)) + (canon resource.drop $R' (core func $resource.drop)) + + (core module $CM + (import "" "ftbl" (table 1 funcref)) + (import "" "resource.new" (func $resource.new (param i32) (result i32))) + (import "" "resource.drop" (func $resource.drop (param i32))) + (global $num-made (mut i32) (i32.const 0)) + (global $num-live (mut i32) (i32.const 0)) + + (func (export "make") (result i32) + (global.set $num-made (i32.add (global.get $num-made) (i32.const 1))) + (global.set $num-live (i32.add (global.get $num-live) (i32.const 1))) + (call $resource.new (i32.add (i32.const 0x40) (global.get $num-made))) + ) + + ;; borrow params arrive as the rep since $C implements R + (func (export "get-rep") (param $rep i32) (result i32) + (local.get $rep) + ) + (func (export "get-rep-pair") (param $rep1 i32) (param $rep2 i32) (result i32) + (i32.add (local.get $rep1) (local.get $rep2)) + ) + + (func (export "borrow-and-take") (param $rep i32) (param $own i32) (result i32) + (call $resource.drop (local.get $own)) + (local.get $rep) + ) + + (func (export "num-live") (result i32) + (global.get $num-live) + ) + (func $dtor (param $rep i32) + (if (i32.or (i32.le_u (local.get $rep) (i32.const 0x40)) + (i32.gt_u (local.get $rep) (i32.add (i32.const 0x40) (global.get $num-made)))) + (then unreachable)) + (if (i32.eqz (global.get $num-live)) + (then unreachable)) + (global.set $num-live (i32.sub (global.get $num-live) (i32.const 1))) + ) + (elem (i32.const 0) $dtor) + ) + (core instance $cm (instantiate $CM (with "" (instance + (export "ftbl" (table $indirect "ftbl")) + (export "resource.new" (func $resource.new)) + (export "resource.drop" (func $resource.drop)) + )))) + (func (export "make") (result (own $R)) (canon lift (core func $cm "make"))) + (func (export "get-rep") (param "r" (borrow $R)) (result u32) (canon lift (core func $cm "get-rep"))) + (func (export "get-rep-pair") (param "a" (borrow $R)) (param "b" (borrow $R)) (result u32) (canon lift (core func $cm "get-rep-pair"))) + (func (export "borrow-and-take") (param "b" (borrow $R)) (param "o" (own $R)) (result u32) (canon lift (core func $cm "borrow-and-take"))) + (func (export "num-live") (result u32) (canon lift (core func $cm "num-live"))) + ) + + (component $D + (import "c" (instance $c + (export "R" (type $R (sub resource))) + (export "make" (func (result (own $R)))) + (export "get-rep" (func (param "r" (borrow $R)) (result u32))) + (export "get-rep-pair" (func (param "a" (borrow $R)) (param "b" (borrow $R)) (result u32))) + (export "borrow-and-take" (func (param "b" (borrow $R)) (param "o" (own $R)) (result u32))) + (export "num-live" (func (result u32))) + )) + (core module $DM + (import "" "resource.drop" (func $resource.drop (param i32))) + (import "" "make" (func $make (result i32))) + (import "" "get-rep" (func $get-rep (param i32) (result i32))) + (import "" "get-rep-pair" (func $get-rep-pair (param i32 i32) (result i32))) + (import "" "borrow-and-take" (func $borrow-and-take (param i32 i32) (result i32))) + (import "" "num-live" (func $num-live (result i32))) + + (func (export "run") (result i32) + (local $h1 i32) (local $h2 i32) (local $h3 i32) + (local.set $h1 (call $make)) + (if (i32.ne (i32.const 1) (local.get $h1)) + (then unreachable)) + + (if (i32.ne (i32.const 0x41) (call $get-rep (local.get $h1))) + (then unreachable)) + (if (i32.ne (i32.const 0x41) (call $get-rep (local.get $h1))) + (then unreachable)) + + (if (i32.ne (i32.const 0x82) (call $get-rep-pair (local.get $h1) (local.get $h1))) + (then unreachable)) + + (local.set $h2 (call $make)) + (if (i32.ne (i32.const 2) (local.get $h2)) + (then unreachable)) + (if (i32.ne (i32.const 2) (call $num-live)) + (then unreachable)) + (if (i32.ne (i32.const 0x41) (call $borrow-and-take (local.get $h1) (local.get $h2))) + (then unreachable)) + (if (i32.ne (i32.const 1) (call $num-live)) + (then unreachable)) + + (if (i32.ne (i32.const 0x41) (call $get-rep (local.get $h1))) + (then unreachable)) + (call $resource.drop (local.get $h1)) + (if (i32.ne (i32.const 0) (call $num-live)) + (then unreachable)) + + (local.set $h3 (call $make)) + (if (i32.ne (i32.const 1) (local.get $h3)) + (then unreachable)) + (if (i32.ne (i32.const 0x43) (call $get-rep (local.get $h3))) + (then unreachable)) + (call $resource.drop (local.get $h3)) + + (i32.const 42) + ) + + (func (export "lend-trap") + (local $h i32) + (local.set $h (call $make)) + (drop (call $borrow-and-take (local.get $h) (local.get $h))) + ) + ) + (alias export $c "R" (type $R)) + (canon resource.drop $R (core func $resource.drop)) + (canon lower (func $c "make") (core func $make')) + (canon lower (func $c "get-rep") (core func $get-rep')) + (canon lower (func $c "get-rep-pair") (core func $get-rep-pair')) + (canon lower (func $c "borrow-and-take") (core func $borrow-and-take')) + (canon lower (func $c "num-live") (core func $num-live')) + (core instance $dm (instantiate $DM (with "" (instance + (export "resource.drop" (func $resource.drop)) + (export "make" (func $make')) + (export "get-rep" (func $get-rep')) + (export "get-rep-pair" (func $get-rep-pair')) + (export "borrow-and-take" (func $borrow-and-take')) + (export "num-live" (func $num-live')) + )))) + (func (export "run") (result u32) (canon lift (core func $dm "run"))) + (func (export "lend-trap") (canon lift (core func $dm "lend-trap"))) + ) + + (instance $c (instantiate $C)) + (instance $d (instantiate $D (with "c" (instance $c)))) + (func (export "run") (alias export $d "run")) + (func (export "lend-trap") (alias export $d "lend-trap")) +) + +(component instance $i $BorrowTester) +(assert_return (invoke "run") (u32.const 42)) + +(component instance $i $BorrowTester) +(assert_trap (invoke "lend-trap") "cannot remove owned resource while borrowed") diff --git a/test/resources/handle-table.wast b/test/resources/handle-table.wast new file mode 100644 index 00000000..ddfb6af5 --- /dev/null +++ b/test/resources/handle-table.wast @@ -0,0 +1,324 @@ +;; Runtime semantics of the per-component-instance handle table: sequential +;; index allocation and reuse, bounds- and type-checking of every handle +;; access, and isolation between component instances. + +;; Indices allocate sequentially from 1 and freed indices are reused LIFO +;; (the free-list order is spec-normative, so exact indices can be asserted). +(component + (type $R (resource (rep i32))) + (canon resource.new $R (core func $R.resource.new)) + (canon resource.drop $R (core func $R.resource.drop)) + (canon resource.rep $R (core func $R.resource.rep)) + (core module $M + (import "" "new" (func $new (param i32) (result i32))) + (import "" "drop" (func $drop (param i32))) + (import "" "rep" (func $rep (param i32) (result i32))) + (func (export "run") (result i32) + (if (i32.ne (i32.const 1) (call $new (i32.const 100))) (then unreachable)) + (if (i32.ne (i32.const 2) (call $new (i32.const 200))) (then unreachable)) + (if (i32.ne (i32.const 3) (call $new (i32.const 300))) (then unreachable)) + + (call $drop (i32.const 2)) + (if (i32.ne (i32.const 2) (call $new (i32.const 400))) (then unreachable)) + (if (i32.ne (i32.const 100) (call $rep (i32.const 1))) (then unreachable)) + (if (i32.ne (i32.const 400) (call $rep (i32.const 2))) (then unreachable)) + (if (i32.ne (i32.const 300) (call $rep (i32.const 3))) (then unreachable)) + + (call $drop (i32.const 1)) + (call $drop (i32.const 2)) + (call $drop (i32.const 3)) + (if (i32.ne (i32.const 3) (call $new (i32.const 500))) (then unreachable)) + (if (i32.ne (i32.const 2) (call $new (i32.const 600))) (then unreachable)) + (if (i32.ne (i32.const 1) (call $new (i32.const 700))) (then unreachable)) + (if (i32.ne (i32.const 500) (call $rep (i32.const 3))) (then unreachable)) + (if (i32.ne (i32.const 600) (call $rep (i32.const 2))) (then unreachable)) + (if (i32.ne (i32.const 700) (call $rep (i32.const 1))) (then unreachable)) + + (if (i32.ne (i32.const 4) (call $new (i32.const 800))) (then unreachable)) + + (i32.const 42) + ) + ) + (core instance $m (instantiate $M (with "" (instance + (export "new" (func $R.resource.new)) + (export "drop" (func $R.resource.drop)) + (export "rep" (func $R.resource.rep)) + )))) + (func (export "run") (result u32) (canon lift (core func $m "run"))) +) +(assert_return (invoke "run") (u32.const 42)) + +;; Both dropping a handle and transferring ownership out remove the entry: +;; once the table is drained, a fresh handle gets index 1 again. +(component + (component $C + (type $R' (resource (rep i32))) + (export $R "R" (type $R')) + (canon resource.new $R' (core func $R.resource.new)) + (canon resource.drop $R' (core func $R.resource.drop)) + (core module $CM + (import "" "new" (func $new (param i32) (result i32))) + (import "" "drop" (func $drop (param i32))) + (func (export "make") (param $rep i32) (result i32) (call $new (local.get $rep))) + (func (export "take") (param $h i32) (call $drop (local.get $h))) + ) + (core instance $cm (instantiate $CM (with "" (instance + (export "new" (func $R.resource.new)) + (export "drop" (func $R.resource.drop)) + )))) + (func (export "make") (param "rep" u32) (result (own $R)) (canon lift (core func $cm "make"))) + (func (export "take") (param "r" (own $R)) (canon lift (core func $cm "take"))) + ) + (component $D + (import "c" (instance $c + (export "R" (type $R (sub resource))) + (export "make" (func (param "rep" u32) (result (own $R)))) + (export "take" (func (param "r" (own $R)))) + )) + (alias export $c "R" (type $R)) + (canon resource.drop $R (core func $R.resource.drop)) + (canon lower (func $c "make") (core func $make')) + (canon lower (func $c "take") (core func $take')) + (core module $DM + (import "" "make" (func $make (param i32) (result i32))) + (import "" "take" (func $take (param i32))) + (import "" "drop" (func $drop (param i32))) + (func (export "run") (result i32) + (if (i32.ne (i32.const 1) (call $make (i32.const 100))) (then unreachable)) + (if (i32.ne (i32.const 2) (call $make (i32.const 200))) (then unreachable)) + (call $drop (i32.const 2)) + (call $take (i32.const 1)) + (if (i32.ne (i32.const 1) (call $make (i32.const 300))) (then unreachable)) + (i32.const 43) + ) + ) + (core instance $dm (instantiate $DM (with "" (instance + (export "make" (func $make')) + (export "take" (func $take')) + (export "drop" (func $R.resource.drop)) + )))) + (func (export "run") (result u32) (canon lift (core func $dm "run"))) + ) + (instance $c (instantiate $C)) + (instance $d (instantiate $D (with "c" (instance $c)))) + (func (export "run") (alias export $d "run")) +) +(assert_return (invoke "run") (u32.const 43)) + +;; Unknown handle indices trap: never-allocated, already-dropped, 0, and +;; 0xffffffff, both for resource built-ins and when lifting handles at a call. +(component definition $Traps + (type $R (resource (rep i32))) + (canon resource.new $R (core func $R.resource.new)) + (canon resource.drop $R (core func $R.resource.drop)) + (canon resource.rep $R (core func $R.resource.rep)) + (core module $M + (import "" "new" (func $new (param i32) (result i32))) + (import "" "drop" (func $drop (param i32))) + (import "" "rep" (func $rep (param i32) (result i32))) + (func (export "drop-never-allocated") (call $drop (i32.const 5))) + (func (export "rep-never-allocated") (drop (call $rep (i32.const 5)))) + (func (export "double-drop") + (if (i32.ne (i32.const 1) (call $new (i32.const 100))) (then unreachable)) + (call $drop (i32.const 1)) + (call $drop (i32.const 1)) + ) + (func (export "drop-zero") (call $drop (i32.const 0))) + (func (export "drop-max") (call $drop (i32.const 0xffffffff))) + ) + (core instance $m (instantiate $M (with "" (instance + (export "new" (func $R.resource.new)) + (export "drop" (func $R.resource.drop)) + (export "rep" (func $R.resource.rep)) + )))) + (func (export "drop-never-allocated") (canon lift (core func $m "drop-never-allocated"))) + (func (export "rep-never-allocated") (canon lift (core func $m "rep-never-allocated"))) + (func (export "double-drop") (canon lift (core func $m "double-drop"))) + (func (export "drop-zero") (canon lift (core func $m "drop-zero"))) + (func (export "drop-max") (canon lift (core func $m "drop-max"))) + + (component $C + (type $R' (resource (rep i32))) + (export $R "R" (type $R')) + (canon resource.new $R' (core func $R.resource.new)) + (canon resource.drop $R' (core func $R.resource.drop)) + (core module $CM + (import "" "new" (func $new (param i32) (result i32))) + (import "" "drop" (func $drop (param i32))) + (func (export "make") (result i32) (call $new (i32.const 100))) + (func (export "consume") (param $h i32) (call $drop (local.get $h))) + (func (export "use") (param $rep i32)) + ) + (core instance $cm (instantiate $CM (with "" (instance + (export "new" (func $R.resource.new)) + (export "drop" (func $R.resource.drop)) + )))) + (func (export "make") (result (own $R)) (canon lift (core func $cm "make"))) + (func (export "consume") (param "r" (own $R)) (canon lift (core func $cm "consume"))) + (func (export "use") (param "r" (borrow $R)) (canon lift (core func $cm "use"))) + ) + (component $D + (import "c" (instance $c + (export "R" (type $R (sub resource))) + (export "make" (func (result (own $R)))) + (export "consume" (func (param "r" (own $R)))) + (export "use" (func (param "r" (borrow $R)))) + )) + (alias export $c "R" (type $R)) + (canon resource.drop $R (core func $R.resource.drop)) + (canon lower (func $c "make") (core func $make')) + (canon lower (func $c "consume") (core func $consume')) + (canon lower (func $c "use") (core func $use')) + (core module $DM + (import "" "make" (func $make (result i32))) + (import "" "consume" (func $consume (param i32))) + (import "" "use" (func $use (param i32))) + (import "" "drop" (func $drop (param i32))) + (func (export "own-use-after-drop") + (if (i32.ne (i32.const 1) (call $make)) (then unreachable)) + (call $drop (i32.const 1)) + (call $consume (i32.const 1)) + ) + (func (export "borrow-never-valid") + (call $use (i32.const 3)) + ) + ) + (core instance $dm (instantiate $DM (with "" (instance + (export "make" (func $make')) + (export "consume" (func $consume')) + (export "use" (func $use')) + (export "drop" (func $R.resource.drop)) + )))) + (func (export "own-use-after-drop") (canon lift (core func $dm "own-use-after-drop"))) + (func (export "borrow-never-valid") (canon lift (core func $dm "borrow-never-valid"))) + ) + (instance $c (instantiate $C)) + (instance $d (instantiate $D (with "c" (instance $c)))) + (func (export "own-use-after-drop") (alias export $d "own-use-after-drop")) + (func (export "borrow-never-valid") (alias export $d "borrow-never-valid")) +) +(component instance $i $Traps) +(assert_trap (invoke "drop-never-allocated") "unknown handle index 5") +(component instance $i $Traps) +(assert_trap (invoke "rep-never-allocated") "unknown handle index 5") +(component instance $i $Traps) +(assert_trap (invoke "double-drop") "unknown handle index 1") +(component instance $i $Traps) +(assert_trap (invoke "drop-zero") "unknown handle index 0") +(component instance $i $Traps) +(assert_trap (invoke "drop-max") "unknown handle index 4294967295") +(component instance $i $Traps) +(assert_trap (invoke "own-use-after-drop") "unknown handle index 1") +(component instance $i $Traps) +(assert_trap (invoke "borrow-never-valid") "unknown handle index 3") + +;; Handle tables are per component instance: an index allocated in one +;; instance of $User is unknown in a sibling instance of the same definition. +(component + (component $Def + (type $R' (resource (rep i32))) + (export $R "R" (type $R')) + (canon resource.new $R' (core func $R.resource.new)) + (core module $M + (import "" "new" (func $new (param i32) (result i32))) + (func (export "make") (result i32) (call $new (i32.const 100))) + ) + (core instance $m (instantiate $M (with "" (instance + (export "new" (func $R.resource.new)) + )))) + (func (export "make") (result (own $R)) (canon lift (core func $m "make"))) + ) + (component $User + (import "c" (instance $c + (export "R" (type $R (sub resource))) + (export "make" (func (result (own $R)))) + )) + (alias export $c "R" (type $R)) + (canon resource.drop $R (core func $R.resource.drop)) + (canon lower (func $c "make") (core func $make')) + (core module $UM + (import "" "make" (func $make (result i32))) + (import "" "drop" (func $drop (param i32))) + (func (export "alloc") + (if (i32.ne (i32.const 1) (call $make)) (then unreachable)) + ) + (func (export "dealloc") (call $drop (i32.const 1))) + ) + (core instance $um (instantiate $UM (with "" (instance + (export "make" (func $make')) + (export "drop" (func $R.resource.drop)) + )))) + (func (export "alloc") (canon lift (core func $um "alloc"))) + (func (export "dealloc") (canon lift (core func $um "dealloc"))) + ) + (instance $def (instantiate $Def)) + (instance $u1 (instantiate $User (with "c" (instance $def)))) + (instance $u2 (instantiate $User (with "c" (instance $def)))) + (func (export "alloc-in1") (alias export $u1 "alloc")) + (func (export "dealloc-in2") (alias export $u2 "dealloc")) +) +(assert_return (invoke "alloc-in1")) +(assert_trap (invoke "dealloc-in2") "unknown handle index 1") + +;; A parent aliasing a child's exported resource type still has its own empty +;; table: index 1 allocated by the child is unknown in the parent. +(component + (component $Child + (type $R' (resource (rep i32))) + (canon resource.new $R' (core func $R.resource.new)) + (core module $M + (import "" "new" (func $new (param i32) (result i32))) + (func $start + (if (i32.ne (i32.const 1) (call $new (i32.const 100))) (then unreachable)) + ) + (start $start) + ) + (core instance (instantiate $M (with "" (instance + (export "new" (func $R.resource.new)) + )))) + (export "R" (type $R')) + ) + (instance $child (instantiate $Child)) + (alias export $child "R" (type $R)) + (canon resource.drop $R (core func $R.resource.drop)) + (core module $PM + (import "" "drop" (func $drop (param i32))) + (func (export "drop-childs-index") (call $drop (i32.const 1))) + ) + (core instance $pm (instantiate $PM (with "" (instance + (export "drop" (func $R.resource.drop)) + )))) + (func (export "drop-childs-index") (canon lift (core func $pm "drop-childs-index"))) +) +(assert_trap (invoke "drop-childs-index") "unknown handle index 1") + +;; Two resource types share one per-instance table, but each entry remembers +;; its type: using an $R1 handle as an $R2 handle traps. +(component definition $WrongType + (type $R1 (resource (rep i32))) + (type $R2 (resource (rep i32))) + (canon resource.new $R1 (core func $R1.resource.new)) + (canon resource.drop $R2 (core func $R2.resource.drop)) + (core module $M + (import "" "R1.new" (func $R1.new (param i32) (result i32))) + (import "" "R2.drop" (func $R2.drop (param i32))) + (func (export "drop-R1-as-R2") + (if (i32.ne (i32.const 1) (call $R1.new (i32.const 100))) (then unreachable)) + (call $R2.drop (i32.const 1)) + ) + (func (export "return-R1-as-R2") (result i32) + (call $R1.new (i32.const 100)) + ) + ) + (core instance $m (instantiate $M (with "" (instance + (export "R1.new" (func $R1.resource.new)) + (export "R2.drop" (func $R2.resource.drop)) + )))) + (export $R2' "R2" (type $R2)) + (func (export "drop-R1-as-R2") (canon lift (core func $m "drop-R1-as-R2"))) + (func (export "return-R1-as-R2") (result (own $R2')) (canon lift (core func $m "return-R1-as-R2"))) +) +(component instance $i $WrongType) +(assert_trap (invoke "drop-R1-as-R2") "handle index 1 used with the wrong type, expected guest-defined resource but found a different guest-defined resource") +(component instance $i $WrongType) +(assert_trap (invoke "return-R1-as-R2") "handle index 1 used with the wrong type, expected guest-defined resource but found a different guest-defined resource") diff --git a/test/validation/abi.wast b/test/validation/abi.wast index ef1d744c..8b8ed061 100644 --- a/test/validation/abi.wast +++ b/test/validation/abi.wast @@ -1,3 +1,6 @@ +;; Validation of `canon lift`/`canon lower` ABI options: string-encoding, +;; memory, realloc and post-return, and the lifted core function's signature. + (assert_invalid (component (import "foo" (func $foo (result (tuple u64 u64 u64 u64 u64 u64 u64 u64)))) @@ -29,3 +32,243 @@ (canon lower (func $foo) (memory (core memory $i "mem")) (realloc (core func $i "realloc")) (core func $foo2)) ) ) + +;; the memory option must refer to a defined core memory + +(assert_invalid + (component + (import "f" (func $f)) + (core func $f' (canon lower (func $f) (memory 0))) + ) + "memory index out of bounds") + +;; memory is required when lifting a list param, lifting >1 flat results or +;; lowering a list param (lowering a large result is covered above) + +(assert_invalid + (component + (core module $M (func (export "f") (param i32 i32))) + (core instance $i (instantiate $M)) + (func $f (param "p" (list u8)) (canon lift (core func $i "f"))) + ) + "canonical option `memory` is required") +(assert_invalid + (component + (core module $M (func (export "f") (result i32) unreachable)) + (core instance $i (instantiate $M)) + (func $f (result (tuple s8 u8)) (canon lift (core func $i "f"))) + ) + "canonical option `memory` is required") +(assert_invalid + (component + (import "f" (func $f (param "p" (list u8)))) + (core func $f' (canon lower (func $f))) + ) + "canonical option `memory` is required") + +;; realloc is required when lifting a list param, lifting >16 flat params or +;; lowering a string result + +(assert_invalid + (component + (core module $M + (memory (export "mem") 1) + (func (export "f") (param i32 i32)) + ) + (core instance $i (instantiate $M)) + (func $f (param "p" (list u8)) + (canon lift (core func $i "f") (memory (core memory $i "mem")))) + ) + "canonical option `realloc` is required") +(assert_invalid + (component + (core module $M + (memory (export "mem") 1) + (func (export "f") (param i32)) + ) + (core instance $i (instantiate $M)) + (func $f + (param "p1" u32) (param "p2" u32) (param "p3" u32) (param "p4" u32) (param "p5" u32) + (param "p6" u32) (param "p7" u32) (param "p8" u32) (param "p9" u32) (param "p10" u32) + (param "p11" u32) (param "p12" u32) (param "p13" u32) (param "p14" u32) (param "p15" u32) + (param "p16" u32) (param "p17" u32) (param "p18" u32) (param "p19" u32) (param "p20" u32) + (canon lift (core func $i "f") (memory (core memory $i "mem")))) + ) + "canonical option `realloc` is required") +(assert_invalid + (component + (import "f" (func $f (result string))) + (core module $M (memory (export "mem") 1)) + (core instance $i (instantiate $M)) + (core func $f' (canon lower (func $f) (memory (core memory $i "mem")))) + ) + "canonical option `realloc` is required") + +;; string-encoding: lift and lower each accept utf8, utf16 and latin1+utf16 + +(component definition + (import "log" (func $log (param "msg" string))) + (core module $Libc + (memory (export "mem") 1) + (func (export "realloc") (param i32 i32 i32 i32) (result i32) unreachable) + ) + (core instance $libc (instantiate $Libc)) + (alias core export $libc "mem" (core memory $mem)) + (alias core export $libc "realloc" (core func $realloc)) + (canon lower (func $log) string-encoding=utf8 (memory $mem) (realloc $realloc) (core func $log1')) + (canon lower (func $log) string-encoding=utf16 (memory $mem) (realloc $realloc) (core func $log2')) + (canon lower (func $log) string-encoding=latin1+utf16 (memory $mem) (realloc $realloc) (core func $log3')) + (core module $M (func (export "log") (param i32 i32))) + (core instance $m (instantiate $M)) + (func (export "log1") (param "msg" string) + (canon lift (core func $m "log") string-encoding=utf8 (memory $mem) (realloc $realloc))) + (func (export "log2") (param "msg" string) + (canon lift (core func $m "log") string-encoding=utf16 (memory $mem) (realloc $realloc))) + (func (export "log3") (param "msg" string) + (canon lift (core func $m "log") string-encoding=latin1+utf16 (memory $mem) (realloc $realloc))) +) + +;; at most one string-encoding option may be specified + +(assert_invalid + (component + (import "f" (func $f)) + (core func $f' (canon lower (func $f) string-encoding=utf8 string-encoding=utf16)) + ) + "canonical encoding option `utf8` conflicts with option `utf16`") +(assert_invalid + (component + (import "f" (func $f)) + (core func $f' (canon lower (func $f) string-encoding=utf8 string-encoding=latin1+utf16)) + ) + "canonical encoding option `utf8` conflicts with option `latin1-utf16`") +(assert_invalid + (component + (import "f" (func $f)) + (core func $f' (canon lower (func $f) string-encoding=utf16 string-encoding=latin1+utf16)) + ) + "canonical encoding option `utf16` conflicts with option `latin1-utf16`") + +;; the memory, realloc and post-return options may be specified at most once + +(assert_invalid + (component + (import "f" (func $f)) + (core module $M (memory (export "mem") 1)) + (core instance $i (instantiate $M)) + (core func $f' (canon lower (func $f) + (memory (core memory $i "mem")) + (memory (core memory $i "mem")))) + ) + "`memory` is specified more than once") +(assert_invalid + (component + (core module $M + (memory (export "mem") 1) + (func (export "f") (param i32 i32)) + (func (export "realloc") (param i32 i32 i32 i32) (result i32) unreachable) + ) + (core instance $i (instantiate $M)) + (func $f (param "p" (list u8)) + (canon lift (core func $i "f") + (memory (core memory $i "mem")) + (realloc (core func $i "realloc")) + (realloc (core func $i "realloc")))) + ) + "canonical option `realloc` is specified more than once") +(assert_invalid + (component + (core module $M + (memory (export "mem") 1) + (func (export "f") (result i32) unreachable) + (func (export "realloc") (param i32 i32 i32 i32) (result i32) unreachable) + (func (export "post") (param i32)) + ) + (core instance $i (instantiate $M)) + (func $f (result string) + (canon lift (core func $i "f") + (memory (core memory $i "mem")) + (realloc (core func $i "realloc")) + (post-return (core func $i "post")) + (post-return (core func $i "post")))) + ) + "canonical option `post-return` is specified more than once") + +;; the realloc and post-return options must have the correct core signatures +;; and post-return is only valid when lifting + +(assert_invalid + (component + (core module $M + (memory (export "mem") 1) + (func (export "f") (param i32 i32)) + (func (export "realloc")) + ) + (core instance $i (instantiate $M)) + (func $f (param "p" (list u8)) + (canon lift (core func $i "f") + (memory (core memory $i "mem")) + (realloc (core func $i "realloc")))) + ) + "canonical option `realloc` uses a core function with an incorrect signature") +(assert_invalid + (component + (core module $M + (memory (export "mem") 1) + (func (export "f") (result i32) unreachable) + (func (export "realloc") (param i32 i32 i32 i32) (result i32) unreachable) + ;; post-return must take the lifted core func's results as params, here (param i32) + (func (export "post")) + ) + (core instance $i (instantiate $M)) + (func $f (result string) + (canon lift (core func $i "f") + (memory (core memory $i "mem")) + (realloc (core func $i "realloc")) + (post-return (core func $i "post")))) + ) + "canonical option `post-return` uses a core function with an incorrect signature") +(assert_invalid + (component + (import "f" (func $f (param "p" string))) + (core module $M + (memory (export "mem") 1) + (func (export "realloc") (param i32 i32 i32 i32) (result i32) unreachable) + (func (export "post") (param i32)) + ) + (core instance $i (instantiate $M)) + (core func $f' (canon lower (func $f) + (memory (core memory $i "mem")) + (realloc (core func $i "realloc")) + (post-return (core func $i "post")))) + ) + "canonical option `post-return` cannot be specified for lowerings") + +;; the lifted core func's signature must match the flattening of the +;; component-level function type, on both the param and result side + +(assert_invalid + (component + (core module $M (func (export "f") (param i32))) + (core instance $i (instantiate $M)) + (func $f (canon lift (core func $i "f"))) + ) + "lowered parameter types `[]` do not match parameter types `[I32]`") +(assert_invalid + (component + (core module $M (func (export "f") (result i32) unreachable)) + (core instance $i (instantiate $M)) + (func $f (canon lift (core func $i "f"))) + ) + "lowered result types `[]` do not match result types `[I32]`") + +;; a type ascription on canon lift must be a function type + +(assert_invalid + (component + (type $t string) + (core module $M (func (export "f"))) + (core instance $i (instantiate $M)) + (func $f (type $t) (canon lift (core func $i "f"))) + ) + "not a function type") diff --git a/test/validation/annotated-names.wast b/test/validation/annotated-names.wast new file mode 100644 index 00000000..28d54521 --- /dev/null +++ b/test/validation/annotated-names.wast @@ -0,0 +1,202 @@ +;; Tests for `[constructor]`/`[method]`/`[static]` annotated plainnames +;; (Explainer.md#import-and-export-definitions and the import/export +;; validation rules of Binary.md). + +;; `[constructor]a` requires a single `(own $a)` or `(result (own $a) (error E)?)` +;; result of the resource imported/exported as "a" + +(component definition + (import "a" (type $a (sub resource))) + (import "[constructor]a" (func (result (own $a)))) + (import "b" (type $b (sub resource))) + (import "[constructor]b" (func (result (result (own $b))))) + (import "c" (type $c (sub resource))) + (import "[constructor]c" (func (result (result (own $c) (error string))))) + (import "d" (type $d (sub resource))) + (import "[constructor]d" (func (param "x" u32) (result (own $d))))) +(assert_invalid + (component + (import "[constructor]" (func))) + "not in kebab case") +(assert_invalid + (component + (import "[constructor]a" (func))) + "should return one value") +(assert_invalid + (component + (import "[constructor]a" (func (result u32)))) + "should return `(own $T)`") +(assert_invalid + (component + (import "b" (type $a (sub resource))) + (import "[constructor]a" (func (result (own $a))))) + "function does not match expected resource name `b`") +(assert_invalid + (component + (import "a" (type $a (sub resource))) + (import "[constructor]a" (func (result string)))) + "function should return `(own $T)` or `(result (own $T))`") +(assert_invalid + (component + (import "a" (type $a (sub resource))) + (import "[constructor]a" (func (result (result string))))) + "function should return `(own $T)` or `(result (own $T))`") +(assert_invalid + (component + (import "a" (type $a (sub resource))) + (import "[constructor]a" (func (result (result (result (own $a))))))) + "function should return `(own $T)` or `(result (own $T))`") + +;; `[method]a.b` requires two `.`-separated labels and a first +;; `(param "self" (borrow $a))` + +(component definition + (import "a" (type $T (sub resource))) + (import "[method]a.b" (func (param "self" (borrow $T))))) +(assert_invalid + (component + (import "[method]" (func))) + "failed to find `.` character") +(assert_invalid + (component + (import "[method]a" (func))) + "failed to find `.` character") +(assert_invalid + (component + (import "[method]a." (func))) + "not in kebab case") +(assert_invalid + (component + (import "[method].a" (func))) + "not in kebab case") +(assert_invalid + (component + (import "[method]a.b.c" (func))) + "not in kebab case") +(assert_invalid + (component + (import "[method]a.b" (instance))) + "is not a func") +(assert_invalid + (component + (import "[method]a.b" (func))) + "should have at least one argument") +(assert_invalid + (component + (import "[method]a.b" (func (param "x" u32)))) + "should have a first argument called `self`") +(assert_invalid + (component + (import "[method]a.b" (func (param "self" u32)))) + "should take a first argument of `(borrow $T)`") +(assert_invalid + (component + (import "b" (type $T (sub resource))) + (import "[method]a.b" (func (param "self" (borrow $T))))) + "does not match expected resource name") + +;; `[static]a.b` requires two `.`-separated labels and a resource named "a" +;; in scope, but constrains the function type no further + +(component definition + (import "a" (type (sub resource))) + (import "[static]a.b" (func (param "x" u32) (result string)))) +(assert_invalid + (component + (import "[static]" (func))) + "failed to find `.` character") +(assert_invalid + (component + (import "[static]a" (func))) + "failed to find `.` character") +(assert_invalid + (component + (import "[static]a." (func))) + "not in kebab case") +(assert_invalid + (component + (import "[static].a" (func))) + "not in kebab case") +(assert_invalid + (component + (import "[static]a.b.c" (func))) + "not in kebab case") +(assert_invalid + (component + (import "[static]a.b" (instance))) + "is not a func") +(assert_invalid + (component + (import "[static]a.b" (func))) + "static resource name is not known in this context") + +;; the resource name resolves in the same namespace as the annotated name, so +;; since import and export namespaces are disjoint, an exported `[method]` +;; requires the resource to itself be (re-)exported + +(component + (component + (import "b" (type $T (sub resource))) + (import "f" (func $f (param "self" (borrow $T)))) + (export $c "c" (type $T)) + (export "[method]c.foo" (func $f) (func (param "self" (borrow $c)))))) +(assert_invalid + (component + (import "b" (type $T (sub resource))) + (import "f" (func $f (param "self" (borrow $T)))) + (export "[method]b.foo" (func $f))) + "resource used in function does not have a name in this context") + +;; imports aren't transitive: a resource inside an imported instance confers +;; no root-level name + +(assert_invalid + (component + (import "i" (instance $i + (export "t" (type (sub resource))))) + (alias export $i "t" (type $t)) + (import "[method]t.foo" (func (param "self" (borrow $t))))) + "resource used in function does not have a name in this context") + +;; validation applies inside type declarators and in synthesized +;; bag-of-exports instance types + +(component + (type (component + (type $it (instance + (export "bar" (type (sub resource))) + (export "[static]bar.a" (func)))) + (export "x" (instance (type $it)))))) +(assert_invalid + (component + (type (component + (import "b" (type $T (sub resource))) + (import "[constructor]a" (func (result (own $T))))))) + "function does not match expected resource name `b`") +(assert_invalid + (component + (type $T (resource (rep i32))) + (core module $m (func (export "a") (result i32) unreachable)) + (core instance $i (instantiate $m)) + (func $f (result (own $T)) (canon lift (core func $i "a"))) + (instance + (export "a" (type $T)) + (export "[constructor]a" (func $f)))) + "resource used in function does not have a name in this context") + +;; strong-uniqueness is computed on the post-`.` label, so `[method]a.a` and +;; `[static]a.a` conflict with a plain `a` while `[constructor]a` does not + +(component definition + (import "a" (type $a (sub resource))) + (import "[constructor]a" (func (result (own $a))))) +(assert_invalid + (component + (import "a" (type $a (sub resource))) + (import "[method]a.a" (func (param "self" (borrow $a))))) + "import name `[method]a.a` conflicts with previous name `a`") +(assert_invalid + (component + (import "a" (type $a (sub resource))) + (import "[static]a.a" (func))) + "import name `[static]a.a` conflicts with previous name `a`") diff --git a/test/validation/core-modules.wast b/test/validation/core-modules.wast new file mode 100644 index 00000000..c649ec7f --- /dev/null +++ b/test/validation/core-modules.wast @@ -0,0 +1,117 @@ +;; Validation of core modules and core module types embedded in components: +;; nested core code and module types are fully core-validated, and two-level +;; core import names must mangle to distinct single-level component names. + +;; valid nested core module, core module type and module-typed import + +(component definition + (core module + (func (export "add") (param i32 i32) (result i32) + (i32.add (local.get 0) (local.get 1))) + ) + (core type $MT (module + (type $ft (func)) + (import "a" "b" (func (type $ft))) + (import "a" "c" (func (type $ft))) + (export "f" (func (type $ft))) + (export "g" (func (type $ft))) + )) + (import "m" (core module (type $MT))) +) + +;; the code of a core module nested in a component is core-validated + +(assert_invalid + (component + (core module + (func + i32.add) + ) + ) + "type mismatch") + +;; module types are internally validated: index bounds, duplicate export +;; names and core limits + +(assert_invalid + (component + (core type (module + (export "a" (func (type 0))) + )) + ) + "type index out of bounds") +(assert_invalid + (component + (core type (module + (export "a" (func)) + (export "a" (func)) + )) + ) + "export name `a` already defined") +(assert_invalid + (component + (core type (module + (import "" "" (memory 70000)) + )) + ) + "memory size must be at most") + +;; ...including when the module type is itself nested in a component or +;; instance type + +(assert_invalid + (component + (type (component + (core type (module + (export "" (func)) + (export "" (func)) + )) + )) + ) + "name `` already defined") +(assert_invalid + (component + (type (instance + (core type (module + (export "" (func)) + (export "" (func)) + )) + )) + ) + "name `` already defined") + +;; duplicate two-level core import names are forbidden (in both concrete +;; modules and module types) since they mangle to the same single-level name + +(assert_invalid + (component + (core module + (import "" "" (func)) + (import "" "" (func)) + ) + ) + "duplicate import name `:`") +(assert_invalid + (component + (core module + (import "" "a" (func)) + (import "" "a" (func)) + ) + ) + "duplicate import name `:a`") +(assert_invalid + (component + (core type (module + (import "" "" (func)) + (import "" "" (func)) + )) + ) + "duplicate import name `:`") +(assert_invalid + (component + (core type (module + (import "" "a" (func)) + (import "" "a" (func)) + )) + ) + "duplicate import name `:a`") diff --git a/test/validation/defined-types.wast b/test/validation/defined-types.wast new file mode 100644 index 00000000..21ed2d57 --- /dev/null +++ b/test/validation/defined-types.wast @@ -0,0 +1,250 @@ +;; Well-formedness of defined (value) types: label rules, non-emptiness, the +;; 32-flag limit, where a defined type is (and is not) allowed, and the sort +;; checks applied when a type index is ascribed to an import or export. + +;; all primitive and compound defined types are well-formed, referenced by +;; index or inline, including error-only and empty result types + +(component + (type bool) + (type u8) (type s8) (type u16) (type s16) + (type u32) (type s32) (type u64) (type s64) + (type f32) (type f64) + (type char) (type string) + + (type $r (record (field "x" (result)) (field "y" string))) + (type $u (variant (case "r" $r) (case "s" string))) + (type $e (result $u (error u32))) + (type (result $u)) + (type (result (error $u))) + (type (result)) + (type (func (param "a" $e) (result (option $r)))) + + (type $errno (enum "a" "b" "e")) + (type (list $errno)) + (type $oflags (flags "read" "write" "exclusive")) + (type (tuple $oflags $errno $r)) +) + +;; labels must be non-empty + +(assert_invalid + (component (type (record (field "" s32)))) + "record field name cannot be empty") +(assert_invalid + (component (type (variant (case "" s32)))) + "variant case name cannot be empty") +(assert_invalid + (component (type (flags ""))) + "flag name cannot be empty") +(assert_invalid + (component (type (enum ""))) + "enum tag name cannot be empty") +(assert_invalid + (component (type (func (param "" string)))) + "function parameter name cannot be empty") + +;; labels must be unique, compared case-insensitively + +(assert_invalid + (component (type (record (field "a-B-c-D" string) (field "A-b-C-d" u8)))) + "record field name `A-b-C-d` conflicts with previous field name `a-B-c-D`") +(assert_invalid + (component (type (variant (case "x" s64) (case "x" s64)))) + "variant case name `x` conflicts with previous case name `x`") +(assert_invalid + (component (type (variant (case "x" s64) (case "X" s64)))) + "variant case name `X` conflicts with previous case name `x`") +(assert_invalid + (component (type (flags "x" "y" "X"))) + "flag name `X` conflicts with previous flag name `x`") +(assert_invalid + (component (type (enum "x" "y" "X"))) + "enum tag name `X` conflicts with previous tag name `x`") +(assert_invalid + (component (type (func (param "foo" string) (param "FOO" u32)))) + "function parameter name `FOO` conflicts with previous parameter name `foo`") + +;; labels must be in kebab case + +(assert_invalid + (component (type (enum "NevEr"))) + "enum tag name `NevEr` is not in kebab case") +(assert_invalid + (component (type (record (field "GoNnA" string)))) + "record field name `GoNnA` is not in kebab case") +(assert_invalid + (component (type (variant (case "GIVe" string)))) + "variant case name `GIVe` is not in kebab case") +(assert_invalid + (component (type (func (param "yOu" string)))) + "function parameter name `yOu` is not in kebab case") + +;; variant, enum, record, flags and tuple must be non-empty + +(assert_invalid + (component (type (variant))) + "variant type must have at least one case") +(assert_invalid + (component (type (enum))) + "enum type must have at least one variant") +(assert_invalid + (component (type (record))) + "record type must have at least one field") +(assert_invalid + (component (type (flags))) + "flags must have at least one entry") +(assert_invalid + (component (type (tuple))) + "tuple type must have at least one type") + +;; at most 32 flags + +(component + (type (flags + "f1" "f2" "f3" "f4" "f5" "f6" "f7" "f8" + "f9" "f10" "f11" "f12" "f13" "f14" "f15" "f16" + "f17" "f18" "f19" "f20" "f21" "f22" "f23" "f24" + "f25" "f26" "f27" "f28" "f29" "f30" "f31" "f32")) +) +(assert_invalid + (component + (type (flags + "f1" "f2" "f3" "f4" "f5" "f6" "f7" "f8" + "f9" "f10" "f11" "f12" "f13" "f14" "f15" "f16" + "f17" "f18" "f19" "f20" "f21" "f22" "f23" "f24" + "f25" "f26" "f27" "f28" "f29" "f30" "f31" "f32" "f33"))) + "cannot have more than 32 flags") + +;; func, instance and component types are not defined (value) types + +(assert_invalid + (component + (type $t (func)) + (type (func (param "t" $t)))) + "type index 0 is not a defined type") +(assert_invalid + (component + (type $t (instance)) + (type (func (result $t)))) + "type index 0 is not a defined type") +(assert_invalid + (component + (type $t (component)) + (type (option $t))) + "type index 0 is not a defined type") + +;; type indices inside defined types must be in bounds + +(assert_invalid + (component (type (option 0))) + "type index out of bounds") +(assert_invalid + (component (type (list 0))) + "type index out of bounds") +(assert_invalid + (component (type (record (field "x" 0)))) + "type index out of bounds") +(assert_invalid + (component (type (variant (case "x" 0)))) + "type index out of bounds") +(assert_invalid + (component (type (result 0 (error 1)))) + "type index out of bounds") +(assert_invalid + (component (type (tuple 0))) + "type index out of bounds") + +;; indices ascribed to imports and exports or used by canon lift must also be +;; in bounds + +(assert_invalid + (component (import "a" (func (type 100)))) + "type index out of bounds") +(assert_invalid + (component + (core module $m (func (export "f"))) + (core instance $i (instantiate $m)) + (func (type 100) (canon lift (core func $i "f")))) + "type index out of bounds") +(assert_invalid + (component (export "a" (core module 0))) + "module index out of bounds") +(assert_invalid + (component (export "a" (instance 0))) + "instance index out of bounds") + +;; a type ascribed to a func import/export must be a function type + +(assert_invalid + (component + (type $t (instance)) + (import "a" (func (type $t)))) + "type index 0 is not a function type") +(assert_invalid + (component + (type $t (instance)) + (core module $m (func (export "f"))) + (core instance $i (instantiate $m)) + (func $f (canon lift (core func $i "f"))) + (export "a" (func $f) (func (type $t)))) + "type index 0 is not a function type") +(assert_invalid + (component + (type $t (instance)) + (type (component + (import "a" (func (type $t)))))) + "type index 0 is not a function type") +(assert_invalid + (component + (type $t (record (field "x" u8))) + (type (instance + (export "a" (func (type $t)))))) + "type index 0 is not a function type") +(assert_invalid + (component + (type $t (instance)) + (type (instance + (export "a" (instance + (export "b" (func (type $t)))))))) + "type index 0 is not a function type") + +;; ...an instance import/export must be an instance type + +(assert_invalid + (component + (type $t (func)) + (import "a" (instance (type $t)))) + "type index 0 is not an instance type") +(assert_invalid + (component + (type $t (func)) + (type (component + (import "a" (instance (type $t)))))) + "type index 0 is not an instance type") +(assert_invalid + (component + (type $t (func)) + (type (instance + (export "a" (instance (type $t)))))) + "type index 0 is not an instance type") + +;; ...a core module import/export must be a core module type + +(assert_invalid + (component + (core type $t (func)) + (import "a" (core module (type $t)))) + "core type index 0 is not a module type") +(assert_invalid + (component + (core type $t (func)) + (type (component + (import "a" (core module (type $t)))))) + "core type index 0 is not a module type") +(assert_invalid + (component + (core type $t (func)) + (type (instance + (export "a" (core module (type $t)))))) + "core type index 0 is not a module type") diff --git a/test/validation/extern-names.wast b/test/validation/extern-names.wast new file mode 100644 index 00000000..233921da --- /dev/null +++ b/test/validation/extern-names.wast @@ -0,0 +1,58 @@ +;; Test the extern-name grammar beyond plain kebab names (covered by +;; kebab.wast): versioned interface names, semver parsing, exclusion of +;; non-name forms and the (interface "...") id-form sugar. + +;; the same interface name may coexist unversioned and at multiple versions, +;; but exact duplicates still conflict + +(component definition + (import "wasi:http/types" (func)) + (import "wasi:http/types@1.0.0" (func)) + (import "wasi:http/types@2.0.0" (func)) + (import "a-b:c-d/e-f@123456.7890.488" (func)) + (import "a:b/c@0.0.0+abcd" (func)) + (import "a:b/c@0.0.0+abcd-efg" (func)) + (import "a:b/c@0.0.0-abcd+efg" (func)) + (import "a:b/c@0.0.0-abcd.1.2+efg.4.ee.5" (func)) +) +(assert_invalid + (component + (import "wasi:http/types@1.0.0" (func)) + (import "wasi:http/types@1.0.0" (func))) + "conflicts with previous name") + +;; malformed versions + +(assert_invalid + (component (import "a:b/c@" (func))) + "empty string") +(assert_invalid + (component (import "a:b/c@." (func))) + "unexpected character '.'") +(assert_invalid + (component (import "a:b/c@1." (func))) + "unexpected end of input") +(assert_invalid + (component (import "a:b/c@a.2" (func))) + "unexpected character 'a'") +(assert_invalid + (component (import "a:b/c@2.b" (func))) + "unexpected character 'b'") +(assert_invalid + (component (import "a:b/c@2.0x0" (func))) + "unexpected character 'x'") +(assert_invalid + (component (import "a:b/c@2.0.0+" (func))) + "empty identifier segment") +(assert_invalid + (component (import "a:b/c@2.0.0-" (func))) + "empty identifier segment") + +;; nested namespaces and nested projections are gated (🪺) future syntax + +(assert_invalid + (component (import "foo:bar:baz/qux" (func))) + "expected `/` after package name") +(assert_invalid + (component (import "foo:bar/baz/qux" (func))) + "trailing characters found: `/qux`") diff --git a/test/validation/external-visibility.wast b/test/validation/external-visibility.wast index 804cd120..afc6cf5c 100644 --- a/test/validation/external-visibility.wast +++ b/test/validation/external-visibility.wast @@ -214,3 +214,392 @@ (instance $bag (export "f" (func $f))) (export "bag" (instance $bag))) "instance not valid to be used as export") + +;; direct type exports: anonymous structural types need no name + +(component definition + (type $T1 (tuple (tuple u32))) + (export "t1" (type $T1)) + (type $T2 (option (tuple (list u8) (result (list u32) (error (option string)))))) + (export "t2" (type $T2)) + (type $T3 u32) + (export "t3" (type $T3))) + +;; ...but a named type referenced by an exported type must itself be +;; exported first, whatever position it's referenced from + +(assert_invalid + (component + (type $Rec (record (field "x" u32))) + (type $Rec2 (record (field "r" $Rec))) + (export "t" (type $Rec2))) + "type not valid to be used as export") + +(assert_invalid + (component + (type $Rec (record (field "x" u32))) + (type $L (list $Rec)) + (export "t" (type $L))) + "type not valid to be used as export") + +(assert_invalid + (component + (type $Rec (record (field "x" u32))) + (type $T (tuple $Rec)) + (export "t" (type $T))) + "type not valid to be used as export") + +(assert_invalid + (component + (type $Rec (record (field "x" u32))) + (type $V (variant (case "c" $Rec))) + (export "t" (type $V))) + "type not valid to be used as export") + +(assert_invalid + (component + (type $Rec (record (field "x" u32))) + (type $O (option $Rec)) + (export "t" (type $O))) + "type not valid to be used as export") + +(assert_invalid + (component + (type $Rec (record (field "x" u32))) + (type $Res (result $Rec)) + (export "t" (type $Res))) + "type not valid to be used as export") + +;; every nameable kind (not just records) needs a name + +(assert_invalid + (component + (type $E (enum "a")) + (type $L (list $E)) + (export "t" (type $L))) + "type not valid to be used as export") + +(assert_invalid + (component + (type $Fl (flags "a")) + (type $L (list $Fl)) + (export "t" (type $L))) + "type not valid to be used as export") + +(assert_invalid + (component + (type $V (variant (case "a"))) + (type $L (list $V)) + (export "t" (type $L))) + "type not valid to be used as export") + +(assert_invalid + (component + (type $R (resource (rep i32))) + (type $L (list (own $R))) + (export "t" (type $L))) + "type not valid to be used as export") + +;; type imports enforce the same restrictions; importing the inner type first +;; makes it valid + +(component definition + (type $Rec (record (field "x" u32))) + (import "rec" (type $Rec' (eq $Rec))) + (type $Rec2 (record (field "r" $Rec'))) + (import "t" (type (eq $Rec2)))) + +(assert_invalid + (component + (type $Rec (record (field "x" u32))) + (type $Rec2 (record (field "r" $Rec))) + (import "t" (type (eq $Rec2)))) + "type not valid to be used as import") + +;; an instance type containing an unexportable type export is definable, but +;; not usable as a type import or export; same for func types + +(component definition + (type (instance + (type $Rec (record (field "x" u32))) + (type $Rec2 (record (field "r" $Rec))) + (export "t" (type (eq $Rec2)))))) + +(assert_invalid + (component + (type $I (instance + (type $Rec (record (field "x" u32))) + (type $Rec2 (record (field "r" $Rec))) + (export "t" (type (eq $Rec2))))) + (import "i" (type (eq $I)))) + "type not valid to be used as import") + +(assert_invalid + (component + (type $I (instance + (type $Rec (record (field "x" u32))) + (type $Rec2 (record (field "r" $Rec))) + (export "t" (type (eq $Rec2))))) + (export "i" (type $I))) + "type not valid to be used as export") + +(assert_invalid + (component + (type $Rec (record (field "x" u32))) + (type $F (func (result $Rec))) + (import "f" (type (eq $F)))) + "type not valid to be used as import") + +(assert_invalid + (component + (type $Rec (record (field "x" u32))) + (type $F (func (result $Rec))) + (export "f" (type $F))) + "type not valid to be used as export") + +;; instance types defer visibility validation until attached to a concrete +;; import or export; component types validate eagerly + +(component definition + (type (instance + (type $Rec (record (field "x" u32))) + (export "f" (func (param "x" $Rec)))))) + +(assert_invalid + (component + (type $I (instance + (type $Rec (record (field "x" u32))) + (type $Rec2 (record (field "r" $Rec))) + (export "t" (type (eq $Rec2))))) + (import "i" (instance (type $I)))) + "instance not valid to be used as import") + +(assert_invalid + (component + (type (component + (type $Rec (record (field "x" u32))) + (export "f" (func (param "x" $Rec)))))) + "func not valid to be used as export") + +(assert_invalid + (component + (type (component + (type $Rec (record (field "x" u32))) + (type $Rec2 (record (field "r" $Rec))) + (export "t" (type (eq $Rec2)))))) + "type not valid to be used as export") + +;; within a component type, an import may not reference a preceding export's +;; resource +(assert_invalid + (component + (type (component + (export "r" (type $R (sub resource))) + (import "f" (func (result (own $R))))))) + "func not valid to be used as import") + +;; a local unexported synthesized instance may export unexportable types +(component definition + (type $Rec (record (field "x" u32))) + (type $Rec2 (record (field "r" $Rec))) + (instance (export "t" (type $Rec2)))) + +;; aliasing a type through an exported instance confers a name; aliasing out +;; of an unexported synthesized instance or an instantiated child does not + +(component definition + (core module $m (func (export "f") (param i32))) + (core instance $i (instantiate $m)) + (type $Rec (record (field "x" u32))) + (instance $bag (export "t" (type $Rec))) + (export $bag' "i" (instance $bag)) + (alias export $bag' "t" (type $Rec')) + (func $f (param "r" $Rec') (canon lift (core func $i "f"))) + (export "f" (func $f))) + +(component definition + (core module $m (func (export "f") (param i32))) + (core instance $i (instantiate $m)) + (component $C + (type $Rec (record (field "x" u32))) + (export "t" (type $Rec))) + (instance $c (instantiate $C)) + (export $c' "i" (instance $c)) + (alias export $c' "t" (type $Rec)) + (func $f (param "r" $Rec) (canon lift (core func $i "f"))) + (export "f" (func $f))) + +(assert_invalid + (component + (core module $m (func (export "f") (param i32))) + (core instance $i (instantiate $m)) + (type $Rec (record (field "x" u32))) + (instance $bag (export "t" (type $Rec))) + (alias export $bag "t" (type $Rec')) + (func $f (param "r" $Rec') (canon lift (core func $i "f"))) + (export "f" (func $f))) + "func not valid to be used as export") + +(assert_invalid + (component + (core module $m (func (export "f") (param i32))) + (core instance $i (instantiate $m)) + (component $C + (type $Rec (record (field "x" u32))) + (export "t" (type $Rec))) + (instance $c (instantiate $C)) + (alias export $c "t" (type $Rec)) + (func $f (param "r" $Rec) (canon lift (core func $i "f"))) + (export "f" (func $f))) + "func not valid to be used as export") + +;; re-exporting an instance aliased from a child does not confer visibility on +;; the types referenced by the instance's exports +(assert_invalid + (component + (component $A + (core module $m (func (export "f") (result i32) unreachable)) + (core instance $i (instantiate $m)) + (type $Rec (record (field "x" u32))) + (export $Rec' "t" (type $Rec)) + (func $f (result $Rec') (canon lift (core func $i "f"))) + (instance $bag (export "f" (func $f))) + (export "i" (instance $bag))) + (instance $a (instantiate $A)) + ;; only "i" is re-exported here, not the record type "t" behind it + (export "i2" (instance $a "i"))) + "instance not valid to be used as export") + +;; visibility threads through instantiation plus re-export of the child's +;; exported type +(component definition + (type $Rec (record (field "x" u32))) + (import "t" (type $Rec' (eq $Rec))) + (component $C + (type $Rec (record (field "x" u32))) + (import "t" (type $Rec' (eq $Rec))) + (type $Rec2 (record (field "r" $Rec'))) + (export "t2" (type $Rec2))) + (instance $c (instantiate $C (with "t" (type $Rec')))) + (export "t2" (type $c "t2"))) + +;; outer-aliased types imported/exported only in the parent confer no +;; visibility in the child + +(assert_invalid + (component + (type $Rec (record (field "x" u32))) + (import "t" (type $Rec' (eq $Rec))) + (component + (import "f" (func (result $Rec'))))) + "func not valid to be used as import") + +(assert_invalid + (component + (type $Rec (record (field "x" u32))) + (export $Rec' "t" (type $Rec)) + (component + (core module $m (func (export "f") (result i32) unreachable)) + (core instance $i (instantiate $m)) + (func $f (result $Rec') (canon lift (core func $i "f"))) + (export "f" (func $f)))) + "func not valid to be used as export") + +;; bags-of-exports count as "explicit in" for resources: synthesized, +;; transitive, instantiated, or threaded through nested instance-typed imports + +(component definition + (type $R (resource (rep i32))) + (instance $bag (export "r" (type $R))) + (export $bag' "i" (instance $bag)) + (alias export $bag' "r" (type $R')) + (core func $drop (canon resource.drop $R')) + (func $f (param "x" (own $R')) (canon lift (core func $drop))) + (export "f" (func $f))) + +(component definition + (type $R (resource (rep i32))) + (instance $bag (export "r" (type $R))) + (instance $bag2 (export "i" (instance $bag))) + (export $bag2' "i2" (instance $bag2)) + (alias export $bag2' "i" (instance $i)) + (alias export $i "r" (type $R')) + (core func $drop (canon resource.drop $R')) + (func $f (param "x" (own $R')) (canon lift (core func $drop))) + (export "f" (func $f))) + +(component definition + (type $R (resource (rep i32))) + (component $C + (import "x" (type $X (sub resource))) + (export "y" (type $X))) + (instance $c (instantiate $C (with "x" (type $R)))) + (export $c' "c" (instance $c)) + (alias export $c' "y" (type $R')) + (core func $drop (canon resource.drop $R')) + (func $f (param "x" (own $R')) (canon lift (core func $drop))) + (export "f" (func $f))) + +(component definition + (type $R (resource (rep i32))) + (component $C + (import "x" (type $X (sub resource))) + (export "y" (type $X))) + (instance $c (instantiate $C (with "x" (type $R)))) + (instance $ix (export "x" (type $c "y"))) + (component $C2 + (import "x" (instance $i + (export "i1" (instance + (export "i2" (type (sub resource))))))) + (export "y" (type $i "i1" "i2"))) + (instance $i2 (export "i2" (type $ix "x"))) + (instance $i1 (export "i1" (instance $i2))) + (instance $c2 (instantiate $C2 (with "x" (instance $i1)))) + (export $R' "r" (type $c2 "y")) + (core func $drop (canon resource.drop $R')) + (func $f (param "x" (own $R')) (canon lift (core func $drop))) + (export "f" (func $f))) + +(component definition + (type $R (resource (rep i32))) + (component $C + (import "x" (instance $x (export "t" (type (sub resource))))) + (export "y" (instance $x))) + (instance $c (instantiate $C + (with "x" (instance (export "t" (type $R)))))) + (export $c' "c" (instance $c)) + (alias export $c' "y" (instance $y)) + (alias export $y "t" (type $R')) + (core func $drop (canon resource.drop $R')) + (func $f (param "x" (own $R')) (canon lift (core func $drop))) + (export "f" (func $f))) + +;; export ascription is a one-directional subtype check: forgetting exports is +;; an allowed up-cast, adding them is not + +(component definition + (core module $m (func (export "f"))) + (core instance $i (instantiate $m)) + (func $f (canon lift (core func $i "f"))) + (instance $inst (export "f" (func $f))) + (export "f2" (instance $inst) (instance))) + +(assert_invalid + (component + (import "f" (instance $i)) + (export "f2" (instance $i) (instance (export "f" (func))))) + "ascribed type of export is not compatible") + +;; ascription replaces the visible type: the export ascribed to an empty +;; instance no longer satisfies a consumer requiring "f" +(assert_invalid + (component + (import "f" (func $f)) + (component $C + (import "f" (instance $i (export "f" (func)))) + (export "f2" (instance $i) (instance))) + (instance $c (instantiate $C (with "f" (instance (export "f" (func $f)))))) + (component $Consume + (import "arg" (instance (export "f" (func))))) + (instance (instantiate $Consume (with "arg" (instance $c "f2"))))) + "missing expected export `f`") diff --git a/test/validation/indicies.wast b/test/validation/indicies.wast index d7d1bb66..38e88826 100644 --- a/test/validation/indicies.wast +++ b/test/validation/indicies.wast @@ -1,3 +1,6 @@ +;; Text-format index and name forms: inline aliases and sugar in each position, +;; and how definitions, imports, aliases and exports introduce new indices. + ;; test component instantiate parsing (component (component @@ -66,6 +69,18 @@ ) ) +;; test alias sugar in instantiate target position +(component + (component + (import "a" (instance $i (export "x" (core module)))) + (core instance (instantiate (module $i "x"))) + ) + (component + (import "a" (instance $i (export "x" (component)))) + (instance (instantiate (component $i "x"))) + ) +) + ;; test canon lower parsing (component (component @@ -204,6 +219,19 @@ ) ) +;; test inverted and anonymous canon resource built-in forms +(component + (component + (type $r (resource (rep i32))) + (core func (canon resource.new $r)) + (canon resource.new $r (core func)) + (core func (canon resource.drop $r)) + (canon resource.drop $r (core func)) + (core func (canon resource.rep $r)) + (canon resource.rep $r (core func)) + ) +) + ;; test waitable-set.wait/poll parsing (component (component @@ -247,3 +275,115 @@ (canon future.new (type $i "T") (core func)) ) ) + +;; test alias sugar in export position +(component + (component + (import "a" (instance $foo + (export "v" (component)) + (export "m" (core module)))) + (export "v" (component $foo "v")) + (export "w" (core module $foo "m")) + ) +) + +;; test inline export sugar on definitions +(component + (component + (type (export "foo") u8) + (core module (export "x")) + ) +) + +;; test inline import sugar on instance declarations +(component + (component + (type $empty (instance)) + (instance $d (import "g") (type $empty)) + (instance (import "h")) + (instance (import "i") + (export "x" (func))) + (instance (export "j") (export "k") (import "x")) + ) +) + +;; test standalone core module type declarators +(component + (component + (core type (module)) + (core type (module + (type $f (func (param i32) (result i32))) + (import "a" "b" (func (type $f))) + (export "c" (func (type $f))) + )) + ) + (component + ;; module imports and core module types live in distinct index spaces + (import "a" (core module)) + (core type (module)) + ) +) + +;; test module definitions interleaved with module imports and aliases +(component + (component + (core module + (func (export ""))) + (import "a" (core module)) + (core module + (func (export "") (result i32) i32.const 5)) + (import "b" (instance (export "a" (core module)))) + (alias export 0 "a" (core module)) + ) +) + +;; test that exports introduce new indices +(component + (component + (component + (component + (component) + (instance (instantiate 0)) + (export "a" (instance 0)) + ) + (instance (instantiate 0)) + (export "a" (instance 0)) + ) + (instance (instantiate 0)) ;; instance 0 + (alias export 0 "a" (instance)) ;; instance 1 + (export "a" (instance 1)) ;; instance 2 + (alias export 2 "a" (instance)) ;; instance 3 + (export "inner-a" (instance 3)) ;; instance 4 + ) + (component + (component + (core module) + (export "a" (core module 0)) + ) + (instance (instantiate 0)) + (alias export 0 "a" (core module)) ;; core module 0 + (export "a" (core module 0)) ;; core module 1 + (core instance (instantiate 1)) + ) +) + +;; test core global alias parsing +(component + (component + (core module $M + (global (export "g") i32 (i32.const 0)) + (global (export "gm") (mut i64) (i64.const 0))) + (core instance $m (instantiate $M)) + (alias core export $m "g" (core global $g)) + (alias core export $m "gm" (core global $gm)) + (core module $N + (import "" "g" (global i32)) + (import "" "gm" (global (mut i64)))) + (core instance (instantiate $N (with "" (instance + (export "g" (global $g)) + (export "gm" (global $gm)))))) + (core instance (instantiate $N (with "" (instance + (export "g" (global $m "g")) + (export "gm" (global $m "gm")))))) + ) +) diff --git a/test/validation/instantiation.wast b/test/validation/instantiation.wast new file mode 100644 index 00000000..b6f113a6 --- /dev/null +++ b/test/validation/instantiation.wast @@ -0,0 +1,666 @@ +;; Instantiation-time type checking: matching `with` arguments against the +;; instantiated component's or core module's declared imports, and validating +;; synthesized (bag-of-exports) instances. + +;; type arguments must structurally match `eq`-bounded type imports + +(component + (type $t (tuple u32 u32)) + (component $c + (type $t (tuple u32 u32)) + (import "x" (type (eq $t)))) + (instance (instantiate $c (with "x" (type $t))))) + +(assert_invalid + (component + (component $c + (type $t (tuple u32 u32)) + (import "x" (type (eq $t)))) + (type $x (tuple string string)) + (instance (instantiate $c (with "x" (type $x))))) + "expected primitive `u32` found primitive `string`") + +(assert_invalid + (component + (component $c + (type $t u32) + (import "x" (type (eq $t)))) + (type $x (record (field "f" u32))) + (instance (instantiate $c (with "x" (type $x))))) + "expected primitive, found record") + +(assert_invalid + (component + (component $c + (type $t (record (field "f" u32))) + (import "x" (type (eq $t)))) + (type $x u32) + (instance (instantiate $c (with "x" (type $x))))) + "expected record, found u32") + +(assert_invalid + (component + (component $c + (type $t (record (field "x" u32))) + (import "x" (type (eq $t)))) + (type $f (tuple u8)) + (type $x (record (field "x" $f))) + (instance (instantiate $c (with "x" (type $x))))) + "expected u32, found tuple") + +(assert_invalid + (component + (component $c + (type $f (option s32)) + (type $t (record (field "x" $f))) + (import "x" (type (eq $t)))) + (type $x (record (field "x" u32))) + (instance (instantiate $c (with "x" (type $x))))) + "type mismatch in record field `x`") + +(assert_invalid + (component + (component $c + (type $t (record (field "x" u32))) + (import "x" (type (eq $t)))) + (type $x (record (field "y" u32) (field "z" u64))) + (instance (instantiate $c (with "x" (type $x))))) + "expected 1 fields, found 2") + +(assert_invalid + (component + (component $c + (type $t (record (field "a" u32))) + (import "x" (type (eq $t)))) + (type $x (record (field "b" u32))) + (instance (instantiate $c (with "x" (type $x))))) + "expected field name `a`, found `b`") + +(assert_invalid + (component + (component $c + (type $t (variant (case "x" u32))) + (import "x" (type (eq $t)))) + (type $x (variant (case "x" u32) (case "y" u32))) + (instance (instantiate $c (with "x" (type $x))))) + "expected 1 cases, found 2") + +(assert_invalid + (component + (component $c + (type $t (variant (case "x" u32))) + (import "x" (type (eq $t)))) + (type $x (variant (case "y" u32))) + (instance (instantiate $c (with "x" (type $x))))) + "expected case named `x`, found `y`") + +(assert_invalid + (component + (component $c + (type $t (variant (case "x" u32))) + (import "x" (type (eq $t)))) + (type $x (variant (case "x"))) + (instance (instantiate $c (with "x" (type $x))))) + "expected case `x` to have a type, found none") + +(assert_invalid + (component + (component $c + (type $t (variant (case "x"))) + (import "x" (type (eq $t)))) + (type $x (variant (case "x" u32))) + (instance (instantiate $c (with "x" (type $x))))) + "expected case `x` to have no type") + +(assert_invalid + (component + (component $c + (type $t (variant (case "x" u32))) + (import "x" (type (eq $t)))) + (type $x (variant (case "x" s32))) + (instance (instantiate $c (with "x" (type $x))))) + "type mismatch in variant case `x`") + +(assert_invalid + (component + (component $c + (type $t (tuple u8)) + (import "x" (type (eq $t)))) + (type $x (tuple u32 u32)) + (instance (instantiate $c (with "x" (type $x))))) + "expected 1 types, found 2") + +(assert_invalid + (component + (component $c + (type $t (tuple u8)) + (import "x" (type (eq $t)))) + (type $x (tuple u16)) + (instance (instantiate $c (with "x" (type $x))))) + "type mismatch in tuple field 0") + +(assert_invalid + (component + (component $c + (type $t (flags "a")) + (import "x" (type (eq $t)))) + (type $x (flags "x")) + (instance (instantiate $c (with "x" (type $x))))) + "mismatch in flags elements") + +(assert_invalid + (component + (component $c + (type $t (enum "a")) + (import "x" (type (eq $t)))) + (type $x (enum "x")) + (instance (instantiate $c (with "x" (type $x))))) + "mismatch in enum elements") + +(assert_invalid + (component + (component $c + (type $t (result s32)) + (import "x" (type (eq $t)))) + (type $x (result u32)) + (instance (instantiate $c (with "x" (type $x))))) + "type mismatch in ok variant") + +(assert_invalid + (component + (component $c + (type $t (result (error s32))) + (import "x" (type (eq $t)))) + (type $x (result (error u32))) + (instance (instantiate $c (with "x" (type $x))))) + "type mismatch in err variant") + +(assert_invalid + (component + (component $c + (type $t (result)) + (import "x" (type (eq $t)))) + (type $x (result u32)) + (instance (instantiate $c (with "x" (type $x))))) + "expected ok type to not be present") + +(assert_invalid + (component + (component $c + (type $t (result u32)) + (import "x" (type (eq $t)))) + (type $x (result)) + (instance (instantiate $c (with "x" (type $x))))) + "expected ok type, but found none") + +(assert_invalid + (component + (component $c + (type $t (result)) + (import "x" (type (eq $t)))) + (type $x (result (error u32))) + (instance (instantiate $c (with "x" (type $x))))) + "expected err type to not be present") + +(assert_invalid + (component + (component $c + (type $t (result (error u32))) + (import "x" (type (eq $t)))) + (type $x (result)) + (instance (instantiate $c (with "x" (type $x))))) + "expected err type, but found none") + + +;; function arguments must match the imported function type exactly, +;; including parameter names + +(component definition + (import "f" (func $f (param "x" u32) (result u32))) + (component $c (import "f" (func (param "x" u32) (result u32)))) + (instance (instantiate $c (with "f" (func $f))))) + +(assert_invalid + (component + (import "f" (func $f (result string))) + (component $c (import "f" (func))) + (instance (instantiate $c (with "f" (func $f))))) + "expected a result, found none") + +(assert_invalid + (component + (import "f" (func $f (param "x" string))) + (component $c (import "f" (func))) + (instance (instantiate $c (with "f" (func $f))))) + "expected 0 parameters, found 1") + +(assert_invalid + (component + (import "f" (func $f (param "x" u32))) + (component $c (import "f" (func (param "y" u32)))) + (instance (instantiate $c (with "f" (func $f))))) + "expected parameter named `y`, found `x`") + +(assert_invalid + (component + (import "f" (func $f (param "x" u32))) + (component $c (import "f" (func (param "x" s32)))) + (instance (instantiate $c (with "f" (func $f))))) + "type mismatch in function parameter `x`") + +(assert_invalid + (component + (import "f" (func $f (result u32))) + (component $c (import "f" (func (result s32)))) + (instance (instantiate $c (with "f" (func $f))))) + "type mismatch with result type") + + +;; instance arguments are checked export-by-export, including the sort; extra +;; exports beyond the imported instance type are allowed + +(component definition + (import "i" (instance $i + (export "a" (func)) + (export "b" (func)))) + (component $c (import "i" (instance (export "a" (func))))) + (instance (instantiate $c (with "i" (instance $i))))) + +(assert_invalid + (component + (import "i" (instance $i (export "a" (func)))) + (component $c (import "i" (instance (export "a" (component))))) + (instance (instantiate $c (with "i" (instance $i))))) + "type mismatch in instance export `a`") + + +;; core module arguments are checked by core subtyping: imports +;; contravariantly (the supplied module may import less) and exports +;; covariantly (it may export more) + +(component + (core module $m (import "" "g" (global i32))) + (component $c + (import "m" (core module + (import "" "g" (global i32)) + (import "" "f" (func))))) + (instance (instantiate $c (with "m" (core module $m))))) + +(component + (core module $m + (func (export "f")) + (global (export "g") i32 (i32.const 0))) + (component $c + (import "m" (core module (export "f" (func))))) + (instance (instantiate $c (with "m" (core module $m))))) + +(assert_invalid + (component + (core module $m (import "" "f" (global i32))) + (component $c + (import "m" (core module (import "" "f" (func))))) + (instance (instantiate $c (with "m" (core module $m))))) + "type mismatch in import `::f`") + +(assert_invalid + (component + (core module $m (import "" "extra" (global i32))) + (component $c + (import "m" (core module))) + (instance (instantiate $c (with "m" (core module $m))))) + "missing expected import `::extra`") + +(assert_invalid + (component + (core module $m) + (component $c + (import "m" (core module (export "x" (func))))) + (instance (instantiate $c (with "m" (core module $m))))) + "missing expected export `x`") + +(assert_invalid + (component + (core module $m (func (export "g"))) + (component $c + (import "m" (core module (export "g" (global i32))))) + (instance (instantiate $c (with "m" (core module $m))))) + "type mismatch in export `g`") + +;; table/memory limits are covariant on the export side and contravariant on +;; the import side + +(component + (core module $m + (import "" "t" (table 1 funcref)) + (table (export "x") 2 funcref)) + (component $c + (import "m" (core module + (import "" "t" (table 2 funcref)) + (export "x" (table 1 funcref))))) + (instance (instantiate $c (with "m" (core module $m))))) + +(component + (core module $m + (import "" "m" (memory 1)) + (memory (export "x") 2)) + (component $c + (import "m" (core module + (import "" "m" (memory 2)) + (export "x" (memory 1))))) + (instance (instantiate $c (with "m" (core module $m))))) + + +;; core instance arguments: each two-level import is looked up in the instance +;; supplied for its module name and checked by core subtyping, including sort + +(assert_invalid + (component + (core module $m1 (import "" "f" (func))) + (core module $m2 (func (export "f") (param i32))) + (core instance $i (instantiate $m2)) + (core instance (instantiate $m1 (with "" (instance $i))))) + "expected: (func)") + +(assert_invalid + (component + (core module $m1 (import "" "f" (func))) + (core module $m2 (func (export "f") (result i32) (i32.const 0))) + (core instance $i (instantiate $m2)) + (core instance (instantiate $m1 (with "" (instance $i))))) + "expected: (func)") + +(assert_invalid + (component + (core module $m1 (import "" "f" (func))) + (core module $m2 (func (export "g") (param i32))) + (core instance $i (instantiate $m2)) + (core instance (instantiate $m1 + (with "" (instance (export "f" (func $i "g"))))))) + "expected: (func)") + +(assert_invalid + (component + (core module $m1 (import "" "g" (global i32))) + (core module $m2 (global (export "g") i64 (i64.const 0))) + (core instance $i (instantiate $m2)) + (core instance (instantiate $m1 (with "" (instance $i))))) + "expected global type i32, found i64") + +(assert_invalid + (component + (core module $m1 (import "" "t" (table 1 funcref))) + (core module $m2 (table (export "t") 2 externref)) + (core instance $i (instantiate $m2)) + (core instance (instantiate $m1 (with "" (instance $i))))) + "expected table element type funcref, found externref") + +(assert_invalid + (component + (core module $m1 (import "" "t" (table 2 2 funcref))) + (core module $m2 (table (export "t") 1 funcref)) + (core instance $i (instantiate $m2)) + (core instance (instantiate $m1 (with "" (instance $i))))) + "mismatch in table limits") + +(assert_invalid + (component + (core module $m1 (import "" "t" (table 1 2 funcref))) + (core module $m2 (table (export "t") 2 funcref)) + (core instance $i (instantiate $m2)) + (core instance (instantiate $m1 (with "" (instance $i))))) + "mismatch in table limits") + +(assert_invalid + (component + (core module $m1 (import "" "t" (table 2 2 funcref))) + (core module $m2 (table (export "t") 2 3 funcref)) + (core instance $i (instantiate $m2)) + (core instance (instantiate $m1 (with "" (instance $i))))) + "mismatch in table limits") + +(assert_invalid + (component + (core module $m1 (import "" "m" (memory 1 2 shared))) + (core module $m2 (memory (export "m") 1)) + (core instance $i (instantiate $m2)) + (core instance (instantiate $m1 (with "" (instance $i))))) + "mismatch in the shared flag for memories") + +(assert_invalid + (component + (core module $m1 (import "" "m" (memory 1))) + (core module $m2 (memory (export "m") 0)) + (core instance $i (instantiate $m2)) + (core instance (instantiate $m1 (with "" (instance $i))))) + "mismatch in memory limits") + +(assert_invalid + (component + (core module $m1 (import "a" "b" (global i32))) + (core module $m2 (func (export "b"))) + (core instance $i (instantiate $m2)) + (core instance (instantiate $m1 (with "a" (instance $i))))) + "expected global, found func") + +;; every imported module name needs an argument, and the supplied instance +;; must cover every field imported from that name + +(assert_invalid + (component + (core module $m (import "" "f" (func))) + (core instance (instantiate $m))) + "missing module instantiation argument") + +(assert_invalid + (component + (core module $libc + (memory (export "memory") 1) + (table (export "table") 0 funcref)) + (core instance $libc (instantiate $libc)) + (core module $needs + (import "" "memory" (memory 1)) + (import "" "table" (table 0 funcref))) + (core instance (instantiate $needs + (with "" (instance (export "memory" (memory $libc "memory"))))))) + "does not export an item named `table`") + + +;; superfluous arguments are ignored, and argument names are uninterpreted +;; (in particular, not validated as kebab-case) + +(component + (component $c) + (instance $i (instantiate $c)) + (instance (instantiate $c (with "extra" (instance $i))))) + +(component + (component $c) + (instance $i (instantiate $c)) + (instance (instantiate $c (with "NotKebab-Case" (instance $i))))) + +;; `with` arguments: the argument's sort must match the import's sort + +(assert_invalid + (component + (component $c (import "a" (func))) + (component $d) + (instance (instantiate $c (with "a" (component $d))))) + "expected func, found component") + +(assert_invalid + (component + (component $x) + (instance $i (instantiate $x)) + (component $c (import "x" (component))) + (instance (instantiate $c (with "x" (instance $i))))) + "expected component, found instance") + +;; duplicate argument names are disallowed + +(assert_invalid + (component + (core module $m) + (core instance $i (instantiate $m)) + (core instance (instantiate $m + (with "a" (instance $i)) + (with "a" (instance $i))))) + "duplicate module instantiation argument named `a`") + +(assert_invalid + (component + (component $c) + (instance $i (instantiate $c)) + (instance (instantiate $c + (with "a" (instance $i)) + (with "a" (instance $i))))) + "instantiation argument `a` conflicts with previous argument `a`") + + +;; synthesized instances reject duplicate export names + +(assert_invalid + (component + (component $c) + (instance + (export "a" (component $c)) + (export "a" (component $c)))) + "export name `a` conflicts with previous name `a`") + +(assert_invalid + (component + (core module $m (func (export "f"))) + (core instance $i (instantiate $m)) + (core instance + (export "a" (func $i "f")) + (export "a" (func $i "f")))) + "export name `a` already defined") + + +;; instantiating an index that was never defined + +(assert_invalid + (component + (core instance (instantiate 0))) + "unknown module") + +(assert_invalid + (component + (instance (instantiate 0))) + "unknown component") + +(assert_invalid + (component + (import "a" (core module)) + (core instance (instantiate 1))) + "unknown module") + +;; out-of-bounds sort indices in synthesized instance exports + +(assert_invalid + (component (instance (export "a" (func 0)))) + "index out of bounds") + +(assert_invalid + (component (instance (export "a" (instance 0)))) + "index out of bounds") + +(assert_invalid + (component (instance (export "a" (component 0)))) + "index out of bounds") + +(assert_invalid + (component (instance (export "a" (core module 0)))) + "index out of bounds") + +(assert_invalid + (component (core instance (export "a" (func 0)))) + "index out of bounds") + +(assert_invalid + (component (core instance (export "a" (table 0)))) + "index out of bounds") + +(assert_invalid + (component (core instance (export "a" (global 0)))) + "index out of bounds") + +(assert_invalid + (component (core instance (export "a" (memory 0)))) + "index out of bounds") + +;; out-of-bounds `with` argument indices + +(assert_invalid + (component + (component $c) + (instance (instantiate $c (with "a" (core module 0))))) + "index out of bounds") + +(assert_invalid + (component + (component $c) + (instance (instantiate $c (with "a" (instance 0))))) + "index out of bounds") + +(assert_invalid + (component + (component $c) + (instance (instantiate $c (with "a" (func 0))))) + "index out of bounds") + +(assert_invalid + (component + (component $c) + (instance (instantiate $c (with "a" (component 100))))) + "index out of bounds") + +;; projecting a nonexistent export out of an instance + +(assert_invalid + (component + (component $c) + (instance $i (instantiate $c)) + (export "a" (instance $i "a"))) + "no export named `a`") + +(assert_invalid + (component + (export "a" (instance 100 "a"))) + "index out of bounds") + +(assert_invalid + (component + (instance) + (alias export 0 "Xml" (func))) + "instance 0 has no export named `Xml`") + +(assert_invalid + (component + (core module $m) + (core instance $i (instantiate $m)) + (alias core export $i "a" (core func))) + "core instance 0 has no export named `a`") + +(assert_invalid + (component + (import "a" (component $c)) + (instance $i (instantiate $c)) + (alias export $i "a" (func))) + "instance 0 has no export named `a`") + +;; projecting an export that exists but has the wrong sort + +(assert_invalid + (component + (import "a" (instance (export "a" (func)))) + (export "a" (core module 0 "a"))) + "is not a module") + +(assert_invalid + (component + (component $c + (component $inner) + (export "a" (component $inner))) + (instance $i (instantiate $c)) + (export "a" (core module $i "a"))) + "is not a module") diff --git a/test/validation/kebab.wast b/test/validation/kebab.wast index df135f87..478677ac 100644 --- a/test/validation/kebab.wast +++ b/test/validation/kebab.wast @@ -1,3 +1,6 @@ +;; Validation of kebab-case plain names and `ns:pkg/iface` extern names, and +;; case-insensitive uniqueness of import/export names. + (component (component (import "a" (func)) (import "a1" (func)) @@ -30,10 +33,42 @@ (component (import "a--" (func))) "is not in kebab case") +(assert_invalid + (component + (import "aBc" (func))) + "`aBc` is not in kebab case") (assert_invalid (component (import "1:a/b" (func))) "is not in kebab case") +(assert_invalid + (component + (import "wasi:http/TyPeS" (func))) + "`TyPeS` is not in kebab case") +(assert_invalid + (component + (import "WaSi:http/types" (func))) + "`WaSi` is not in kebab case") +(assert_invalid + (component + (import "wasi:HtTp/types" (func))) + "`HtTp` is not in kebab case") +(assert_invalid + (component + (import "wasi/http" (func))) + "`wasi/http` is not in kebab case") +(assert_invalid + (component + (import "wasi:" (func))) + "`` is not in kebab case") +(assert_invalid + (component + (import "wasi:/" (func))) + "`` is not in kebab case") +(assert_invalid + (component + (import ":/" (func))) + "`` is not in kebab case") (assert_invalid (component (import "A:b/c" (func))) @@ -58,3 +93,58 @@ (component (import "ns:pkg-A/b" (func))) "is not a valid extern name") + +;; names are validated in non-import positions too +(assert_invalid + (component + (import "f" (func $f)) + (instance (export "1" (func $f)))) + "`1` is not in kebab case") +(assert_invalid + (component + (type (component (import "GonnA" (func))))) + "`GonnA` is not in kebab case") +(assert_invalid + (component + (type (component (export "NevEr" (func))))) + "`NevEr` is not in kebab case") +(assert_invalid + (component + (type (instance (export "lET" (func))))) + "`lET` is not in kebab case") +(assert_invalid + (component + (import "DOWn" (instance))) + "`DOWn` is not in kebab case") + +;; import/export names must be unique, compared case-insensitively +(assert_invalid + (component + (import "f" (func $f)) + (export "a" (func $f)) + (export "a" (func $f))) + "export name `a` conflicts with previous name `a`") +(assert_invalid + (component + (import "f" (func $f)) + (export "a" (func $f)) + (export "A" (func $f))) + "export name `A` conflicts with previous name `a`") +(assert_invalid + (component + (type (component + (import "A" (func)) + (import "a" (func))))) + "import name `a` conflicts with previous name `A`") +(assert_invalid + (component + (type (component + (export "a" (func)) + (export "A" (func))))) + "export name `A` conflicts with previous name `a`") +(assert_invalid + (component + (type (instance + (export "foo-BAR-baz" (func)) + (export "FOO-bar-BAZ" (func))))) + "export name `FOO-bar-BAZ` conflicts with previous name `foo-BAR-baz`") diff --git a/test/validation/outer-alias.wast b/test/validation/outer-alias.wast index f3a8e6b2..2fe3496c 100644 --- a/test/validation/outer-alias.wast +++ b/test/validation/outer-alias.wast @@ -1,5 +1,6 @@ ;; Validation of `outer` aliases: the allowed sorts, the cross-`component` -;; no-resource-types rule, de Bruijn counting, and `alias` declarator restrictions. +;; no-resource-types rule, de Bruijn counting, `alias` declarator restrictions, +;; and the implicit outer aliases injected by text-format name resolution. ;; aliasing from the current component (ct=0): @@ -74,6 +75,25 @@ ) "transitively refers to resources") +;; the rule applies to the aliased type as a whole: a component type that +;; transitively mentions a resource may not cross a `component` boundary either + +(assert_invalid + (component $C + (type $R (resource (rep i32))) + (type $U (component (export "a" (type (eq $R))))) + (component (alias outer $C $U (type $a))) + ) + "transitively refers to resources") + +(assert_invalid + (component $C + (type $R (resource (rep i32))) + (type $U (component (import "a" (type (eq $R))))) + (component (alias outer $C $U (type $a))) + ) + "transitively refers to resources") + ;; ct=0 (no boundary) (component definition $C (type $R (resource (rep i32))) @@ -214,6 +234,32 @@ ) "index out of bounds") +;; the same count/index bounds checks apply to every outer-aliasable sort + +(assert_invalid + (component (alias outer 1 0 (core type $a))) + "invalid outer alias count") + +(assert_invalid + (component (alias outer 0 0 (core type $a))) + "index out of bounds") + +(assert_invalid + (component (alias outer 1 0 (core module $a))) + "invalid outer alias count") + +(assert_invalid + (component (alias outer 0 0 (core module $a))) + "index out of bounds") + +(assert_invalid + (component (alias outer 1 0 (component $a))) + "invalid outer alias count") + +(assert_invalid + (component (alias outer 0 0 (component $a))) + "index out of bounds") + ;; core:alias (component definition $C @@ -228,3 +274,12 @@ (export "c" (func (type 0))) )) ) + +;; the text format resolves a name that fails to resolve locally via an +;; implicit `alias outer`, which only exists for the outer-aliasable sorts + +(assert_malformed + (component quote + "(import \"x\" (func $x))" + "(component (export \"x\" (func $x)))") + "outer item `x` is not a module, type, or component") diff --git a/test/validation/resources.wast b/test/validation/resources.wast index f685e6e7..9ecec3e1 100644 --- a/test/validation/resources.wast +++ b/test/validation/resources.wast @@ -1,4 +1,5 @@ -;; Tests for the resource-type parts of Explainer.md#type-checking. +;; Tests for the resource-type parts of Explainer.md#type-checking and +;; validation of Explainer.md#resource-built-ins. ;; `sub` bounds are fresh @@ -349,6 +350,68 @@ (with "T8" (type $R2)) (with "a" (type $Rec))))) +;; each instance-typed import generates fresh resources + +(component definition + (type $I (instance + (export "r" (type $r (sub resource))) + (export "f" (func (result (own $r)))))) + (import "i1" (instance $i1 (type $I))) + (import "i2" (instance $i2 (type $I))) + (component $C + (import "r" (type $r (sub resource))) + (import "f" (func (result (own $r))))) + (instance (instantiate $C + (with "r" (type $i1 "r")) + (with "f" (func $i1 "f")))) + (instance (instantiate $C + (with "r" (type $i2 "r")) + (with "f" (func $i2 "f"))))) + +(assert_invalid + (component + (type $I (instance + (export "r" (type $r (sub resource))) + (export "f" (func (result (own $r)))))) + (import "i1" (instance $i1 (type $I))) + (import "i2" (instance $i2 (type $I))) + (component $C + (import "r" (type $r (sub resource))) + (import "f" (func (result (own $r))))) + (instance (instantiate $C + (with "r" (type $i1 "r")) + (with "f" (func $i2 "f"))))) + "resource types are not the same") + +;; ...including instance-typed exports of a single imported instance +(assert_invalid + (component + (import "x" (instance $i + (type $I (instance + (export "r" (type (sub resource))))) + (export "a" (instance (type $I))) + (export "b" (instance (type $I))))) + (component $eq + (import "a" (type $a (sub resource))) + (import "b" (type (eq $a)))) + (instance (instantiate $eq + (with "a" (type $i "a" "r")) + (with "b" (type $i "b" "r"))))) + "resource types are not the same") + +;; within one component type, an instance-typed export's resource can be +;; aliased and eq-referenced by later exports +(component + (type $X (component + (type $T (instance + (export "r" (type (sub resource))))) + (export "t" (instance $t (type $T))) + (alias export $t "r" (type $r)) + (type $T2 (instance + (export "r2" (type (eq $r))) + (export "r" (type (sub resource))))) + (export "t2" (instance (type $T2)))))) + ;; resource type definitions are generative (assert_invalid @@ -462,6 +525,40 @@ "resource types are not the same") +;; per-instantiation generativity is also enforced through functions using the +;; resource, not just type imports + +(component + (component $C + (type $R (resource (rep i32))) + (export $R' "r" (type $R)) + (core func $drop (canon resource.drop $R)) + (func (export "f") (param "x" (own $R')) (canon lift (core func $drop)))) + (instance $c1 (instantiate $C)) + (component $D + (import "r" (type $R (sub resource))) + (import "f" (func (param "x" (own $R))))) + (instance (instantiate $D + (with "r" (type $c1 "r")) + (with "f" (func $c1 "f"))))) + +(assert_invalid + (component + (component $C + (type $R (resource (rep i32))) + (export $R' "r" (type $R)) + (core func $drop (canon resource.drop $R)) + (func (export "f") (param "x" (own $R')) (canon lift (core func $drop)))) + (instance $c1 (instantiate $C)) + (instance $c2 (instantiate $C)) + (component $D + (import "r" (type $R (sub resource))) + (import "f" (func (param "x" (own $R))))) + (instance (instantiate $D + (with "r" (type $c1 "r")) + (with "f" (func $c2 "f"))))) + "resource types are not the same") + ;; multiple exports of one resource with export ascription (component @@ -574,3 +671,176 @@ (import "x" (type (sub resource)))) (instance (instantiate $c))) "missing import named `x`") + +;; `own` and `borrow` require a resource type + +(assert_invalid + (component + (type $x (own 100))) + "type index out of bounds") + +(assert_invalid + (component + (type $x (borrow 100))) + "type index out of bounds") + +(assert_invalid + (component + (type $t u8) + (type $x (own $t))) + "not a resource type") + +(assert_invalid + (component + (type $t u8) + (type $x (borrow $t))) + "not a resource type") + +;; `borrow` cannot appear in function results + +(assert_invalid + (component + (type $R (resource (rep i32))) + (type $F (func (result (borrow $R))))) + "function result cannot contain a `borrow` type") + +(assert_invalid + (component + (type $R (resource (rep i32))) + (type $F (func (result (list (borrow $R)))))) + "function result cannot contain a `borrow` type") + +(assert_invalid + (component + (type $R (resource (rep i32))) + (type $F (func (result (option (borrow $R)))))) + "function result cannot contain a `borrow` type") + +(assert_invalid + (component + (type $R (resource (rep i32))) + (type $Rec (record (field "f" (borrow $R)))) + (type $F (func (result (option (list $Rec)))))) + "function result cannot contain a `borrow` type") + +;; resources can only be defined in concrete components, not in component or +;; instance types + +(assert_invalid + (component + (type $C (component + (type $R (resource (rep i32)))))) + "resources can only be defined within a concrete component") + +(assert_invalid + (component + (type $I (instance + (type $R (resource (rep i32)))))) + "resources can only be defined within a concrete component") + +;; destructors must be core functions of type [i32] -> [] + +(component + (core module $M + (func (export "dtor") (param i32))) + (core instance $m (instantiate $M)) + (type $R (resource (rep i32) (dtor (core func $m "dtor")))) + (core func (canon resource.new $R))) + +(assert_invalid + (component + (core module $M + (func (export "dtor"))) + (core instance $m (instantiate $M)) + (type $R (resource (rep i32) (dtor (core func $m "dtor"))))) + "wrong signature for a destructor") + +(assert_invalid + (component + (type $R (resource (rep i32) (dtor (core func 100))))) + "function index out of bounds") + +;; canon resource built-ins require a resource type + +(assert_invalid + (component + (type $T (tuple u32)) + (core func (canon resource.drop $T))) + "not a resource type") + +(assert_invalid + (component + (type $C (component)) + (core func (canon resource.new $C))) + "not a resource type") + +(assert_invalid + (component + (type $C (component)) + (core func (canon resource.drop $C))) + "not a resource type") + +(assert_invalid + (component + (core func (canon resource.drop 100))) + "type index out of bounds") + +;; canon resource.new/resource.rep additionally require a *local* resource type + +(assert_invalid + (component + (import "T" (type $T (sub resource))) + (core func (canon resource.new $T))) + "not a local resource") + +(assert_invalid + (component + (import "T" (type $T (sub resource))) + (core func (canon resource.rep $T))) + "not a local resource") + +;; a resource aliased from a child instance's export is not local... +(assert_invalid + (component + (component $C + (type $R (resource (rep i32))) + (export "r" (type $R))) + (instance $c (instantiate $C)) + (alias export $c "r" (type $R)) + (core func (canon resource.rep $R))) + "not a local resource") + +;; ...though it can still be dropped +(component + (component $C + (type $R (resource (rep i32))) + (export "r" (type $R))) + (instance $c (instantiate $C)) + (alias export $c "r" (type $R)) + (core func (canon resource.drop $R))) + +;; ...and it stays local if the child's export is this component's own resource +;; threaded back through `with` +(component + (type $R (resource (rep i32))) + (component $C + (import "x" (type $x (sub resource))) + (export "y" (type $x))) + (instance $c (instantiate $C (with "x" (type $R)))) + (alias export $c "y" (type $R2)) + (core func (canon resource.rep $R2))) + +;; component-typed imports can use abstract resources in their imports and +;; exports + +(component + (component $C1 + (import "X" (type $X (sub resource))) + (import "f" (func $f (result (own $X)))) + (export "g" (func $f))) + (component $C2 + (import "C1" (component + (import "X" (type $X (sub resource))) + (import "f" (func (result (own $X)))) + (export "g" (func (result (own $X))))))) + (instance $c (instantiate $C2 (with "C1" (component $C1))))) diff --git a/test/values/alignment.wast b/test/values/alignment.wast new file mode 100644 index 00000000..1dfe102a --- /dev/null +++ b/test/values/alignment.wast @@ -0,0 +1,207 @@ +;; Pointer alignment and bounds checks in the canonical ABI at a +;; cross-component boundary. + +;; callee returns a misaligned retptr for a spilled (>1 flat) result +(component definition $CalleeRetptr + (component $C + (core module $M + (memory (export "mem") 1) + (func (export "f") (result i32) (i32.const 1))) + (core instance $m (instantiate $M)) + (func (export "f") (result (tuple u32 u32)) + (canon lift (core func $m "f") (memory (core memory $m "mem"))))) + (component $D + (import "f" (func $f (result (tuple u32 u32)))) + (core module $Libc (memory (export "mem") 1)) + (core instance $libc (instantiate $Libc)) + (core func $f' (canon lower (func $f) (memory (core memory $libc "mem")))) + (core module $Main + (import "" "f" (func $f (param i32))) + (func (export "run") (call $f (i32.const 8)))) + (core instance $main (instantiate $Main (with "" (instance (export "f" (func $f')))))) + (func (export "run") (canon lift (core func $main "run")))) + (instance $c (instantiate $C)) + (instance $d (instantiate $D (with "f" (func $c "f")))) + (func (export "run") (alias export $d "run"))) +(component instance $i $CalleeRetptr) +(assert_trap (invoke "run") "unaligned pointer") + +;; caller passes a misaligned retptr to the lowered import +(component definition $CallerRetptr + (component $C + (core module $M + (memory (export "mem") 1) + (func (export "f") (result i32) (i32.const 0))) + (core instance $m (instantiate $M)) + (func (export "f") (result (tuple u32 u32)) + (canon lift (core func $m "f") (memory (core memory $m "mem"))))) + (component $D + (import "f" (func $f (result (tuple u32 u32)))) + (core module $Libc (memory (export "mem") 1)) + (core instance $libc (instantiate $Libc)) + (core func $f' (canon lower (func $f) (memory (core memory $libc "mem")))) + (core module $Main + (import "" "f" (func $f (param i32))) + (func (export "run") (call $f (i32.const 1)))) + (core instance $main (instantiate $Main (with "" (instance (export "f" (func $f')))))) + (func (export "run") (canon lift (core func $main "run")))) + (instance $c (instantiate $C)) + (instance $d (instantiate $D (with "f" (func $c "f")))) + (func (export "run") (alias export $d "run"))) +(component instance $i $CallerRetptr) +(assert_trap (invoke "run") "unaligned pointer") + +;; >16 flat params spill through the callee's realloc, which returns a +;; misaligned pointer +(component definition $CalleeArgptr + (component $C + (type $big (tuple u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32)) + (core module $M + (memory (export "mem") 1) + (func (export "f") (param i32)) + (func (export "realloc") (param i32 i32 i32 i32) (result i32) (i32.const 1))) + (core instance $m (instantiate $M)) + (func (export "f") (param "a" $big) + (canon lift (core func $m "f") + (memory (core memory $m "mem")) (realloc (core func $m "realloc"))))) + (component $D + (type $big (tuple u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32)) + (import "f" (func $f (param "a" $big))) + (core module $Libc (memory (export "mem") 1)) + (core instance $libc (instantiate $Libc)) + (core func $f' (canon lower (func $f) (memory (core memory $libc "mem")))) + (core module $Main + (import "" "f" (func $f (param i32))) + (func (export "run") (call $f (i32.const 8)))) + (core instance $main (instantiate $Main (with "" (instance (export "f" (func $f')))))) + (func (export "run") (canon lift (core func $main "run")))) + (instance $c (instantiate $C)) + (instance $d (instantiate $D (with "f" (func $c "f")))) + (func (export "run") (alias export $d "run"))) +(component instance $i $CalleeArgptr) +(assert_trap (invoke "run") "unaligned pointer") + +;; caller passes a misaligned argptr for the spilled params +(component definition $CallerArgptr + (component $C + (type $big (tuple u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32)) + (core module $M + (memory (export "mem") 1) + (func (export "f") (param i32)) + (func (export "realloc") (param i32 i32 i32 i32) (result i32) (i32.const 8))) + (core instance $m (instantiate $M)) + (func (export "f") (param "a" $big) + (canon lift (core func $m "f") + (memory (core memory $m "mem")) (realloc (core func $m "realloc"))))) + (component $D + (type $big (tuple u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32)) + (import "f" (func $f (param "a" $big))) + (core module $Libc (memory (export "mem") 1)) + (core instance $libc (instantiate $Libc)) + (core func $f' (canon lower (func $f) (memory (core memory $libc "mem")))) + (core module $Main + (import "" "f" (func $f (param i32))) + (func (export "run") (call $f (i32.const 1)))) + (core instance $main (instantiate $Main (with "" (instance (export "f" (func $f')))))) + (func (export "run") (canon lift (core func $main "run")))) + (instance $c (instantiate $C)) + (instance $d (instantiate $D (with "f" (func $c "f")))) + (func (export "run") (alias export $d "run"))) +(component instance $i $CallerArgptr) +(assert_trap (invoke "run") "unaligned pointer") + +;; a utf16 caller-side string pointer must be 2-aligned, even when len=0 +(component definition $Utf16Src + (component $C + (core module $M + (memory (export "mem") 1) + (func (export "f") (param i32 i32)) + (func (export "realloc") (param i32 i32 i32 i32) (result i32) (i32.const 8))) + (core instance $m (instantiate $M)) + (func (export "f") (param "s" string) + (canon lift (core func $m "f") string-encoding=utf8 + (memory (core memory $m "mem")) (realloc (core func $m "realloc"))))) + (component $D + (import "f" (func $f (param "s" string))) + (core module $Libc (memory (export "mem") 1)) + (core instance $libc (instantiate $Libc)) + (core func $f' (canon lower (func $f) string-encoding=utf16 + (memory (core memory $libc "mem")))) + (core module $Main + (import "" "f" (func $f (param i32 i32))) + (func (export "run") (call $f (i32.const 1) (i32.const 0)))) + (core instance $main (instantiate $Main (with "" (instance (export "f" (func $f')))))) + (func (export "run") (canon lift (core func $main "run")))) + (instance $c (instantiate $C)) + (instance $d (instantiate $D (with "f" (func $c "f")))) + (func (export "run") (alias export $d "run"))) +(component instance $i $Utf16Src) +(assert_trap (invoke "run") "unaligned pointer") + +;; a latin1+utf16 caller-side string pointer must be 2-aligned for both +;; dynamic representations: untagged (latin1) and tagged (utf16) lengths +(component definition $Latin1Utf16Src + (component $C + (core module $M + (memory (export "mem") 1) + (func (export "f") (param i32 i32)) + (func (export "realloc") (param i32 i32 i32 i32) (result i32) (i32.const 8))) + (core instance $m (instantiate $M)) + (func (export "f") (param "s" string) + (canon lift (core func $m "f") string-encoding=utf8 + (memory (core memory $m "mem")) (realloc (core func $m "realloc"))))) + (component $D + (import "f" (func $f (param "s" string))) + (core module $Libc (memory (export "mem") 1)) + (core instance $libc (instantiate $Libc)) + (core func $f' (canon lower (func $f) string-encoding=latin1+utf16 + (memory (core memory $libc "mem")))) + (core module $Main + (import "" "f" (func $f (param i32 i32))) + (func (export "run-latin1") (call $f (i32.const 1) (i32.const 0))) + (func (export "run-utf16") (call $f (i32.const 1) (i32.const 0x80000000)))) + (core instance $main (instantiate $Main (with "" (instance (export "f" (func $f')))))) + (func (export "run-latin1") (canon lift (core func $main "run-latin1"))) + (func (export "run-utf16") (canon lift (core func $main "run-utf16")))) + (instance $c (instantiate $C)) + (instance $d (instantiate $D (with "f" (func $c "f")))) + (func (export "run-latin1") (alias export $d "run-latin1")) + (func (export "run-utf16") (alias export $d "run-utf16"))) +(component instance $i $Latin1Utf16Src) +(assert_trap (invoke "run-latin1") "unaligned pointer") +(component instance $i $Latin1Utf16Src) +(assert_trap (invoke "run-utf16") "unaligned pointer") + +;; caller-side string ptr/len out of bounds of the caller's own memory, both +;; with the pointer itself out of bounds and with only ptr+len out of bounds +(component definition $StringOOB + (component $C + (core module $M + (memory (export "mem") 1) + (func (export "f") (param i32 i32)) + (func (export "realloc") (param i32 i32 i32 i32) (result i32) (i32.const 8))) + (core instance $m (instantiate $M)) + (func (export "f") (param "s" string) + (canon lift (core func $m "f") string-encoding=utf8 + (memory (core memory $m "mem")) (realloc (core func $m "realloc"))))) + (component $D + (import "f" (func $f (param "s" string))) + (core module $Libc (memory (export "mem") 1)) + (core instance $libc (instantiate $Libc)) + (core func $f' (canon lower (func $f) string-encoding=utf8 + (memory (core memory $libc "mem")))) + (core module $Main + (import "" "f" (func $f (param i32 i32))) + (func (export "run-ptr-oob") (call $f (i32.const 0x80000000) (i32.const 1))) + (func (export "run-len-oob") (call $f (i32.const 65535) (i32.const 2)))) + (core instance $main (instantiate $Main (with "" (instance (export "f" (func $f')))))) + (func (export "run-ptr-oob") (canon lift (core func $main "run-ptr-oob"))) + (func (export "run-len-oob") (canon lift (core func $main "run-len-oob")))) + (instance $c (instantiate $C)) + (instance $d (instantiate $D (with "f" (func $c "f")))) + (func (export "run-ptr-oob") (alias export $d "run-ptr-oob")) + (func (export "run-len-oob") (alias export $d "run-len-oob"))) +(component instance $i $StringOOB) +(assert_trap (invoke "run-ptr-oob") "string content out-of-bounds") +(component instance $i $StringOOB) +(assert_trap (invoke "run-len-oob") "string content out-of-bounds") diff --git a/test/values/numerics.wast b/test/values/numerics.wast new file mode 100644 index 00000000..99fcbc03 --- /dev/null +++ b/test/values/numerics.wast @@ -0,0 +1,313 @@ +;; Scalar-value canonicalization semantics of the canonical ABI: small-int +;; truncation, bool normalization, char validation, and flags masking. + +;; Out-of-range core i32s passed as u8/s8/u16/s16 params are truncated to the +;; type's width (and sign-extended for signed types) before reaching the callee. +(component + (component $C + (core module $M + (func (export "expect-zero") (param i32) + (if (i32.ne (local.get 0) (i32.const 0)) (then unreachable))) + (func (export "expect-neg1") (param i32) + (if (i32.ne (local.get 0) (i32.const -1)) (then unreachable))) + ) + (core instance $m (instantiate $M)) + (func (export "u8") (param "x" u8) (canon lift (core func $m "expect-zero"))) + (func (export "u16") (param "x" u16) (canon lift (core func $m "expect-zero"))) + (func (export "s8") (param "x" s8) (canon lift (core func $m "expect-neg1"))) + (func (export "s16") (param "x" s16) (canon lift (core func $m "expect-neg1"))) + ) + (component $D + (import "u8" (func $u8 (param "x" u8))) + (import "s8" (func $s8 (param "x" s8))) + (import "u16" (func $u16 (param "x" u16))) + (import "s16" (func $s16 (param "x" s16))) + (core func $u8' (canon lower (func $u8))) + (core func $s8' (canon lower (func $s8))) + (core func $u16' (canon lower (func $u16))) + (core func $s16' (canon lower (func $s16))) + (core module $M + (import "" "u8" (func $u8 (param i32))) + (import "" "s8" (func $s8 (param i32))) + (import "" "u16" (func $u16 (param i32))) + (import "" "s16" (func $s16 (param i32))) + (func (export "run") (result i32) + (call $u8 (i32.const 0)) + (call $u8 (i32.const 0xff00)) ;; low byte is 0 + (call $s8 (i32.const -1)) + (call $s8 (i32.const 0xff)) ;; low byte sign-extends to -1 + (call $s8 (i32.const 0xffff)) + (call $u16 (i32.const 0)) + (call $u16 (i32.const 0xff0000)) + (call $s16 (i32.const -1)) + (call $s16 (i32.const 0xffff)) + (call $s16 (i32.const 0xffffff)) + (i32.const 42) + ) + ) + (core instance $m (instantiate $M (with "" (instance + (export "u8" (func $u8')) + (export "s8" (func $s8')) + (export "u16" (func $u16')) + (export "s16" (func $s16')) + )))) + (func (export "run") (result u32) (canon lift (core func $m "run"))) + ) + (instance $c (instantiate $C)) + (instance $d (instantiate $D + (with "u8" (func $c "u8")) + (with "s8" (func $c "s8")) + (with "u16" (func $c "u16")) + (with "s16" (func $c "s16")) + )) + (func (export "run") (alias export $d "run")) +) +(assert_return (invoke "run") (u32.const 42)) + +;; An out-of-range core result is truncated when lifted to a narrower type at +;; the host boundary. +(component + (core module $M (func (export "id") (param i32) (result i32) (local.get 0))) + (core instance $m (instantiate $M)) + (func (export "i-to-b") (param "x" u32) (result bool) (canon lift (core func $m "id"))) + (func (export "i-to-u8") (param "x" u32) (result u8) (canon lift (core func $m "id"))) + (func (export "i-to-s8") (param "x" u32) (result s8) (canon lift (core func $m "id"))) + (func (export "i-to-u16") (param "x" u32) (result u16) (canon lift (core func $m "id"))) + (func (export "i-to-s16") (param "x" u32) (result s16) (canon lift (core func $m "id"))) +) +(assert_return (invoke "i-to-b" (u32.const 0)) (bool.const false)) +(assert_return (invoke "i-to-b" (u32.const 2)) (bool.const true)) +(assert_return (invoke "i-to-u8" (u32.const 0xf01)) (u8.const 1)) +(assert_return (invoke "i-to-s8" (u32.const 0xffffffff)) (s8.const -1)) +(assert_return (invoke "i-to-u16" (u32.const 0xffffffff)) (u16.const 0xffff)) +(assert_return (invoke "i-to-s16" (u32.const 0xffffffff)) (s16.const -1)) + +;; Any nonzero core i32 passed as a bool param reaches the callee as exactly 1; +;; 0 stays 0. +(component + (component $C + (core module $M + (func (export "expect-one") (param i32) + (if (i32.ne (local.get 0) (i32.const 1)) (then unreachable))) + (func (export "expect-zero") (param i32) + (if (i32.ne (local.get 0) (i32.const 0)) (then unreachable))) + ) + (core instance $m (instantiate $M)) + (func (export "assert-true") (param "x" bool) (canon lift (core func $m "expect-one"))) + (func (export "assert-false") (param "x" bool) (canon lift (core func $m "expect-zero"))) + ) + (component $D + (import "assert-true" (func $assert-true (param "x" bool))) + (import "assert-false" (func $assert-false (param "x" bool))) + (core func $assert-true' (canon lower (func $assert-true))) + (core func $assert-false' (canon lower (func $assert-false))) + (core module $M + (import "" "assert-true" (func $assert-true (param i32))) + (import "" "assert-false" (func $assert-false (param i32))) + (func (export "run") (result i32) + (call $assert-true (i32.const 1)) + (call $assert-true (i32.const 2)) + (call $assert-true (i32.const -1)) + (call $assert-false (i32.const 0)) + (i32.const 43) + ) + ) + (core instance $m (instantiate $M (with "" (instance + (export "assert-true" (func $assert-true')) + (export "assert-false" (func $assert-false')) + )))) + (func (export "run") (result u32) (canon lift (core func $m "run"))) + ) + (instance $c (instantiate $C)) + (instance $d (instantiate $D + (with "assert-true" (func $c "assert-true")) + (with "assert-false" (func $c "assert-false")) + )) + (func (export "run") (alias export $d "run")) +) +(assert_return (invoke "run") (u32.const 43)) + +;; Valid chars round-trip across components and the host boundary, including +;; the surrogate-range boundaries 0xd7ff/0xe000 and the max scalar 0x10ffff. +(component + (component $C + (core module $M (func (export "id") (param i32) (result i32) (local.get 0))) + (core instance $m (instantiate $M)) + (func (export "id") (param "x" char) (result char) (canon lift (core func $m "id"))) + ) + (component $D + (import "id" (func $id (param "x" char) (result char))) + (core func $id' (canon lower (func $id))) + (core module $M + (import "" "id" (func $id (param i32) (result i32))) + (func $check (param i32) + (if (i32.ne (call $id (local.get 0)) (local.get 0)) (then unreachable))) + (func (export "run") (result i32) + (call $check (i32.const 0)) + (call $check (i32.const 0xd7ff)) + (call $check (i32.const 0xe000)) + (call $check (i32.const 0x10ffff)) + (i32.const 44) + ) + ) + (core instance $m (instantiate $M (with "" (instance (export "id" (func $id')))))) + (func (export "run") (result u32) (canon lift (core func $m "run"))) + ) + (instance $c (instantiate $C)) + (instance $d (instantiate $D (with "id" (func $c "id")))) + (func (export "run") (alias export $d "run")) + (func (export "roundtrip") (alias export $c "id")) +) +(assert_return (invoke "run") (u32.const 44)) +(assert_return (invoke "roundtrip" (char.const "⛳")) (char.const "⛳")) +(assert_return (invoke "roundtrip" (char.const "🍰")) (char.const "🍰")) + +;; Surrogates and values above 0x10ffff are invalid char bit patterns and trap +;; when passed from core code. +(component definition $CharTraps + (component $C + (core module $M (func (export "take") (param i32))) + (core instance $m (instantiate $M)) + (func (export "take") (param "x" char) (canon lift (core func $m "take"))) + ) + (component $D + (import "take" (func $take (param "x" char))) + (core func $take' (canon lower (func $take))) + (core module $M + (import "" "take" (func $take (param i32))) + (func (export "run-d800") (call $take (i32.const 0xd800))) + (func (export "run-dfff") (call $take (i32.const 0xdfff))) + (func (export "run-too-big") (call $take (i32.const 0x110000))) + ) + (core instance $m (instantiate $M (with "" (instance (export "take" (func $take')))))) + (func (export "run-d800") (canon lift (core func $m "run-d800"))) + (func (export "run-dfff") (canon lift (core func $m "run-dfff"))) + (func (export "run-too-big") (canon lift (core func $m "run-too-big"))) + ) + (instance $c (instantiate $C)) + (instance $d (instantiate $D (with "take" (func $c "take")))) + (func (export "run-d800") (alias export $d "run-d800")) + (func (export "run-dfff") (alias export $d "run-dfff")) + (func (export "run-too-big") (alias export $d "run-too-big")) +) +(component instance $ct $CharTraps) +(assert_trap (invoke "run-d800") "invalid `char` bit pattern") +(component instance $ct $CharTraps) +(assert_trap (invoke "run-dfff") "invalid `char` bit pattern") +(component instance $ct $CharTraps) +(assert_trap (invoke "run-too-big") "invalid `char` bit pattern") + +;; Undefined upper flag bits are masked off crossing components; a 32-flag type +;; has no undefined bits so all pass through. +(component + (type $f1' (flags "f1")) + (type $f8' (flags "f1" "f2" "f3" "f4" "f5" "f6" "f7" "f8")) + (type $f9' (flags "f1" "f2" "f3" "f4" "f5" "f6" "f7" "f8" "f9")) + (type $f16' (flags + "f1" "f2" "f3" "f4" "f5" "f6" "f7" "f8" + "g1" "g2" "g3" "g4" "g5" "g6" "g7" "g8" + )) + (type $f17' (flags + "f1" "f2" "f3" "f4" "f5" "f6" "f7" "f8" + "g1" "g2" "g3" "g4" "g5" "g6" "g7" "g8" + "g9" + )) + (type $f32' (flags + "f1" "f2" "f3" "f4" "f5" "f6" "f7" "f8" + "g1" "g2" "g3" "g4" "g5" "g6" "g7" "g8" + "h1" "h2" "h3" "h4" "h5" "h6" "h7" "h8" + "i1" "i2" "i3" "i4" "i5" "i6" "i7" "i8" + )) + (component $C + (export $f1 "t-f1" (type $f1')) + (export $f8 "t-f8" (type $f8')) + (export $f9 "t-f9" (type $f9')) + (export $f16 "t-f16" (type $f16')) + (export $f17 "t-f17" (type $f17')) + (export $f32 "t-f32" (type $f32')) + (core module $M + (func (export "f1") (param i32) + (if (i32.ne (local.get 0) (i32.const 0x1)) (then unreachable))) + (func (export "f8") (param i32) + (if (i32.ne (local.get 0) (i32.const 0x11)) (then unreachable))) + (func (export "f9") (param i32) + (if (i32.ne (local.get 0) (i32.const 0x111)) (then unreachable))) + (func (export "f16") (param i32) + (if (i32.ne (local.get 0) (i32.const 0x1111)) (then unreachable))) + (func (export "f17") (param i32) + (if (i32.ne (local.get 0) (i32.const 0x11111)) (then unreachable))) + (func (export "f32") (param i32) + (if (i32.ne (local.get 0) (i32.const 0xffffffff)) (then unreachable))) + ) + (core instance $m (instantiate $M)) + (func (export "f1") (param "x" $f1) (canon lift (core func $m "f1"))) + (func (export "f8") (param "x" $f8) (canon lift (core func $m "f8"))) + (func (export "f9") (param "x" $f9) (canon lift (core func $m "f9"))) + (func (export "f16") (param "x" $f16) (canon lift (core func $m "f16"))) + (func (export "f17") (param "x" $f17) (canon lift (core func $m "f17"))) + (func (export "f32") (param "x" $f32) (canon lift (core func $m "f32"))) + ) + (component $D + (import "c" (instance $i + (export "t-f1" (type $f1 (eq $f1'))) + (export "t-f8" (type $f8 (eq $f8'))) + (export "t-f9" (type $f9 (eq $f9'))) + (export "t-f16" (type $f16 (eq $f16'))) + (export "t-f17" (type $f17 (eq $f17'))) + (export "t-f32" (type $f32 (eq $f32'))) + (export "f1" (func (param "x" $f1))) + (export "f8" (func (param "x" $f8))) + (export "f9" (func (param "x" $f9))) + (export "f16" (func (param "x" $f16))) + (export "f17" (func (param "x" $f17))) + (export "f32" (func (param "x" $f32))) + )) + (core func $f1' (canon lower (func $i "f1"))) + (core func $f8' (canon lower (func $i "f8"))) + (core func $f9' (canon lower (func $i "f9"))) + (core func $f16' (canon lower (func $i "f16"))) + (core func $f17' (canon lower (func $i "f17"))) + (core func $f32' (canon lower (func $i "f32"))) + (core module $M + (import "" "f1" (func $f1 (param i32))) + (import "" "f8" (func $f8 (param i32))) + (import "" "f9" (func $f9 (param i32))) + (import "" "f16" (func $f16 (param i32))) + (import "" "f17" (func $f17 (param i32))) + (import "" "f32" (func $f32 (param i32))) + (func (export "run") (result i32) + (call $f1 (i32.const 0xffffff01)) + (call $f8 (i32.const 0xffffff11)) + (call $f9 (i32.const 0xffffff11)) + (call $f16 (i32.const 0xffff1111)) + (call $f17 (i32.const 0xffff1111)) + (call $f32 (i32.const 0xffffffff)) + (i32.const 45) + ) + ) + (core instance $m (instantiate $M (with "" (instance + (export "f1" (func $f1')) + (export "f8" (func $f8')) + (export "f9" (func $f9')) + (export "f16" (func $f16')) + (export "f17" (func $f17')) + (export "f32" (func $f32')) + )))) + (func (export "run") (result u32) (canon lift (core func $m "run"))) + ) + (instance $c (instantiate $C)) + (instance $d (instantiate $D (with "c" (instance $c)))) + (func (export "run") (alias export $d "run")) +) +(assert_return (invoke "run") (u32.const 45)) + +;; Undefined upper bits in a core flags result are also dropped when lifted to +;; the host. +(component + (type $f9 (flags "f1" "f2" "f3" "f4" "f5" "f6" "f7" "f8" "f9")) + (export $f9' "f9" (type $f9)) + (core module $M (func (export "junk") (result i32) (i32.const 0xffffff11))) + (core instance $m (instantiate $M)) + (func (export "junk-to-f9") (result $f9') (canon lift (core func $m "junk"))) +) +(assert_return (invoke "junk-to-f9") (flags.const "f1" "f5" "f9")) diff --git a/test/values/post-return.wast b/test/values/post-return.wast index b5f2ca9d..936dd457 100644 --- a/test/values/post-return.wast +++ b/test/values/post-return.wast @@ -356,3 +356,61 @@ )) ) (assert_return (invoke "f") (u32.const 11)) + + +;; on a cross-component call, post-return runs exactly once, before control +;; returns to the caller, and receives the function's flat results as arguments: +(component + (component $C + (core module $CM + (global $post-called (mut i32) (i32.const 0)) + (func (export "foo") (result i32) + (if (i32.ne (global.get $post-called) (i32.const 0)) (then unreachable)) + (i32.const 100) + ) + (func (export "foo-post") (param i32) + (if (i32.ne (local.get 0) (i32.const 100)) (then unreachable)) + (if (i32.ne (global.get $post-called) (i32.const 0)) (then unreachable)) + (global.set $post-called (i32.const 1)) + ) + (func (export "assert-post") (result i32) + (global.get $post-called) + ) + ) + (core instance $cm (instantiate $CM)) + (func (export "foo") (result u32) (canon lift + (core func $cm "foo") + (post-return (core func $cm "foo-post")) + )) + (func (export "assert-post") (result u32) (canon lift + (core func $cm "assert-post") + )) + ) + (component $D + (import "foo" (func $foo (result u32))) + (import "assert-post" (func $assert-post (result u32))) + (canon lower (func $foo) (core func $foo')) + (canon lower (func $assert-post) (core func $assert-post')) + (core module $DM + (import "" "foo" (func $foo (result i32))) + (import "" "assert-post" (func $assert-post (result i32))) + (func (export "run") (result i32) + (if (i32.ne (call $foo) (i32.const 100)) (then unreachable)) + (if (i32.ne (call $assert-post) (i32.const 1)) (then unreachable)) + (i32.const 42) + ) + ) + (core instance $dm (instantiate $DM (with "" (instance + (export "foo" (func $foo')) + (export "assert-post" (func $assert-post')) + )))) + (func (export "run") (result u32) (canon lift (core func $dm "run"))) + ) + (instance $c (instantiate $C)) + (instance $d (instantiate $D + (with "foo" (func $c "foo")) + (with "assert-post" (func $c "assert-post")) + )) + (func (export "run") (alias export $d "run")) +) +(assert_return (invoke "run") (u32.const 42)) diff --git a/test/values/realloc.wast b/test/values/realloc.wast new file mode 100644 index 00000000..7706e03b --- /dev/null +++ b/test/values/realloc.wast @@ -0,0 +1,124 @@ +;; Invocation and failure semantics of the `realloc` canonopt: lowering a list +;; always calls realloc, even for zero-size allocations, and the returned +;; pointer is alignment- and bounds-checked. + +;; lowering an empty list across components still calls realloc with (0, 0, align, 0) +(component + (component $C + (core module $CM + (memory (export "mem") 1) + (global $calls (mut i32) (i32.const 0)) + (func (export "realloc") (param $old i32) (param $old-size i32) (param $align i32) (param $new-size i32) (result i32) + (if (i32.or + (i32.or (local.get $old) (local.get $old-size)) + (i32.or (i32.ne (local.get $align) (i32.const 1)) (local.get $new-size))) + (then unreachable)) + (global.set $calls (i32.add (global.get $calls) (i32.const 1))) + (i32.const 16)) + (func (export "f") (param $ptr i32) (param $len i32) (result i32) + (if (i32.ne (local.get $ptr) (i32.const 16)) (then unreachable)) + (if (local.get $len) (then unreachable)) + (i32.mul (global.get $calls) (i32.const 42)))) + (core instance $cm (instantiate $CM)) + (func (export "f") (param "a" (list u8)) (result u32) + (canon lift (core func $cm "f") (memory (core memory $cm "mem")) (realloc (core func $cm "realloc"))))) + (component $D + (import "f" (func $f (param "a" (list u8)) (result u32))) + (core module $Memory (memory (export "mem") 1)) + (core instance $memory (instantiate $Memory)) + (core func $f' (canon lower (func $f) (memory (core memory $memory "mem")))) + (core module $DM + (import "" "f" (func $f' (param i32 i32) (result i32))) + (func (export "run") (result i32) + (call $f' (i32.const 0) (i32.const 0)))) + (core instance $dm (instantiate $DM (with "" (instance (export "f" (func $f')))))) + (func (export "run") (result u32) (canon lift (core func $dm "run")))) + (instance $c (instantiate $C)) + (instance $d (instantiate $D (with "f" (func $c "f")))) + (func (export "run") (alias export $d "run")) +) +(assert_return (invoke "run") (u32.const 42)) + +;; realloc returning an out-of-bounds pointer traps, even for a zero-size allocation +(component definition $OobRealloc + (component $C + (core module $CM + (memory (export "mem") 1) + (func (export "realloc") (param i32 i32 i32 i32) (result i32) (i32.const -1)) + (func (export "f") (param i32 i32))) + (core instance $cm (instantiate $CM)) + (func (export "f") (param "a" (list u8)) + (canon lift (core func $cm "f") (memory (core memory $cm "mem")) (realloc (core func $cm "realloc"))))) + (component $D + (import "f" (func $f (param "a" (list u8)))) + (core module $Memory (memory (export "mem") 1)) + (core instance $memory (instantiate $Memory)) + (core func $f' (canon lower (func $f) (memory (core memory $memory "mem")))) + (core module $DM + (import "" "f" (func $f' (param i32 i32))) + (func (export "run") (call $f' (i32.const 0) (i32.const 0)))) + (core instance $dm (instantiate $DM (with "" (instance (export "f" (func $f')))))) + (func (export "run") (canon lift (core func $dm "run")))) + (instance $c (instantiate $C)) + (instance $d (instantiate $D (with "f" (func $c "f")))) + (func (export "run") (alias export $d "run")) +) +(component instance $i $OobRealloc) +(assert_trap (invoke "run") "wasm trap: list content out-of-bounds") + +;; realloc returning a misaligned pointer for a (list u32) lowering traps +(component definition $MisalignedRealloc + (component $C + (core module $CM + (memory (export "mem") 1) + (func (export "realloc") (param i32 i32 i32 i32) (result i32) (i32.const 2)) + (func (export "f") (param i32 i32))) + (core instance $cm (instantiate $CM)) + (func (export "f") (param "a" (list u32)) + (canon lift (core func $cm "f") (memory (core memory $cm "mem")) (realloc (core func $cm "realloc"))))) + (component $D + (import "f" (func $f (param "a" (list u32)))) + (core module $Memory (memory (export "mem") 1)) + (core instance $memory (instantiate $Memory)) + (core func $f' (canon lower (func $f) (memory (core memory $memory "mem")))) + (core module $DM + (import "" "f" (func $f' (param i32 i32))) + (func (export "run") (call $f' (i32.const 8) (i32.const 1)))) + (core instance $dm (instantiate $DM (with "" (instance (export "f" (func $f')))))) + (func (export "run") (canon lift (core func $dm "run")))) + (instance $c (instantiate $C)) + (instance $d (instantiate $D (with "f" (func $c "f")))) + (func (export "run") (alias export $d "run")) +) +(component instance $i $MisalignedRealloc) +(assert_trap (invoke "run") "wasm trap: unaligned pointer") + +;; realloc failure lowering a (list u32) argument of a directly-invoked export; +;; the returned pointer is bounds-checked even for a zero-size allocation +(component definition $HostOobRealloc + (core module $M + (memory (export "mem") 1) + (func (export "realloc") (param i32 i32 i32 i32) (result i32) + (i32.const -4)) ;; 4-aligned, so the bounds check is what trips + (func (export "f") (param i32 i32))) + (core instance $m (instantiate $M)) + (func (export "f") (param "a" (list u32)) + (canon lift (core func $m "f") (memory (core memory $m "mem")) (realloc (core func $m "realloc")))) +) +(component instance $i $HostOobRealloc) +(assert_trap (invoke "f" (list.const (u32.const 1) (u32.const 2))) "realloc return: beyond end of memory") +(component instance $i $HostOobRealloc) +(assert_trap (invoke "f" (list.const)) "realloc return: beyond end of memory") + +;; realloc returning -1 for a (list u32) fails the alignment check before the bounds check +(component definition $HostMisalignedRealloc + (core module $M + (memory (export "mem") 1) + (func (export "realloc") (param i32 i32 i32 i32) (result i32) (i32.const -1)) + (func (export "f") (param i32 i32))) + (core instance $m (instantiate $M)) + (func (export "f") (param "a" (list u32)) + (canon lift (core func $m "f") (memory (core memory $m "mem")) (realloc (core func $m "realloc")))) +) +(component instance $i $HostMisalignedRealloc) +(assert_trap (invoke "f" (list.const (u32.const 1) (u32.const 2))) "realloc return: result not aligned") diff --git a/test/values/strings.wast b/test/values/strings.wast index 034d4908..e96f54e9 100644 --- a/test/values/strings.wast +++ b/test/values/strings.wast @@ -15,7 +15,6 @@ (i32.store16 (i32.const 20) (i32.const 0x84_83)) (i32.const 0) ) - ;; TODO: so many cases left to test, everyone feel free to fill in... ) (core instance $m (instantiate $M)) (func (export "f1") (result string) (canon lift (core func $m "f1") (memory (core memory $m "mem")))) diff --git a/test/values/transcode.wast b/test/values/transcode.wast new file mode 100644 index 00000000..0ec72e09 --- /dev/null +++ b/test/values/transcode.wast @@ -0,0 +1,534 @@ +;; Test string transcoding between directly-linked components whose `canon +;; lower` (caller) and `canon lift` (callee) declare different string +;; encodings; each side checks the exact transcoded bytes in its own memory. + +;; utf16 caller -> utf8 callee, plus an empty-string round trip. utf16 lengths +;; count 16-bit code units (not bytes) and code units are little-endian. +(component + (component $C + (core module $M + (memory (export "mem") 1) + (global $next (mut i32) (i32.const 1024)) + (func (export "realloc") (param $old i32) (param $osize i32) (param $align i32) (param $nsize i32) (result i32) + (local $r i32) + ;; shrinking realloc: keep the (8-aligned) allocation in place + (if (i32.and (i32.ne (local.get $old) (i32.const 0)) + (i32.le_u (local.get $nsize) (local.get $osize))) + (then (return (local.get $old)))) + ;; fresh 8-aligned bump allocation + (global.set $next (i32.and (i32.add (global.get $next) (i32.const 7)) (i32.const -8))) + (local.set $r (global.get $next)) + (global.set $next (i32.add (global.get $next) (local.get $nsize))) + ;; growing realloc must preserve the old contents + (if (i32.ne (local.get $old) (i32.const 0)) + (then (memory.copy (local.get $r) (local.get $old) (local.get $osize)))) + (local.get $r)) + + ;; response "ok☃🍰" utf8 = 6F 6B E2 98 83 F0 9F 8D B0 (9 bytes) + (data (i32.const 64) "\6f\6b\e2\98\83\f0\9f\8d\b0") + + ;; expect "hö☃🍰" utf8 = 68 C3 B6 E2 98 83 F0 9F 8D B0 (10 bytes) + (func (export "join") (param $ptr i32) (param $len i32) (result i32) + (if (i32.ne (local.get $len) (i32.const 10)) (then unreachable)) + (if (i64.ne (i64.load (local.get $ptr)) (i64.const 0x9FF08398E2B6C368)) (then unreachable)) + (if (i32.ne (i32.load16_u offset=8 (local.get $ptr)) (i32.const 0xB08D)) (then unreachable)) + (i32.store (i32.const 0) (i32.const 64)) + (i32.store (i32.const 4) (i32.const 9)) + (i32.const 0)) + + ;; expect "" (0 bytes); respond "" as (ptr=0, len=0) + (func (export "empty") (param $ptr i32) (param $len i32) (result i32) + (if (i32.ne (local.get $len) (i32.const 0)) (then unreachable)) + (i32.store (i32.const 0) (i32.const 0)) + (i32.store (i32.const 4) (i32.const 0)) + (i32.const 0)) + ) + (core instance $m (instantiate $M)) + (func (export "join") (param "s" string) (result string) + (canon lift (core func $m "join") string-encoding=utf8 + (memory (core memory $m "mem")) (realloc (core func $m "realloc")))) + (func (export "empty") (param "s" string) (result string) + (canon lift (core func $m "empty") string-encoding=utf8 + (memory (core memory $m "mem")) (realloc (core func $m "realloc")))) + ) + + (component $D + (import "join" (func $join (param "s" string) (result string))) + (import "empty" (func $empty (param "s" string) (result string))) + (core module $Libc + (memory (export "mem") 1) + (global $next (mut i32) (i32.const 1024)) + (func (export "realloc") (param $old i32) (param $osize i32) (param $align i32) (param $nsize i32) (result i32) + (local $r i32) + (if (i32.and (i32.ne (local.get $old) (i32.const 0)) + (i32.le_u (local.get $nsize) (local.get $osize))) + (then (return (local.get $old)))) + (global.set $next (i32.and (i32.add (global.get $next) (i32.const 7)) (i32.const -8))) + (local.set $r (global.get $next)) + (global.set $next (i32.add (global.get $next) (local.get $nsize))) + (if (i32.ne (local.get $old) (i32.const 0)) + (then (memory.copy (local.get $r) (local.get $old) (local.get $osize)))) + (local.get $r)) + ) + (core instance $libc (instantiate $Libc)) + (core func $join' (canon lower (func $join) string-encoding=utf16 + (memory (core memory $libc "mem")) (realloc (core func $libc "realloc")))) + (core func $empty' (canon lower (func $empty) string-encoding=utf16 + (memory (core memory $libc "mem")) (realloc (core func $libc "realloc")))) + (core module $Main + (import "" "mem" (memory 1)) + (import "" "join" (func $join (param i32 i32 i32))) + (import "" "empty" (func $empty (param i32 i32 i32))) + + ;; argument "hö☃🍰" utf16 = 0068 00F6 2603 D83C DF70 (5 code units) + (data (i32.const 16) "\68\00\f6\00\03\26\3c\d8\70\df") + + (func (export "run") (result i32) + (local $p i32) + (call $join (i32.const 16) (i32.const 5) (i32.const 8)) + ;; expect "ok☃🍰" utf16 = 006F 006B 2603 D83C DF70 (5 code units) + (local.set $p (i32.load (i32.const 8))) + (if (i32.ne (i32.load (i32.const 12)) (i32.const 5)) (then unreachable)) + (if (i64.ne (i64.load (local.get $p)) (i64.const 0xD83C2603006B006F)) (then unreachable)) + (if (i32.ne (i32.load16_u offset=8 (local.get $p)) (i32.const 0xDF70)) (then unreachable)) + (call $empty (i32.const 16) (i32.const 0) (i32.const 8)) + (if (i32.ne (i32.load (i32.const 12)) (i32.const 0)) (then unreachable)) + (i32.const 42)) + ) + (core instance $main (instantiate $Main (with "" (instance + (export "mem" (memory $libc "mem")) + (export "join" (func $join')) + (export "empty" (func $empty')) + )))) + (func (export "run") (result u32) (canon lift (core func $main "run"))) + ) + + (instance $c (instantiate $C)) + (instance $d (instantiate $D + (with "join" (func $c "join")) + (with "empty" (func $c "empty")) + )) + (func (export "run") (alias export $d "run")) +) +(assert_return (invoke "run") (u32.const 42)) + +;; utf8 caller -> utf16 callee; the caller's `canon lower` omits +;; string-encoding, exercising the utf8 default. +(component + (component $C + (core module $M + (memory (export "mem") 1) + (global $next (mut i32) (i32.const 1024)) + (func (export "realloc") (param $old i32) (param $osize i32) (param $align i32) (param $nsize i32) (result i32) + (local $r i32) + (if (i32.and (i32.ne (local.get $old) (i32.const 0)) + (i32.le_u (local.get $nsize) (local.get $osize))) + (then (return (local.get $old)))) + (global.set $next (i32.and (i32.add (global.get $next) (i32.const 7)) (i32.const -8))) + (local.set $r (global.get $next)) + (global.set $next (i32.add (global.get $next) (local.get $nsize))) + (if (i32.ne (local.get $old) (i32.const 0)) + (then (memory.copy (local.get $r) (local.get $old) (local.get $osize)))) + (local.get $r)) + + ;; response "ök🍰" utf16 = 00F6 006B D83C DF70 (4 code units) + (data (i32.const 64) "\f6\00\6b\00\3c\d8\70\df") + + ;; expect "hö☃🍰" utf16 = 0068 00F6 2603 D83C DF70 (5 code units) + (func (export "join") (param $ptr i32) (param $units i32) (result i32) + (if (i32.ne (local.get $units) (i32.const 5)) (then unreachable)) + (if (i64.ne (i64.load (local.get $ptr)) (i64.const 0xD83C260300F60068)) (then unreachable)) + (if (i32.ne (i32.load16_u offset=8 (local.get $ptr)) (i32.const 0xDF70)) (then unreachable)) + (i32.store (i32.const 0) (i32.const 64)) + (i32.store (i32.const 4) (i32.const 4)) + (i32.const 0)) + ) + (core instance $m (instantiate $M)) + (func (export "join") (param "s" string) (result string) + (canon lift (core func $m "join") string-encoding=utf16 + (memory (core memory $m "mem")) (realloc (core func $m "realloc")))) + ) + + (component $D + (import "join" (func $join (param "s" string) (result string))) + (core module $Libc + (memory (export "mem") 1) + (global $next (mut i32) (i32.const 1024)) + (func (export "realloc") (param $old i32) (param $osize i32) (param $align i32) (param $nsize i32) (result i32) + (local $r i32) + (if (i32.and (i32.ne (local.get $old) (i32.const 0)) + (i32.le_u (local.get $nsize) (local.get $osize))) + (then (return (local.get $old)))) + (global.set $next (i32.and (i32.add (global.get $next) (i32.const 7)) (i32.const -8))) + (local.set $r (global.get $next)) + (global.set $next (i32.add (global.get $next) (local.get $nsize))) + (if (i32.ne (local.get $old) (i32.const 0)) + (then (memory.copy (local.get $r) (local.get $old) (local.get $osize)))) + (local.get $r)) + ) + (core instance $libc (instantiate $Libc)) + (core func $join' (canon lower (func $join) + (memory (core memory $libc "mem")) (realloc (core func $libc "realloc")))) + (core module $Main + (import "" "mem" (memory 1)) + (import "" "join" (func $join (param i32 i32 i32))) + + ;; argument "hö☃🍰" utf8 = 68 C3 B6 E2 98 83 F0 9F 8D B0 (10 bytes) + (data (i32.const 16) "\68\c3\b6\e2\98\83\f0\9f\8d\b0") + + (func (export "run") (result i32) + (local $p i32) + (call $join (i32.const 16) (i32.const 10) (i32.const 8)) + ;; expect "ök🍰" utf8 = C3 B6 6B F0 9F 8D B0 (7 bytes) + (local.set $p (i32.load (i32.const 8))) + (if (i32.ne (i32.load (i32.const 12)) (i32.const 7)) (then unreachable)) + (if (i32.ne (i32.load (local.get $p)) (i32.const 0xF06BB6C3)) (then unreachable)) + (if (i32.ne (i32.load16_u offset=4 (local.get $p)) (i32.const 0x8D9F)) (then unreachable)) + (if (i32.ne (i32.load8_u offset=6 (local.get $p)) (i32.const 0xB0)) (then unreachable)) + (i32.const 43)) + ) + (core instance $main (instantiate $Main (with "" (instance + (export "mem" (memory $libc "mem")) + (export "join" (func $join')) + )))) + (func (export "run") (result u32) (canon lift (core func $main "run"))) + ) + + (instance $c (instantiate $C)) + (instance $d (instantiate $D (with "join" (func $c "join")))) + (func (export "run") (alias export $d "run")) +) +(assert_return (invoke "run") (u32.const 43)) + +;; latin1+utf16 caller -> utf8 callee: the length's high bit tags a utf16 (vs +;; latin1) argument; the adapter picks the result representation by content. +(component + (component $C + (core module $M + (memory (export "mem") 1) + (global $next (mut i32) (i32.const 1024)) + (func (export "realloc") (param $old i32) (param $osize i32) (param $align i32) (param $nsize i32) (result i32) + (local $r i32) + (if (i32.and (i32.ne (local.get $old) (i32.const 0)) + (i32.le_u (local.get $nsize) (local.get $osize))) + (then (return (local.get $old)))) + (global.set $next (i32.and (i32.add (global.get $next) (i32.const 7)) (i32.const -8))) + (local.set $r (global.get $next)) + (global.set $next (i32.add (global.get $next) (local.get $nsize))) + (if (i32.ne (local.get $old) (i32.const 0)) + (then (memory.copy (local.get $r) (local.get $old) (local.get $osize)))) + (local.get $r)) + + ;; response "grün" utf8 = 67 72 C3 BC 6E (5 bytes) + (data (i32.const 64) "\67\72\c3\bc\6e") + ;; response "sn☃" utf8 = 73 6E E2 98 83 (5 bytes) + (data (i32.const 80) "\73\6e\e2\98\83") + + ;; expect "höla" utf8 = 68 C3 B6 6C 61 (5 bytes) + (func (export "compact") (param $ptr i32) (param $len i32) (result i32) + (if (i32.ne (local.get $len) (i32.const 5)) (then unreachable)) + (if (i32.ne (i32.load (local.get $ptr)) (i32.const 0x6CB6C368)) (then unreachable)) + (if (i32.ne (i32.load8_u offset=4 (local.get $ptr)) (i32.const 0x61)) (then unreachable)) + (i32.store (i32.const 0) (i32.const 64)) + (i32.store (i32.const 4) (i32.const 5)) + (i32.const 0)) + + ;; expect "☃🍰" utf8 = E2 98 83 F0 9F 8D B0 (7 bytes) + (func (export "unicode") (param $ptr i32) (param $len i32) (result i32) + (if (i32.ne (local.get $len) (i32.const 7)) (then unreachable)) + (if (i32.ne (i32.load (local.get $ptr)) (i32.const 0xF08398E2)) (then unreachable)) + (if (i32.ne (i32.load16_u offset=4 (local.get $ptr)) (i32.const 0x8D9F)) (then unreachable)) + (if (i32.ne (i32.load8_u offset=6 (local.get $ptr)) (i32.const 0xB0)) (then unreachable)) + (i32.store (i32.const 0) (i32.const 80)) + (i32.store (i32.const 4) (i32.const 5)) + (i32.const 0)) + ) + (core instance $m (instantiate $M)) + (func (export "compact") (param "s" string) (result string) + (canon lift (core func $m "compact") string-encoding=utf8 + (memory (core memory $m "mem")) (realloc (core func $m "realloc")))) + (func (export "unicode") (param "s" string) (result string) + (canon lift (core func $m "unicode") string-encoding=utf8 + (memory (core memory $m "mem")) (realloc (core func $m "realloc")))) + ) + + (component $D + (import "compact" (func $compact (param "s" string) (result string))) + (import "unicode" (func $unicode (param "s" string) (result string))) + (core module $Libc + (memory (export "mem") 1) + (global $next (mut i32) (i32.const 1024)) + (func (export "realloc") (param $old i32) (param $osize i32) (param $align i32) (param $nsize i32) (result i32) + (local $r i32) + (if (i32.and (i32.ne (local.get $old) (i32.const 0)) + (i32.le_u (local.get $nsize) (local.get $osize))) + (then (return (local.get $old)))) + (global.set $next (i32.and (i32.add (global.get $next) (i32.const 7)) (i32.const -8))) + (local.set $r (global.get $next)) + (global.set $next (i32.add (global.get $next) (local.get $nsize))) + (if (i32.ne (local.get $old) (i32.const 0)) + (then (memory.copy (local.get $r) (local.get $old) (local.get $osize)))) + (local.get $r)) + ) + (core instance $libc (instantiate $Libc)) + (core func $compact' (canon lower (func $compact) string-encoding=latin1+utf16 + (memory (core memory $libc "mem")) (realloc (core func $libc "realloc")))) + (core func $unicode' (canon lower (func $unicode) string-encoding=latin1+utf16 + (memory (core memory $libc "mem")) (realloc (core func $libc "realloc")))) + (core module $Main + (import "" "mem" (memory 1)) + (import "" "compact" (func $compact (param i32 i32 i32))) + (import "" "unicode" (func $unicode (param i32 i32 i32))) + + ;; argument "höla" latin1 = 68 F6 6C 61 (4 code units, untagged) + (data (i32.const 16) "\68\f6\6c\61") + ;; argument "☃🍰" utf16 = 2603 D83C DF70 (3 code units, tagged) + (data (i32.const 24) "\03\26\3c\d8\70\df") + + (func (export "run") (result i32) + (local $p i32) + (call $compact (i32.const 16) (i32.const 4) (i32.const 8)) + ;; expect "grün" latin1 = 67 72 FC 6E (4 code units, untagged) + (local.set $p (i32.load (i32.const 8))) + (if (i32.ne (i32.load (i32.const 12)) (i32.const 4)) (then unreachable)) + (if (i32.ne (i32.load (local.get $p)) (i32.const 0x6EFC7267)) (then unreachable)) + ;; tagged length 0x80000003 = high bit (utf16 tag) | 3 code units + (call $unicode (i32.const 24) (i32.const 0x80000003) (i32.const 8)) + ;; expect "sn☃" utf16 = 0073 006E 2603 (3 code units, tagged) + (local.set $p (i32.load (i32.const 8))) + (if (i32.ne (i32.load (i32.const 12)) (i32.const 0x80000003)) (then unreachable)) + (if (i32.ne (i32.load (local.get $p)) (i32.const 0x006E0073)) (then unreachable)) + (if (i32.ne (i32.load16_u offset=4 (local.get $p)) (i32.const 0x2603)) (then unreachable)) + (i32.const 44)) + ) + (core instance $main (instantiate $Main (with "" (instance + (export "mem" (memory $libc "mem")) + (export "compact" (func $compact')) + (export "unicode" (func $unicode')) + )))) + (func (export "run") (result u32) (canon lift (core func $main "run"))) + ) + + (instance $c (instantiate $C)) + (instance $d (instantiate $D + (with "compact" (func $c "compact")) + (with "unicode" (func $c "unicode")) + )) + (func (export "run") (alias export $d "run")) +) +(assert_return (invoke "run") (u32.const 44)) + +;; latin1+utf16 on both sides: utf16-tagged input whose code points all fit in +;; latin1 must arrive deflated to latin1; wide content stays utf16. +(component + (component $C + (core module $M + (memory (export "mem") 1) + (global $next (mut i32) (i32.const 1024)) + (func (export "realloc") (param $old i32) (param $osize i32) (param $align i32) (param $nsize i32) (result i32) + (local $r i32) + (if (i32.and (i32.ne (local.get $old) (i32.const 0)) + (i32.le_u (local.get $nsize) (local.get $osize))) + (then (return (local.get $old)))) + (global.set $next (i32.and (i32.add (global.get $next) (i32.const 7)) (i32.const -8))) + (local.set $r (global.get $next)) + (global.set $next (i32.add (global.get $next) (local.get $nsize))) + (if (i32.ne (local.get $old) (i32.const 0)) + (then (memory.copy (local.get $r) (local.get $old) (local.get $osize)))) + (local.get $r)) + + ;; response "øk" latin1 = F8 6B (2 code units, untagged) + (data (i32.const 64) "\f8\6b") + ;; response "n☃" utf16 = 006E 2603 (2 code units, tagged) + (data (i32.const 68) "\6e\00\03\26") + + ;; expect "AB" deflated to latin1 = 41 42 (2 code units, untagged) + (func (export "deflate") (param $ptr i32) (param $tagged i32) (result i32) + (if (i32.ne (local.get $tagged) (i32.const 2)) (then unreachable)) + (if (i32.ne (i32.load16_u (local.get $ptr)) (i32.const 0x4241)) (then unreachable)) + (i32.store (i32.const 0) (i32.const 64)) + (i32.store (i32.const 4) (i32.const 2)) + (i32.const 0)) + + ;; expect "☃" kept as utf16 = 2603 (1 code unit, tagged) + (func (export "keep-wide") (param $ptr i32) (param $tagged i32) (result i32) + (if (i32.ne (local.get $tagged) (i32.const 0x80000001)) (then unreachable)) + (if (i32.ne (i32.load16_u (local.get $ptr)) (i32.const 0x2603)) (then unreachable)) + (i32.store (i32.const 0) (i32.const 68)) + (i32.store (i32.const 4) (i32.const 0x80000002)) + (i32.const 0)) + ) + (core instance $m (instantiate $M)) + (func (export "deflate") (param "s" string) (result string) + (canon lift (core func $m "deflate") string-encoding=latin1+utf16 + (memory (core memory $m "mem")) (realloc (core func $m "realloc")))) + (func (export "keep-wide") (param "s" string) (result string) + (canon lift (core func $m "keep-wide") string-encoding=latin1+utf16 + (memory (core memory $m "mem")) (realloc (core func $m "realloc")))) + ) + + (component $D + (import "deflate" (func $deflate (param "s" string) (result string))) + (import "keep-wide" (func $keep-wide (param "s" string) (result string))) + (core module $Libc + (memory (export "mem") 1) + (global $next (mut i32) (i32.const 1024)) + (func (export "realloc") (param $old i32) (param $osize i32) (param $align i32) (param $nsize i32) (result i32) + (local $r i32) + (if (i32.and (i32.ne (local.get $old) (i32.const 0)) + (i32.le_u (local.get $nsize) (local.get $osize))) + (then (return (local.get $old)))) + (global.set $next (i32.and (i32.add (global.get $next) (i32.const 7)) (i32.const -8))) + (local.set $r (global.get $next)) + (global.set $next (i32.add (global.get $next) (local.get $nsize))) + (if (i32.ne (local.get $old) (i32.const 0)) + (then (memory.copy (local.get $r) (local.get $old) (local.get $osize)))) + (local.get $r)) + ) + (core instance $libc (instantiate $Libc)) + (core func $deflate' (canon lower (func $deflate) string-encoding=latin1+utf16 + (memory (core memory $libc "mem")) (realloc (core func $libc "realloc")))) + (core func $keep-wide' (canon lower (func $keep-wide) string-encoding=latin1+utf16 + (memory (core memory $libc "mem")) (realloc (core func $libc "realloc")))) + (core module $Main + (import "" "mem" (memory 1)) + (import "" "deflate" (func $deflate (param i32 i32 i32))) + (import "" "keep-wide" (func $keep-wide (param i32 i32 i32))) + + ;; argument "AB" over-encoded as utf16 = 0041 0042 (2 code units, tagged) + (data (i32.const 16) "\41\00\42\00") + ;; argument "☃" utf16 = 2603 (1 code unit, tagged) + (data (i32.const 24) "\03\26") + + (func (export "run") (result i32) + (local $p i32) + (call $deflate (i32.const 16) (i32.const 0x80000002) (i32.const 8)) + ;; expect "øk" latin1 = F8 6B (2 code units, untagged) + (local.set $p (i32.load (i32.const 8))) + (if (i32.ne (i32.load (i32.const 12)) (i32.const 2)) (then unreachable)) + (if (i32.ne (i32.load16_u (local.get $p)) (i32.const 0x6BF8)) (then unreachable)) + (call $keep-wide (i32.const 24) (i32.const 0x80000001) (i32.const 8)) + ;; expect "n☃" utf16 = 006E 2603 (2 code units, tagged) + (local.set $p (i32.load (i32.const 8))) + (if (i32.ne (i32.load (i32.const 12)) (i32.const 0x80000002)) (then unreachable)) + (if (i32.ne (i32.load (local.get $p)) (i32.const 0x2603006E)) (then unreachable)) + (i32.const 45)) + ) + (core instance $main (instantiate $Main (with "" (instance + (export "mem" (memory $libc "mem")) + (export "deflate" (func $deflate')) + (export "keep-wide" (func $keep-wide')) + )))) + (func (export "run") (result u32) (canon lift (core func $main "run"))) + ) + + (instance $c (instantiate $C)) + (instance $d (instantiate $D + (with "deflate" (func $c "deflate")) + (with "keep-wide" (func $c "keep-wide")) + )) + (func (export "run") (alias export $d "run")) +) +(assert_return (invoke "run") (u32.const 45)) + +;; list across a utf16 caller -> utf8 callee boundary: each element is +;; transcoded individually and its (ptr, length) pair rebuilt in the callee's +;; memory. +(component + (component $C + (core module $M + (memory (export "mem") 1) + (global $next (mut i32) (i32.const 1024)) + (func (export "realloc") (param $old i32) (param $osize i32) (param $align i32) (param $nsize i32) (result i32) + (local $r i32) + (if (i32.and (i32.ne (local.get $old) (i32.const 0)) + (i32.le_u (local.get $nsize) (local.get $osize))) + (then (return (local.get $old)))) + (global.set $next (i32.and (i32.add (global.get $next) (i32.const 7)) (i32.const -8))) + (local.set $r (global.get $next)) + (global.set $next (i32.add (global.get $next) (local.get $nsize))) + (if (i32.ne (local.get $old) (i32.const 0)) + (then (memory.copy (local.get $r) (local.get $old) (local.get $osize)))) + (local.get $r)) + + ;; response "ok" utf8 = 6F 6B (2 bytes) + (data (i32.const 64) "\6f\6b") + + ;; expect ["hi", "", "☃🍰"] as three (ptr, byte-length) pairs of utf8 + (func (export "concat") (param $ptr i32) (param $len i32) (result i32) + (local $p i32) + (if (i32.ne (local.get $len) (i32.const 3)) (then unreachable)) + ;; element 0: "hi" utf8 = 68 69 (2 bytes) + (local.set $p (i32.load (local.get $ptr))) + (if (i32.ne (i32.load offset=4 (local.get $ptr)) (i32.const 2)) (then unreachable)) + (if (i32.ne (i32.load16_u (local.get $p)) (i32.const 0x6968)) (then unreachable)) + ;; element 1: "" (0 bytes) + (if (i32.ne (i32.load offset=12 (local.get $ptr)) (i32.const 0)) (then unreachable)) + ;; element 2: "☃🍰" utf8 = E2 98 83 F0 9F 8D B0 (7 bytes) + (local.set $p (i32.load offset=16 (local.get $ptr))) + (if (i32.ne (i32.load offset=20 (local.get $ptr)) (i32.const 7)) (then unreachable)) + (if (i32.ne (i32.load (local.get $p)) (i32.const 0xF08398E2)) (then unreachable)) + (if (i32.ne (i32.load16_u offset=4 (local.get $p)) (i32.const 0x8D9F)) (then unreachable)) + (if (i32.ne (i32.load8_u offset=6 (local.get $p)) (i32.const 0xB0)) (then unreachable)) + (i32.store (i32.const 0) (i32.const 64)) + (i32.store (i32.const 4) (i32.const 2)) + (i32.const 0)) + ) + (core instance $m (instantiate $M)) + (func (export "concat") (param "l" (list string)) (result string) + (canon lift (core func $m "concat") string-encoding=utf8 + (memory (core memory $m "mem")) (realloc (core func $m "realloc")))) + ) + + (component $D + (import "concat" (func $concat (param "l" (list string)) (result string))) + (core module $Libc + (memory (export "mem") 1) + (global $next (mut i32) (i32.const 1024)) + (func (export "realloc") (param $old i32) (param $osize i32) (param $align i32) (param $nsize i32) (result i32) + (local $r i32) + (if (i32.and (i32.ne (local.get $old) (i32.const 0)) + (i32.le_u (local.get $nsize) (local.get $osize))) + (then (return (local.get $old)))) + (global.set $next (i32.and (i32.add (global.get $next) (i32.const 7)) (i32.const -8))) + (local.set $r (global.get $next)) + (global.set $next (i32.add (global.get $next) (local.get $nsize))) + (if (i32.ne (local.get $old) (i32.const 0)) + (then (memory.copy (local.get $r) (local.get $old) (local.get $osize)))) + (local.get $r)) + ) + (core instance $libc (instantiate $Libc)) + (core func $concat' (canon lower (func $concat) string-encoding=utf16 + (memory (core memory $libc "mem")) (realloc (core func $libc "realloc")))) + (core module $Main + (import "" "mem" (memory 1)) + (import "" "concat" (func $concat (param i32 i32 i32))) + + ;; element 0: "hi" utf16 = 0068 0069 (2 code units) + (data (i32.const 32) "\68\00\69\00") + ;; element 2: "☃🍰" utf16 = 2603 D83C DF70 (3 code units) + (data (i32.const 40) "\03\26\3c\d8\70\df") + ;; argument ["hi", "", "☃🍰"] as (ptr, code-units) pairs: (32, 2) (0, 0) (40, 3) + (data (i32.const 64) "\20\00\00\00\02\00\00\00\00\00\00\00\00\00\00\00\28\00\00\00\03\00\00\00") + + (func (export "run") (result i32) + (local $p i32) + (call $concat (i32.const 64) (i32.const 3) (i32.const 8)) + ;; expect "ok" utf16 = 006F 006B (2 code units) + (local.set $p (i32.load (i32.const 8))) + (if (i32.ne (i32.load (i32.const 12)) (i32.const 2)) (then unreachable)) + (if (i32.ne (i32.load (local.get $p)) (i32.const 0x006B006F)) (then unreachable)) + (i32.const 46)) + ) + (core instance $main (instantiate $Main (with "" (instance + (export "mem" (memory $libc "mem")) + (export "concat" (func $concat')) + )))) + (func (export "run") (result u32) (canon lift (core func $main "run"))) + ) + + (instance $c (instantiate $C)) + (instance $d (instantiate $D (with "concat" (func $c "concat")))) + (func (export "run") (alias export $d "run")) +) +(assert_return (invoke "run") (u32.const 46)) diff --git a/test/values/variants.wast b/test/values/variants.wast new file mode 100644 index 00000000..80737dfa --- /dev/null +++ b/test/values/variants.wast @@ -0,0 +1,186 @@ +;; Runtime checks for variant/enum values originating in core wasm and +;; crossing a component-to-component boundary: discriminant range checks and +;; the flat-ABI join of differently-typed case payloads into one core slot. + +;; Out-of-range discriminants trap when lifted, in both directions. +(component definition $BadDiscriminant + (component $C + (type $v32' (variant (case "x" u32))) + (export $v32 "v32" (type $v32')) + (type $v0' (variant (case "x"))) + (export $v0 "v0" (type $v0')) + (type $e2' (enum "a" "b")) + (export $e2 "e2" (type $e2')) + (core module $M + (func (export "take-variant") (param i32 i32)) + (func (export "give-variant") (result i32) (i32.const 1)) + (func (export "take-enum") (param i32)) + (func (export "give-enum") (result i32) (i32.const 2)) + ) + (core instance $m (instantiate $M)) + (func (export "take-variant") (param "v" $v32) (canon lift (core func $m "take-variant"))) + (func (export "give-variant") (result $v0) (canon lift (core func $m "give-variant"))) + (func (export "take-enum") (param "e" $e2) (canon lift (core func $m "take-enum"))) + (func (export "give-enum") (result $e2) (canon lift (core func $m "give-enum"))) + ) + (component $D + (import "c" (instance $c + (type $v32' (variant (case "x" u32))) + (export "v32" (type $v32 (eq $v32'))) + (type $v0' (variant (case "x"))) + (export "v0" (type $v0 (eq $v0'))) + (type $e2' (enum "a" "b")) + (export "e2" (type $e2 (eq $e2'))) + (export "take-variant" (func (param "v" $v32))) + (export "give-variant" (func (result $v0))) + (export "take-enum" (func (param "e" $e2))) + (export "give-enum" (func (result $e2))) + )) + (core func $take-variant' (canon lower (func $c "take-variant"))) + (core func $give-variant' (canon lower (func $c "give-variant"))) + (core func $take-enum' (canon lower (func $c "take-enum"))) + (core func $give-enum' (canon lower (func $c "give-enum"))) + (core module $Main + (import "" "take-variant" (func $take-variant (param i32 i32))) + (import "" "give-variant" (func $give-variant (result i32))) + (import "" "take-enum" (func $take-enum (param i32))) + (import "" "give-enum" (func $give-enum (result i32))) + (func (export "bad-variant-param") (call $take-variant (i32.const 1) (i32.const 0))) + (func (export "bad-variant-result") (drop (call $give-variant))) + (func (export "bad-enum-param") (call $take-enum (i32.const 2))) + (func (export "bad-enum-result") (drop (call $give-enum))) + ) + (core instance $main (instantiate $Main (with "" (instance + (export "take-variant" (func $take-variant')) + (export "give-variant" (func $give-variant')) + (export "take-enum" (func $take-enum')) + (export "give-enum" (func $give-enum')) + )))) + (func (export "bad-variant-param") (canon lift (core func $main "bad-variant-param"))) + (func (export "bad-variant-result") (canon lift (core func $main "bad-variant-result"))) + (func (export "bad-enum-param") (canon lift (core func $main "bad-enum-param"))) + (func (export "bad-enum-result") (canon lift (core func $main "bad-enum-result"))) + ) + (instance $c (instantiate $C)) + (instance $d (instantiate $D (with "c" (instance $c)))) + (func (export "bad-variant-param") (alias export $d "bad-variant-param")) + (func (export "bad-variant-result") (alias export $d "bad-variant-result")) + (func (export "bad-enum-param") (alias export $d "bad-enum-param")) + (func (export "bad-enum-result") (alias export $d "bad-enum-result")) +) + +(component instance $i $BadDiscriminant) +(assert_trap (invoke "bad-variant-param") "invalid variant discriminant") +(component instance $i $BadDiscriminant) +(assert_trap (invoke "bad-variant-result") "invalid variant discriminant") +(component instance $i $BadDiscriminant) +(assert_trap (invoke "bad-enum-param") "invalid variant discriminant") +(component instance $i $BadDiscriminant) +(assert_trap (invoke "bad-enum-result") "invalid variant discriminant") + +;; Case payloads of different flat types share one joined core slot; only the +;; bits of the selected case's type survive the crossing. +(component + (component $C + (type $narrow' (variant (case "a" u8) (case "b" u32))) ;; payload slot: i32 + (export $narrow "narrow-t" (type $narrow')) + (type $wide' (variant (case "a" u16) (case "b" u64))) ;; payload slot: i64 + (export $wide "wide-t" (type $wide')) + (type $mix' (variant (case "f" f32) (case "l" u64))) ;; payload slot: i64 + (export $mix "mix-t" (type $mix')) + (core module $M + (import "" "task.return" (func $task.return-mix (param i32 i64))) + (func (export "narrow") (param i32 i32) + (if (i32.eqz (local.get 0)) + (then (if (i32.ne (local.get 1) (i32.const 2)) (then unreachable))) + (else (if (i32.ne (local.get 1) (i32.const 0xdeadbeef)) (then unreachable))))) + (func (export "wide") (param i32 i64) + (if (i32.eqz (local.get 0)) + (then (if (i64.ne (local.get 1) (i64.const 4)) (then unreachable))) + (else (if (i64.ne (local.get 1) (i64.const 0x123456789abcdef0)) (then unreachable))))) + (func (export "mix") (param i32 i64) + (if (i32.eqz (local.get 0)) + (then (if (i64.ne (local.get 1) (i64.const 0x40490fdb)) (then unreachable))) + (else (if (i64.ne (local.get 1) (i64.const 0xfedcba9876543210)) (then unreachable))))) + (func (export "mix-ret") + ;; f32 bits travel in the low half of the i64 join slot; high bits dropped + (call $task.return-mix (i32.const 0) (i64.const 0xffffffff40490fdb))) + ) + (canon task.return (result $mix) (core func $task.return-mix)) + (core instance $m (instantiate $M (with "" (instance + (export "task.return" (func $task.return-mix)) + )))) + (func (export "narrow") (param "v" $narrow) (canon lift (core func $m "narrow"))) + (func (export "wide") (param "v" $wide) (canon lift (core func $m "wide"))) + (func (export "mix") (param "v" $mix) (canon lift (core func $m "mix"))) + (func (export "mix-ret") async (result $mix) (canon lift (core func $m "mix-ret") async)) + ) + (component $D + (import "c" (instance $c + (type $narrow' (variant (case "a" u8) (case "b" u32))) + (export "narrow-t" (type $narrow (eq $narrow'))) + (type $wide' (variant (case "a" u16) (case "b" u64))) + (export "wide-t" (type $wide (eq $wide'))) + (type $mix' (variant (case "f" f32) (case "l" u64))) + (export "mix-t" (type $mix (eq $mix'))) + (export "narrow" (func (param "v" $narrow))) + (export "wide" (func (param "v" $wide))) + (export "mix" (func (param "v" $mix))) + (export "mix-ret" (func async (result $mix))) + )) + (core module $Memory (memory (export "mem") 1)) + (core instance $memory (instantiate $Memory)) + (core func $narrow' (canon lower (func $c "narrow"))) + (core func $wide' (canon lower (func $c "wide"))) + (core func $mix' (canon lower (func $c "mix"))) + (core func $mix-ret' (canon lower (func $c "mix-ret") async (memory (core memory $memory "mem")))) + (core module $Main + (import "" "mem" (memory 1)) + (import "" "narrow" (func $narrow (param i32 i32))) + (import "" "wide" (func $wide (param i32 i64))) + (import "" "mix" (func $mix (param i32 i64))) + (import "" "mix-ret" (func $mix-ret (param i32) (result i32))) + (func (export "join-narrow") (result i32) + (call $narrow (i32.const 0) (i32.const 0xff02)) ;; u8 case: lifts as 2 + (call $narrow (i32.const 1) (i32.const 0xdeadbeef)) + (i32.const 42)) + (func (export "join-wide") (result i32) + (call $wide (i32.const 0) (i64.const 0xff0004)) ;; u16 case: lifts as 4 + (call $wide (i32.const 0) (i64.const 0xff00000004)) ;; also wraps i64 to i32 + (call $wide (i32.const 1) (i64.const 0x123456789abcdef0)) + (i32.const 43)) + (func (export "join-f32") (result i32) + (call $mix (i32.const 0) (i64.const 0xffffffff40490fdb)) ;; f32 bits in low half + (call $mix (i32.const 1) (i64.const 0xfedcba9876543210)) + (i32.const 44)) + (func (export "ret-f32") (result i32) + (if (i32.ne (call $mix-ret (i32.const 16)) (i32.const 2 (; RETURNED ;))) + (then unreachable)) + (if (i32.ne (i32.load8_u (i32.const 16)) (i32.const 0)) (then unreachable)) + (if (i32.ne (i32.load offset=8 (i32.const 16)) (i32.const 0x40490fdb)) (then unreachable)) + (i32.const 45)) + ) + (core instance $main (instantiate $Main (with "" (instance + (export "mem" (memory $memory "mem")) + (export "narrow" (func $narrow')) + (export "wide" (func $wide')) + (export "mix" (func $mix')) + (export "mix-ret" (func $mix-ret')) + )))) + (func (export "join-narrow") (result u32) (canon lift (core func $main "join-narrow"))) + (func (export "join-wide") (result u32) (canon lift (core func $main "join-wide"))) + (func (export "join-f32") (result u32) (canon lift (core func $main "join-f32"))) + (func (export "ret-f32") (result u32) (canon lift (core func $main "ret-f32"))) + ) + (instance $c (instantiate $C)) + (instance $d (instantiate $D (with "c" (instance $c)))) + (func (export "join-narrow") (alias export $d "join-narrow")) + (func (export "join-wide") (alias export $d "join-wide")) + (func (export "join-f32") (alias export $d "join-f32")) + (func (export "ret-f32") (alias export $d "ret-f32")) +) + +(assert_return (invoke "join-narrow") (u32.const 42)) +(assert_return (invoke "join-wide") (u32.const 43)) +(assert_return (invoke "join-f32") (u32.const 44)) +(assert_return (invoke "ret-f32") (u32.const 45)) diff --git a/test/wasm-tools/adapt.wast b/test/wasm-tools/adapt.wast deleted file mode 100644 index 44f195e2..00000000 --- a/test/wasm-tools/adapt.wast +++ /dev/null @@ -1,287 +0,0 @@ -;; RUN: wast --assert default --snapshot tests/snapshots % - -(component definition - (import "log" (func $log (param "msg" string))) - (core module $libc - (memory (export "memory") 1) - (func (export "canonical_abi_realloc") (param i32 i32 i32 i32) (result i32) - unreachable) - ) - - (core module $my_module - (import "env" "log-utf8" (func $log_utf8 (param i32 i32))) - (import "env" "log-utf16" (func $log_utf16 (param i32 i32))) - (import "env" "log-compact-utf16" (func $log_compact_utf16 (param i32 i32))) - - (func (export "log-utf8") (param i32 i32) - local.get 0 - local.get 1 - call $log_utf8 - ) - (func (export "log-utf16") (param i32 i32) - local.get 0 - local.get 1 - call $log_utf16 - ) - (func (export "log-compact-utf16") (param i32 i32) - local.get 0 - local.get 1 - call $log_compact_utf16 - ) - ) - - (core instance $libc (instantiate $libc)) - - (alias core export $libc "canonical_abi_realloc" (core func $realloc)) - (alias core export $libc "memory" (core memory $memory)) - (core func $log_lower_utf8 (canon lower (func $log) string-encoding=utf8 (memory $memory) (realloc $realloc))) - (core func $log_lower_utf16 (canon lower (func $log) string-encoding=utf16 (memory $memory) (realloc $realloc))) - (core func $log_lower_compact_utf16 (canon lower (func $log) string-encoding=latin1+utf16 (memory $memory) (realloc $realloc))) - - (core instance $my_instance (instantiate $my_module - (with "libc" (instance $libc)) - (with "env" (instance - (export "log-utf8" (func $log_lower_utf8)) - (export "log-utf16" (func $log_lower_utf16)) - (export "log-compact-utf16" (func $log_lower_compact_utf16)) - )) - )) - - (func (export "log1") (param "msg" string) - (canon lift - (core func $my_instance "log-utf8") - string-encoding=utf8 - (memory $memory) - (realloc $realloc) - ) - ) - (func (export "log2") (param "msg" string) - (canon lift - (core func $my_instance "log-utf16") - string-encoding=utf16 - (memory $memory) - (realloc $realloc) - ) - ) - (func (export "log3") (param "msg" string) - (canon lift - (core func $my_instance "log-compact-utf16") - string-encoding=latin1+utf16 - (memory $memory) - (realloc $realloc) - ) - ) -) - -(assert_invalid - (component - (import "i" (func $f)) - (core func (canon lower (func $f) string-encoding=utf8 string-encoding=utf16)) - ) - "canonical encoding option `utf8` conflicts with option `utf16`") - -(assert_invalid - (component - (import "i" (func $f)) - (core func (canon lower (func $f) string-encoding=utf8 string-encoding=latin1+utf16)) - ) - "canonical encoding option `utf8` conflicts with option `latin1-utf16`") - -(assert_invalid - (component - (import "i" (func $f)) - (core func (canon lower (func $f) string-encoding=utf16 string-encoding=latin1+utf16)) - ) - "canonical encoding option `utf16` conflicts with option `latin1-utf16`") - -(assert_invalid - (component - (import "i" (func $f)) - (core func (canon lower (func $f) (memory 0))) - ) - "memory index out of bounds") - -(assert_invalid - (component - (import "i" (func $f)) - (core module $m (memory (export "memory") 1)) - (core instance $i (instantiate $m)) - (core func (canon lower (func $f) (memory (core memory $i "memory")) (memory (core memory $i "memory")))) - ) - "`memory` is specified more than once") - -(assert_invalid - (component - (core module $m - (func (export "f") (param i32 i32)) - ) - (core instance $i (instantiate $m)) - (func (param "p1" (list u8)) (canon lift (core func $i "f"))) - ) - "canonical option `memory` is required") - -(assert_invalid - (component - (core module $m - (memory (export "m") 1) - (func (export "f") (param i32 i32)) - ) - (core instance $i (instantiate $m)) - (func (param "p1" (list u8)) - (canon lift (core func $i "f") - (memory (core memory $i "m")) - ) - ) - ) - "canonical option `realloc` is required") - -(assert_invalid - (component - (core module $m - (memory (export "m") 1) - (func (export "f") (param i32 i32)) - (func (export "r") (param i32 i32 i32 i32) (result i32)) - ) - (core instance $i (instantiate $m)) - (func (param "p1" (list u8)) - (canon lift (core func $i "f") - (memory (core memory $i "m")) - (realloc (core func $i "r")) - (realloc (core func $i "r")) - ) - ) - ) - "canonical option `realloc` is specified more than once") - -(assert_invalid - (component - (core module $m - (memory (export "m") 1) - (func (export "f") (param i32 i32)) - (func (export "r")) - ) - (core instance $i (instantiate $m)) - (func (param "p1" (list u8)) - (canon lift (core func $i "f") - (memory (core memory $i "m")) - (realloc (core func $i "r")) - ) - ) - ) - "canonical option `realloc` uses a core function with an incorrect signature") - -(assert_invalid - (component - (core module $m - (memory (export "m") 1) - (func (export "f") (result i32)) - (func (export "r") (param i32 i32 i32 i32) (result i32)) - (func (export "p")) - ) - (core instance $i (instantiate $m)) - (func (result string) - (canon lift (core func $i "f") - (memory (core memory $i "m")) - (realloc (core func $i "r")) - (post-return (core func $i "p")) - ) - ) - ) - "canonical option `post-return` uses a core function with an incorrect signature") - -(assert_invalid - (component - (core module $m - (memory (export "m") 1) - (func (export "f") (result i32)) - (func (export "r") (param i32 i32 i32 i32) (result i32)) - (func (export "p") (param i32)) - ) - (core instance $i (instantiate $m)) - (func (result string) - (canon lift (core func $i "f") - (memory (core memory $i "m")) - (realloc (core func $i "r")) - (post-return (core func $i "p")) - (post-return (core func $i "p")) - ) - ) - ) - "canonical option `post-return` is specified more than once") - -(assert_invalid - (component - (import "i" (func $f (param "p1" string))) - (core module $m - (memory (export "m") 1) - (func (export "f") (result i32)) - (func (export "r") (param i32 i32 i32 i32) (result i32)) - (func (export "p") (param i32)) - ) - (core instance $i (instantiate $m)) - (core func - (canon lower (func $f) - (memory (core memory $i "m")) - (realloc (core func $i "r")) - (post-return (core func $i "p")) - ) - ) - ) - "canonical option `post-return` cannot be specified for lowerings") - -(component - (core module $m - (memory (export "m") 1) - (func (export "f") (result i32) unreachable) - (func (export "r") (param i32 i32 i32 i32) (result i32) unreachable) - (func (export "p") (param i32)) - ) - (core instance $i (instantiate $m)) - (func (result string) - (canon lift (core func $i "f") - (memory (core memory $i "m")) - (realloc (core func $i "r")) - (post-return (core func $i "p")) - ) - ) -) - -(assert_malformed - (component quote - "(core module $m (func (export \"\")))" - "(core instance $i (instantiate $m))" - "(core func (canon lower (func $i \"\")))" - ) - "unknown instance: failed to find name `$i`") - -(assert_invalid - (component - (core module $m (func (export "foo") (param i32))) - (core instance $i (instantiate $m)) - (func (export "foo") (canon lift (core func $i "foo"))) - ) - "lowered parameter types `[]` do not match parameter types `[I32]`") - -(assert_invalid - (component - (core module $m (func (export "foo") (result i32))) - (core instance $i (instantiate $m)) - (func (export "foo") (canon lift (core func $i "foo"))) - ) - "lowered result types `[]` do not match result types `[I32]`") - -(assert_invalid - (component - (type $f string) - (core module $m (func (export "foo"))) - (core instance $i (instantiate $m)) - (func (export "foo") (type $f) (canon lift (core func $i "foo"))) - ) - "not a function type") - -(assert_malformed - (component quote - "(import \"a\" (func $f))" - "(func (export \"foo\") (canon lift (core func $f)))" - ) - "unknown core func: failed to find name `$f`") diff --git a/test/wasm-tools/alias.wast b/test/wasm-tools/alias.wast deleted file mode 100644 index dd9d1b37..00000000 --- a/test/wasm-tools/alias.wast +++ /dev/null @@ -1,301 +0,0 @@ -;; RUN: wast --assert default --snapshot tests/snapshots % - -(component - (component - (import "i" (instance $i - (export "f1" (func)) - (export "f2" (func (param "p1" string))) - )) - (export "run" (func $i "f1")) - ) -) - -(component - (component - (import "i" (component $c - (export "f1" (func)) - (export "f2" (func (param "p1" string))) - )) - (instance $i (instantiate $c)) - (export "run" (func $i "f1")) - ) -) - -(component definition - (import "i" (core module $m - (export "f1" (func $f1)) - (export "f2" (func $f2 (param i32))) - )) - (core instance $i (instantiate $m)) - - (core module $m2 (import "" "" (func))) - - (core instance (instantiate $m2 (with "" (instance (export "" (func $i "f1")))))) -) - -(component definition - (import "a" (core module $libc - (export "memory" (memory 1)) - (export "table" (table 0 funcref)) - (export "func" (func)) - (export "global" (global i32)) - (export "global mut" (global (mut i64))) - )) - (core instance $libc (instantiate $libc)) - (alias core export $libc "memory" (core memory $mem)) - (alias core export $libc "table" (core table $tbl)) - (alias core export $libc "func" (core func $func)) - (alias core export $libc "global" (core global $global)) - (alias core export $libc "global mut" (core global $global_mut)) - - (import "x" (core module $needs_libc - (import "" "memory" (memory 1)) - (import "" "table" (table 0 funcref)) - (import "" "func" (func)) - (import "" "global" (global i32)) - (import "" "global mut" (global (mut i64))) - )) - - (core instance (instantiate $needs_libc (with "" (instance - (export "memory" (memory $mem)) - (export "table" (table $tbl)) - (export "func" (func $func)) - (export "global" (global $global)) - (export "global mut" (global $global_mut)) - )))) -) - -(component - (component - (import "a" (instance $i - (export "a" (func)) - (export "b" (core module)) - (export "c" (instance)) - )) - (export "b" (func $i "a")) - (export "c" (core module $i "b")) - (export "d" (instance $i "c")) - ) -) - - -(component definition - (import "a" (core module $libc - (export "memory" (memory 1)) - (export "table" (table 0 funcref)) - (export "func" (func)) - (export "global" (global i32)) - (export "global mut" (global (mut i64))) - )) - - (import "b" (core module $needs_libc - (import "" "memory" (memory 1)) - (import "" "table" (table 0 funcref)) - (import "" "func" (func)) - (import "" "global" (global i32)) - (import "" "global mut" (global (mut i64))) - )) - - (core instance $libc (instantiate $libc)) - (core instance (instantiate $needs_libc (with "" (instance - (export "memory" (memory $libc "memory")) - (export "table" (table $libc "table")) - (export "func" (func $libc "func")) - (export "global" (global $libc "global")) - (export "global mut" (global $libc "global mut")) - )))) -) - -(assert_invalid - (component - (import "a" (instance (export "a" (func)))) - (export "a" (core module 0 "a")) - ) - "export `a` for instance 0 is not a module") - -(assert_invalid - (component - (component - (component (export "a")) - ) - (instance (instantiate 0)) - (export "a" (core module 0 "a")) - ) - "export `a` for instance 0 is not a module") - -(assert_invalid - (component - (import "a" (core module)) - (core instance (instantiate 0)) - (alias core export 0 "a" (core func)) - ) - "core instance 0 has no export named `a`") - -(assert_invalid - (component - (core module) - (core instance (instantiate 0)) - (alias core export 0 "a" (core func)) - ) - "core instance 0 has no export named `a`") - -(assert_invalid - (component - (import "a" (component)) - (instance (instantiate 0)) - (alias export 0 "a" (func)) - ) - "instance 0 has no export named `a`") - -(assert_invalid - (component - (import "a" (core module $a (export "" (func)))) - (import "b" (core module $b (import "" "" (func (param i32))))) - - (core instance $a (instantiate $a)) - (core instance $b (instantiate $b (with "" (instance $a)))) - ) - "type mismatch") - -;; aliasing various items works - -(component $PARENT - (type $t (func (result string))) - (component - (import "a" (func (type $t))) - ) - (component - (alias outer $PARENT $t (type $my_type)) - (alias outer 0 $my_type (type $my_type_again)) - (import "a" (func (type $my_type_again))) - ) -) - -(component - (type $a (func (result string))) - (component - (type $b (func (result u32))) - (component - (type $c (func (result s32))) - - (component - (import "a" (func $a (type $a))) - (import "b" (func $b (type $b))) - (import "c" (func $c (type $c))) - - (import "d" (component $C - (import "a" (func (result string))) - (import "b" (func (result u32))) - (import "c" (func (result s32))) - )) - - (instance (instantiate $C - (with "a" (func $a)) - (with "b" (func $b)) - (with "c" (func $c)) - )) - ) - ) - ) -) - -;; multiple projections in alias sugar -(component - (component $a - (import "a" (instance $a - (export "a" (instance - (export "a" (instance - (export "a" (instance - (export "a" (func)) - )) - )) - )) - )) - - (import "b" (component $b (import "a" (func)))) - - (instance (instantiate $b - (with "a" (func $a "a" "a" "a" "a")) - )) - ) -) - -;; alias some constructs -(component - (component - (import "a" (instance $foo (export "v" (component)))) - (export "v" (component $foo "v")) - ) -) - -(component definition - (import "a" (instance $foo (export "v" (core module)))) - (export "v" (core module $foo "v")) -) - -(component $C - (core type $t (func)) - (component $C2 - (alias outer $C $t (core type $t2)) - (component - (alias outer $C $t (core type)) - (alias outer $C2 $t2 (core type)) - ) - ) -) - -(component $C - (core module $m) - (alias outer $C $m (core module $target)) - (export "v" (core module $target)) -) - -(component - (component $C - (component $m) - (alias outer $C $m (component $target)) - (export "v" (component $target)) - ) -) - -(assert_invalid - (component (alias outer 100 0 (core type))) - "invalid outer alias count of 100") - -(assert_invalid - (component (alias outer 0 0 (core type))) - "index out of bounds") - -(assert_invalid - (component (alias outer 100 0 (core module))) - "invalid outer alias count of 100") - -(assert_invalid - (component (alias outer 0 0 (core module))) - "index out of bounds") - -(assert_invalid - (component (alias outer 100 0 (component))) - "invalid outer alias count of 100") - -(assert_invalid - (component (alias outer 0 0 (component))) - "index out of bounds") - -(component definition - (import "a" (instance $i - (export "x" (core module)) - )) - ;; inline alias injection sugar works for module references - (core instance (instantiate (module $i "x"))) -) - -(component - (component - (import "a" (instance $i - (export "x" (component)) - )) - ;; inline alias injection sugar works for component references - (instance (instantiate (component $i "x"))) - ) -) diff --git a/test/wasm-tools/big.wast b/test/wasm-tools/big.wast deleted file mode 100644 index e3f23ccf..00000000 --- a/test/wasm-tools/big.wast +++ /dev/null @@ -1,36 +0,0 @@ -;; RUN: wast --assert default --snapshot tests/snapshots % - -(component definition - (import "wasi-logging" (instance $logging - (export "log" (func (param "msg" string))) - )) - (import "libc" (core module $Libc - (export "memory" (memory 1)) - (export "realloc" (func (param i32 i32 i32 i32) (result i32))) - )) - (core instance $libc (instantiate $Libc)) - (core func $log (canon lower - (func $logging "log") - (memory (core memory $libc "memory")) (realloc (core func $libc "realloc")) - )) - (core module $Main - (import "libc" "memory" (memory 1)) - (import "libc" "realloc" (func (param i32 i32 i32 i32) (result i32))) - (import "wasi-logging" "log" (func $log (param i32 i32))) - (func (export "run") (param i32 i32) (result i32) - (local.get 0) - (local.get 1) - (call $log) - (unreachable) - ) - ) - (core instance $main (instantiate $Main - (with "libc" (instance $libc)) - (with "wasi-logging" (instance (export "log" (func $log)))) - )) - (func $run (param "in" string) (result string) (canon lift - (core func $main "run") - (memory (core memory $libc "memory")) (realloc (core func $libc "realloc")) - )) - (export "run" (func $run)) -) diff --git a/test/wasm-tools/definedtypes.wast b/test/wasm-tools/definedtypes.wast deleted file mode 100644 index ca24c124..00000000 --- a/test/wasm-tools/definedtypes.wast +++ /dev/null @@ -1,123 +0,0 @@ -;; RUN: wast --assert default --snapshot tests/snapshots % - -(component $C - (type $A1 bool) - (type $A2 u8) - (type $A3 s8) - (type $A4 u16) - (type $A5 s16) - (type $A6 u32) - (type $A7 s32) - (type $A8 u64) - (type $A9 s64) - (type $A10a f32) - (type $A11a f64) - (type $A10b float32) - (type $A11b float64) - (type $A12 char) - (type $A13 string) - - (type $A14b (record (field "x" (tuple char)))) - (type $A14c (record (field "x" $A1))) - - (type $A15a (variant (case "x"))) - (type $A15b (variant (case "x" $A1))) - (type $A15c (variant (case $x "x") (case $y "y" string) (case "z" string))) - (type $A15d (variant (case "x") (case "y" string) (case "z" string))) - - (type $A16a (list (tuple u8))) - (type $A16b (list $A3)) - - (type $A17a (tuple u8)) - (type $A17b (tuple $A4)) - - (type $A18b (flags "x")) - - (type $A19b (enum "x")) - - (type $A21a (option (tuple u32))) - (type $A21b (option $A6)) - - (type $A22a (result)) - (type $A22b (result $A7)) - (type $A22c (result (error $A8))) - (type $A22d (result $A9 (error $A10a))) -) - -(assert_malformed - (component quote - "(type $t string)" - "(type $v (variant (case $x \"x\" $t) (case $x \"y\" $t)))" - ) - "duplicate variant case identifier" -) - -(assert_invalid - (component - (type $t (func)) - (type (func (param "t" $t))) - ) - "type index 0 is not a defined type") - -(assert_invalid - (component - (type $t (instance)) - (type (func (result $t))) - ) - "type index 0 is not a defined type") - -(assert_invalid - (component - (type $t (component)) - (type (option $t)) - ) - "type index 0 is not a defined type") - -(assert_invalid - (component (type (option 0))) - "index out of bounds") -(assert_invalid - (component (type (list 0))) - "index out of bounds") -(assert_invalid - (component (type (record (field "x" 0)))) - "index out of bounds") -(assert_invalid - (component (type (variant (case "x" 0)))) - "index out of bounds") -(assert_invalid - (component (type (result 0 (error 1)))) - "index out of bounds") -(assert_invalid - (component (type (tuple 0))) - "index out of bounds") - -(assert_invalid - (component (type (record (field "a-B-c-D" string) (field "A-b-C-d" u8)))) - "record field name `A-b-C-d` conflicts with previous field name `a-B-c-D`") -(assert_invalid - (component (type (variant (case "x" s64) (case "x" s64)))) - "variant case name `x` conflicts with previous case name `x`") -(assert_invalid - (component (type (flags "x" "y" "X"))) - "flag name `X` conflicts with previous flag name `x`") -(assert_invalid - (component (type (enum "x" "y" "X"))) - "enum tag name `X` conflicts with previous tag name `x`") - -(assert_invalid - (component (type (record (field "" s32)))) - "name cannot be empty") -(assert_invalid - (component (type (variant (case "" s32)))) - "name cannot be empty") -(assert_invalid - (component (type (flags ""))) - "name cannot be empty") -(assert_invalid - (component (type (enum ""))) - "name cannot be empty") - -(assert_invalid - (component (type (variant))) - "variant type must have at least one case") diff --git a/test/wasm-tools/empty.wast b/test/wasm-tools/empty.wast deleted file mode 100644 index 7f22181b..00000000 --- a/test/wasm-tools/empty.wast +++ /dev/null @@ -1,4 +0,0 @@ -;; RUN: wast --assert default --snapshot tests/snapshots % - -;; The most minimal component. -(component) diff --git a/test/wasm-tools/example.wast b/test/wasm-tools/example.wast deleted file mode 100644 index 9ba429fe..00000000 --- a/test/wasm-tools/example.wast +++ /dev/null @@ -1,17 +0,0 @@ -;; RUN: wast --assert default --snapshot tests/snapshots % - -;; With what's defined so far, we can define the following component: - -(component - (component - (core module (func (export "one") (result i32) (i32.const 1))) - (core module (func (export "two") (result f32) (f32.const 2))) - ) - (core module (func (export "three") (result i64) (i64.const 3))) - (component - (component - (core module (func (export "four") (result f64) (f64.const 4))) - ) - ) - (component) -) diff --git a/test/wasm-tools/export-ascription.wast b/test/wasm-tools/export-ascription.wast deleted file mode 100644 index ca70736e..00000000 --- a/test/wasm-tools/export-ascription.wast +++ /dev/null @@ -1,44 +0,0 @@ -;; RUN: wast --assert default --snapshot tests/snapshots % - -(component - (component - (import "f" (func $f)) - (export "f2" (func $f) (func)) - ) -) - -;; subtyping works -(component - (component - (import "f" (instance $i (export "f" (func)))) - (export "f2" (instance $i) (instance)) - ) -) - -;; make sure subtyping works in the right direction -(assert_invalid - (component - (import "f" (instance $i)) - (export "f2" (instance $i) (instance (export "f" (func)))) - ) - "ascribed type of export is not compatible") - -;; make sure the type is actually changed -(assert_invalid - (component - (import "f" (func $f)) - - (component $c - (import "f" (instance $i (export "f" (func)))) - (export "f2" (instance $i) (instance)) - ) - - (instance $c (instantiate $c (with "f" (instance (export "f" (func $f)))))) - - (component $consume - (import "arg" (instance $i (export "f" (func)))) - ) - - (instance (instantiate $consume (with "arg" (instance $c "f2")))) - ) - "missing expected export `f`") diff --git a/test/wasm-tools/export-introduces-alias.wast b/test/wasm-tools/export-introduces-alias.wast deleted file mode 100644 index 40d33efa..00000000 --- a/test/wasm-tools/export-introduces-alias.wast +++ /dev/null @@ -1,48 +0,0 @@ -;; RUN: wast --assert default --snapshot tests/snapshots % - -(component - (component - (import "x" (func $f)) - - (export $g "g" (func $f)) - (export $g2 "g2" (func $g)) - ) -) - -(component - (type (component - (type $t u8) - (import "x" (instance $i (export "t" (type (eq $t))))) - (alias export $i "t" (type $my-t)) - )) -) - -(component - (type (component - (type $t u8) - (import "x" (instance $i - (export "i" (instance - (export "t" (type (eq $t))) - )) - )) - (alias export $i "i" (instance $my-i)) - (alias export $my-i "t" (type $my-t)) - )) -) - -(assert_malformed - (component quote - "(type (instance" - "(type $t u8)" - "(export \"t\" (type $t (eq $t)))" - "))" - ) - "duplicate type identifier") - -(component - (type (instance - (type $t u8) - (export "t" (type $t2 (eq $t))) - (export "t2" (type $t3 (eq $t2))) - )) -) diff --git a/test/wasm-tools/export.wast b/test/wasm-tools/export.wast deleted file mode 100644 index 73d094c8..00000000 --- a/test/wasm-tools/export.wast +++ /dev/null @@ -1,63 +0,0 @@ -;; RUN: wast --assert default --snapshot tests/snapshots % - -(assert_invalid - (component (export "" (instance 0))) - "index out of bounds") - -(assert_invalid - (component (export "" (component 0))) - "index out of bounds") - -(assert_invalid - (component (export "" (core module 0))) - "index out of bounds") - -(assert_invalid - (component (export "" (func 0))) - "index out of bounds") - -(component - (component - (import "a" (instance $i)) - (import "b" (core module $m)) - (import "c" (component $c)) - (import "e" (func $f)) - - (export "f" (instance $i)) - (export "g" (core module $m)) - (export "h" (component $c)) - (export "j" (func $f)) - ) -) - -(component - (component - (import "a" (func)) - (export (interface "wasi:http/types@2.0.0") (func 0)) - ) -) - -;; import/exports can overlap on ids -(component - (component - (import (interface "wasi:http/types@2.0.0") (func)) - (export (interface "wasi:http/types@2.0.0") (func 0)) - ) -) - -;; cannot export some types of strings -(assert_invalid - (component (type (component (export "integrity=" (func))))) - "not a valid export name") -(assert_invalid - (component (type (component (export "url=" (func))))) - "not a valid export name") -(assert_invalid - (component (type (component (export "relative-url=" (func))))) - "not a valid extern name") -(assert_invalid - (component (type (component (export "locked-dep=" (func))))) - "not a valid export name") -(assert_invalid - (component (type (component (export "unlocked-dep=" (func))))) - "not a valid export name") diff --git a/test/wasm-tools/func.wast b/test/wasm-tools/func.wast deleted file mode 100644 index 55ccca69..00000000 --- a/test/wasm-tools/func.wast +++ /dev/null @@ -1,146 +0,0 @@ -;; RUN: wast --assert default --snapshot tests/snapshots % - -(component definition - (import "a" (func (param "foo" string))) - (import "b" (func (param "foo" string) (param "bar" s32) (param "baz" u32))) - (import "c" (func (result (tuple u8)))) -) - -(component definition - (import "a" (func)) - (import "b" (func (param "p1" string))) - (import "c" (func (result u32))) - (import "d" (func (param "p1" bool) (result string))) -) - - -(assert_invalid - (component - (type (func (param "foo" string) (param "FOO" u32))) - ) - "function parameter name `FOO` conflicts with previous parameter name `foo`" -) - -(assert_invalid - (component - (core module $m - (memory (export "memory") 1) - (func (export "foo") (result i32) unreachable) - ) - (core instance $i (instantiate $m)) - - (func (export "tuple") (result (tuple s8 u8)) - (canon lift (core func $i "foo")) - ) - ) - "canonical option `memory` is required" -) - -(component definition - (import "a" (func $log (param "msg" string))) - (core module $libc - (memory (export "memory") 1) - ) - (core instance $libc (instantiate $libc)) - (core func (canon lower (func $log) (memory (core memory $libc "memory")))) -) - -(component - (core module $m - (memory (export "memory") 1) - (func (export "ret-list") (result i32) unreachable) - ) - (core instance $i (instantiate $m)) - - (func (export "ret-list") (result (list u8)) - (canon lift (core func $i "ret-list") (memory (core memory $i "memory"))) - ) -) - -(component - (type $big (func - (param "p1" u32) (param "p2" u32) (param "p3" u32) (param "p4" u32) (param "p5" u32) - (param "p6" u32) (param "p7" u32) (param "p8" u32) (param "p9" u32) (param "p10" u32) - (param "p11" u32) (param "p12" u32) (param "p13" u32) (param "p14" u32) (param "p15" u32) - (param "p16" u32) (param "p17" u32) (param "p18" u32) (param "p19" u32) (param "p20" u32) - )) - - (component $c - (import "big" (func $big (type $big))) - (core module $libc (memory (export "memory") 1)) - (core instance $libc (instantiate $libc)) - (core func $big (canon lower (func $big) (memory (core memory $libc "memory")))) - ) -) - -(assert_invalid - (component - (core module $m - (memory (export "memory") 1) - (func (export "roundtrip") (param i32)) - ) - (core instance $m (instantiate $m)) - - (type $roundtrip (func - (param "p1" u32) (param "p2" u32) (param "p3" u32) (param "p4" u32) (param "p5" u32) - (param "p6" u32) (param "p7" u32) (param "p8" u32) (param "p9" u32) (param "p10" u32) - (param "p11" u32) (param "p12" u32) (param "p13" u32) (param "p14" u32) (param "p15" u32) - (param "p16" u32) (param "p17" u32) (param "p18" u32) (param "p19" u32) (param "p20" u32) - )) - - (func $roundtrip (type $roundtrip) - (canon lift (core func $m "roundtrip") (memory (core memory $m "memory"))) - ) - (export "roundtrip" (func $roundtrip)) - ) - "canonical option `realloc` is required" -) - -(assert_invalid - (component - (import "a" (func $log (result string))) - (core module $libc - (memory (export "memory") 1) - ) - (core instance $libc (instantiate $libc)) - (core func (canon lower (func $log) (memory (core memory $libc "memory")))) - ) - "canonical option `realloc` is required" -) - -(assert_invalid - (component - (core module $m - (memory (export "memory") 1) - (func (export "param-list") (param i32 i32) unreachable) - ) - (core instance $i (instantiate $m)) - - (func (export "param-list") (param "bytes" (list u8)) - (canon lift (core func $i "param-list") (memory (core memory $i "memory"))) - ) - ) - "canonical option `realloc` is required" -) - -(assert_malformed - (component binary - "\00asm" "\0d\00\01\00" ;; component header - "\07\05" ;; component type section, 5 bytes - "\01" ;; 1 count - "\40" ;; component function type - "\00" ;; 0 parameters - "\01\01" ;; invalid result encoding - ) - "invalid leading byte (0x1) for number of results") - -(assert_malformed - (component binary - "\00asm" "\0d\00\01\00" ;; component header - "\07\05" ;; component type section, 5 bytes - "\01" ;; 1 count - "\40" ;; component function type - "\00" ;; 0 parameters - "\02\00" ;; invalid result encoding - ) - "invalid leading byte (0x2) for component function results") diff --git a/test/wasm-tools/import.wast b/test/wasm-tools/import.wast deleted file mode 100644 index b226157e..00000000 --- a/test/wasm-tools/import.wast +++ /dev/null @@ -1,359 +0,0 @@ -;; RUN: wast --assert default --snapshot tests/snapshots % - -(component - (component - (import "a" (func)) - (import "b" (instance)) - (import "c" (instance - (export "a" (func)) - )) - (import "d" (component - (import "a" (core module)) - (export "b" (func)) - )) - (type $t (func)) - (import "e" (type (eq $t))) - ) -) - -(assert_invalid - (component - (type $f (func)) - (import "a" (instance (type $f))) - ) - "type index 0 is not an instance type") - -(assert_invalid - (component - (core type $f (func)) - (import "a" (core module (type $f))) - ) - "core type index 0 is not a module type") - -(assert_invalid - (component - (type $f string) - (import "a" (func (type $f))) - ) - "type index 0 is not a function type") - -;; Disallow duplicate imports for core wasm modules -(assert_invalid - (component - (core type (module - (import "" "" (func)) - (import "" "" (func)) - )) - ) - "duplicate import name `:`") -(assert_invalid - (component - (core module - (import "" "" (func)) - (import "" "" (func)) - ) - ) - "duplicate import name `:`") -(assert_invalid - (component - (core type (module - (import "" "a" (func)) - (import "" "a" (func)) - )) - ) - "duplicate import name `:a`") -(assert_invalid - (component - (core module - (import "" "a" (func)) - (import "" "a" (func)) - ) - ) - "duplicate import name `:a`") - -(assert_invalid - (component - (import "a" (func)) - (import "a" (func)) - ) - "import name `a` conflicts with previous name `a`") - -(assert_invalid - (component - (type (component - (import "a" (func)) - (import "a" (func)) - )) - ) - "import name `a` conflicts with previous name `a`") - -(assert_invalid - (component - (import "a" (func (type 100))) - ) - "type index out of bounds") - -(assert_invalid - (component - (core module $m (func (export ""))) - (core instance $i (instantiate $m)) - (func (type 100) (canon lift (core func $i ""))) - ) - "type index out of bounds") - -(component definition - (import "wasi:http/types" (func)) - (import "wasi:http/types@1.0.0" (func)) - (import "wasi:http/types@2.0.0" (func)) - (import "a-b:c-d/e-f@123456.7890.488" (func)) - (import "a:b/c@1.2.3" (func)) - (import "a:b/c@0.0.0" (func)) - (import "a:b/c@0.0.0+abcd" (func)) - (import "a:b/c@0.0.0+abcd-efg" (func)) - (import "a:b/c@0.0.0-abcd+efg" (func)) - (import "a:b/c@0.0.0-abcd.1.2+efg.4.ee.5" (func)) -) - -(assert_invalid - (component - (import "wasi:http/types" (func)) - (import "wasi:http/types" (func)) - ) - "conflicts with previous name") - -(assert_invalid - (component (import "" (func))) - "`` is not in kebab case") -(assert_invalid - (component (import "wasi:" (func))) - "`` is not in kebab case") -(assert_invalid - (component (import "wasi:/" (func))) - "not in kebab case") -(assert_invalid - (component (import ":/" (func))) - "not in kebab case") -(assert_invalid - (component (import "wasi/http" (func))) - "`wasi/http` is not in kebab case") -(assert_invalid - (component (import "wasi:http/TyPeS" (func))) - "`TyPeS` is not in kebab case") -(assert_invalid - (component (import "WaSi:http/types" (func))) - "`WaSi` is not in kebab case") -(assert_invalid - (component (import "wasi:HtTp/types" (func))) - "`HtTp` is not in kebab case") -(assert_invalid - (component (import "wasi:http/types@" (func))) - "empty string") -(assert_invalid - (component (import "wasi:http/types@." (func))) - "unexpected character '.'") -(assert_invalid - (component (import "wasi:http/types@1." (func))) - "unexpected end of input") -(assert_invalid - (component (import "wasi:http/types@a.2" (func))) - "unexpected character 'a'") -(assert_invalid - (component (import "wasi:http/types@2.b" (func))) - "unexpected character 'b'") -(assert_invalid - (component (import "wasi:http/types@2.0x0" (func))) - "unexpected character 'x'") -(assert_invalid - (component (import "wasi:http/types@2.0.0+" (func))) - "empty identifier segment") -(assert_invalid - (component (import "wasi:http/types@2.0.0-" (func))) - "empty identifier segment") -(assert_invalid - (component (import "foo:bar:baz/qux" (func))) - "expected `/` after package name") -(assert_invalid - (component (import "foo:bar/baz/qux" (func))) - "trailing characters found: `/qux`") - -(component - (component - (import "a" (func $a)) - (export "a" (func $a)) - ) -) - -(component definition - (import "unlocked-dep=" (func)) - (import "unlocked-dep=" (func)) - (import "unlocked-dep==1.2.3}>" (func)) - (import "unlocked-dep==1.2.3-rc}>" (func)) - (import "unlocked-dep=" (func)) - (import "unlocked-dep=" (func)) - (import "unlocked-dep==1.2.3 <1.2.3}>" (func)) - (import "unlocked-dep==1.2.3-rc <1.2.3}>" (func)) -) - -(assert_invalid - (component (import "unlocked-dep=" (func))) - "expected `<` at ``") -(assert_invalid - (component (import "unlocked-dep=<" (func))) - "`` is not in kebab case") -(assert_invalid - (component (import "unlocked-dep=<>" (func))) - "`` is not in kebab case") -(assert_invalid - (component (import "unlocked-dep=<:>" (func))) - "`` is not in kebab case") -(assert_invalid - (component (import "unlocked-dep=" (func))) - "`` is not in kebab case") -(assert_invalid - (component (import "unlocked-dep=<:a>" (func))) - "`` is not in kebab case") -(assert_invalid - (component (import "unlocked-dep=" (func))) - "expected `{` at `>`") -(assert_invalid - (component (import "unlocked-dep=" (func))) - "expected `>=` or `<` at start of version range") -(assert_invalid - (component (import "unlocked-dep=" (func))) - "`xyz` is not a valid semver") -(assert_invalid - (component (import "unlocked-dep==2.3.4}>" (func))) - "`1.2.3 >=2.3.4` is not a valid semver") - -(component definition - (import "locked-dep=" (func)) - (import "locked-dep=" (func)) - (import "locked-dep=,integrity=" (func)) - (import "locked-dep=,integrity=" (func)) -) - -(assert_invalid - (component (import "locked-dep=" (func))) - "expected `<` at ``") -(assert_invalid - (component (import "locked-dep=<" (func))) - "`` is not in kebab case") -(assert_invalid - (component (import "locked-dep=<:" (func))) - "`` is not in kebab case") -(assert_invalid - (component (import "locked-dep=<:>" (func))) - "`` is not in kebab case") -(assert_invalid - (component (import "locked-dep=" (func))) - "`` is not in kebab case") -(assert_invalid - (component (import "locked-dep=<:a>" (func))) - "`` is not in kebab case") -(assert_invalid - (component (import "locked-dep=` at ``") -(assert_invalid - (component (import "locked-dep=" (func))) - "is not a valid semver") -(assert_invalid - (component (import "locked-dep=` at ``") -(assert_invalid - (component (import "locked-dep=," (func))) - "expected `integrity=<`") -(assert_invalid - (component (import "locked-dep=x" (func))) - "trailing characters found: `x`") - -(component definition - (import "url=<>" (func)) - (import "url=" (func)) - (import "url=,integrity=" (func)) -) - -(assert_invalid - (component (import "url=" (func))) - "expected `<` at ``") -(assert_invalid - (component (import "url=<" (func))) - "failed to find `>`") -(assert_invalid - (component (import "url=<<>" (func))) - "url cannot contain `<`") - -(assert_invalid - (component - (import "relative-url=<>" (func)) - (import "relative-url=" (func)) - (import "relative-url=,integrity=" (func)) - ) - "not a valid extern name") - -(assert_invalid - (component (import "relative-url=" (func))) - "not a valid extern name") -(assert_invalid - (component (import "relative-url=<" (func))) - "not a valid extern name") -(assert_invalid - (component (import "relative-url=<<>" (func))) - "not a valid extern name") - -(component definition - (import "integrity=" (func)) - (import "integrity=" (func)) - (import "integrity=" (func)) - (import "integrity=" (func)) - (import "integrity=< sha512-a sha256-b >" (func)) - (import "integrity=< sha512-a?abcd >" (func)) - (import "integrity=" (func)) - (import "integrity=" (func)) - (import "integrity=" (func)) - (import "integrity=" (func)) -) -(assert_invalid - (component (import "integrity=<>" (func))) - "integrity hash cannot be empty") -(assert_invalid - (component (import "integrity=" (func))) - "expected `-` after hash algorithm") -(assert_invalid - (component (import "integrity=" (func))) - "not valid base64") -(assert_invalid - (component (import "integrity=" (func))) - "not valid base64") -(assert_invalid - (component (import "integrity=" (func))) - "not valid base64") -(assert_invalid - (component (import "integrity=" (func))) - "not valid base64") -(assert_invalid - (component (import "integrity=" (func))) - "not valid base64") -(assert_invalid - (component (import "integrity=" (func))) - "unrecognized hash algorithm") - -;; Prior to WebAssembly/component-model#263 this was a valid component. -;; Specifically the 0x01 prefix byte on the import was valid. Nowadays that's -;; not valid in the spec but it's accepted for backwards compatibility. This -;; tests is here to ensure such compatibility. In the future this test should -;; be changed to `(assert_invalid ...)` -(component definition binary - "\00asm" "\0d\00\01\00" ;; component header - - "\07\05" ;; type section, 5 bytes large - "\01" ;; 1 count - "\40" ;; function - "\00" ;; parameters, 0 count - "\01\00" ;; results, named, 0 count - - "\0a\06" ;; import section, 6 bytes large - "\01" ;; 1 count - "\01" ;; prefix byte of 0x01 (invalid by the spec nowadays) - "\01a" ;; name = "a" - "\01\00" ;; type = func ($type 0) -) diff --git a/test/wasm-tools/imports-exports.wast b/test/wasm-tools/imports-exports.wast deleted file mode 100644 index e650c8c8..00000000 --- a/test/wasm-tools/imports-exports.wast +++ /dev/null @@ -1,26 +0,0 @@ -;; RUN: wast --assert default --snapshot tests/snapshots % - -;; With what's defined so far, we can define a component that imports, links and exports other components: - -(component - (component - (import "c" (instance $c - (export "f" (func (result string))) - )) - (import "d" (component $D - (import "c" (instance $c - (export "f" (func (result string))) - )) - (export "g" (func (result string))) - )) - (instance $d1 (instantiate $D - (with "c" (instance $c)) - )) - (instance $d2 (instantiate $D - (with "c" (instance - (export "f" (func $d1 "g")) - )) - )) - (export "d2" (instance $d2)) - ) -) diff --git a/test/wasm-tools/inline-exports.wast b/test/wasm-tools/inline-exports.wast deleted file mode 100644 index 2c3ff567..00000000 --- a/test/wasm-tools/inline-exports.wast +++ /dev/null @@ -1,9 +0,0 @@ -;; RUN: wast --assert default --snapshot tests/snapshots % - -(component - (type (export "foo") u8) -) - -(assert_malformed - (component quote "(type (component (type (export \"\") (func))))") - "unexpected token") diff --git a/test/wasm-tools/instance-type.wast b/test/wasm-tools/instance-type.wast deleted file mode 100644 index 2f4b1404..00000000 --- a/test/wasm-tools/instance-type.wast +++ /dev/null @@ -1,234 +0,0 @@ -;; RUN: wast --assert default --snapshot tests/snapshots % - -;; instances -(component - (type (instance)) - - (type $foo (func)) - - (type $t (func (result string))) - - (core type (module - (type $local_type (func)) - ;; functions - (export "a" (func)) - (export "b" (func $foo)) - (export "c" (func)) - (export "d" (func $foo)) - (export "e" (func (type $local_type))) - (export "f" (func (param i32))) - (export "g" (func (param i32) (result i32 i64))) - (export "h" (func (type $local_type) (result i32))) - - ;; globals - (export "i" (global i32)) - (export "j" (global $foo i32)) - (export "k" (global (mut i32))) - - ;; tables - (export "l" (table 1 funcref)) - (export "m" (table $foo 1 funcref)) - - ;; memory - (export "n" (memory 1)) - (export "o" (memory $foo 1)) - (export "p" (memory 1 2)) - (export "q" (memory 1 2 shared)) - )) - - (type $outer (instance - (type $local_type (func)) - ;; functions - (export "a" (func)) - (export "a2" (func (type $local_type))) - (export "b" (func)) - (export "c" (func)) - (export "d" (func)) - (export "e" (func (type $t))) - (export "f" (func (param "f" string))) - (export "g" (func (param "g" s32) (result u32))) - (export "h" (func (type $t))) - - ;; components - (type $component_type (component)) - (export "c1" (component)) - (export "c2" (component (import "i1" (func)))) - (export "c3" (component (export "e1" (func)))) - (export "c4" (component (type $component_type))) - (export "c5" (component - (type $nested_func_type (func)) - (alias outer $outer $local_type (type $my_type)) - (import "i1" (func (type $nested_func_type))) - (import "i2" (component)) - (export "e1" (func (type $my_type))) - (export "e2" (component)) - )) - )) -) - -;; expand inline types -(component - (type (instance (export "a" (instance)))) -) - -;; reference outer types -(component - (type (instance - (type $t (instance)) - (export "a" (instance (type $t))) - )) - (type $x (instance)) - (type (instance (export "a" (instance (type $x))))) -) - -;; recursive -(component - (type (instance (export "a" (core module - (type $functype (func)) - - (export "a" (func)) - (export "b" (func (type 0))) - (export "c" (func (param i32))) - (export "d" (func (type $functype))) - - ;; globals - (export "e" (global i32)) - (export "f" (global (mut i32))) - - ;; tables - (export "g" (table 1 funcref)) - - ;; memory - (export "h" (memory 1)) - (export "i" (memory 1 2)) - (export "j" (memory 1 2 shared)) - )))) -) - -;; modules -(component - (core type (module)) - - (core type $foo (module)) - - (type $empty (func)) - (type $i (instance)) - - (core type (module - (type $empty (func)) - (import "" "a" (func)) - (import "" "b" (func (type $empty))) - (import "" "c" (func (param i32))) - (import "" "d" (func (param i32) (result i32))) - - (import "" "e" (global i32)) - (import "" "f" (memory 1)) - (import "" "g" (table 1 funcref)) - - (export "a" (func)) - (export "b" (global i32)) - (export "c" (memory 1)) - (export "d" (table 1 funcref)) - - (export "e" (func (type $empty))) - (export "f" (func (param i32))) - )) - - (type (component - (import "a" (func)) - (import "b" (func (type $empty))) - (import "c" (func (param "c" s32))) - (import "d" (func (param "d" s32) (result s32))) - - (import "h" (instance)) - (import "i" (instance (type $i))) - (import "j" (instance - (export "a" (func)) - (export "b" (func (type $empty))) - (export "c" (func (param "c" s32))) - )) - - (import "k" (core module)) - (import "l" (core module - (type $empty (func)) - (import "" "a" (func (type $empty))) - (import "" "b" (func (param i32))) - (export "a" (func (type $empty))) - (export "b" (func (param i32))) - )) - - (export "m" (func)) - (export "n" (func (type $empty))) - (export "o" (func (param "f" s32))) - - (export "p" (instance - (export "a" (func)) - (export "b" (func (type $empty))) - (export "c" (func (param "c" s32))) - )) - - (export "q" (core module - (type $empty (func)) - (import "" "a" (func (type $empty))) - (import "" "b" (func (param i32))) - (export "a" (func (type $empty))) - (export "b" (func (param i32))) - )) - )) -) - -(assert_invalid - (component - (type (instance - (export "a" (func)) - (export "a" (func))))) - "export name `a` conflicts with previous name `a`") - -(assert_invalid - (component - (type $t (func)) - (type (instance - (export "a" (instance (type $t))) - ))) - "type index 0 is not an instance type") - -(assert_invalid - (component - (core type $t (func)) - (type (instance - (export "a" (core module (type $t))) - ))) - "core type index 0 is not a module type") - -(assert_malformed - (component quote - "(type $t (func))" - "(type (instance (export \"a\" (core module (type $t)))))" - ) - "unknown core type") - -(assert_invalid - (component - (type $t (record (field "a" string))) - (type (instance - (export "a" (func (type $t))) - ))) - "type index 0 is not a function type") - -(assert_invalid - (component - (type $t (instance)) - (type (instance - (export "a" (func (type $t))) - ))) - "type index 0 is not a function type") - -(assert_invalid - (component - (type $t (instance)) - (type (instance - (export "a" (instance - (export "a" (func (type $t))) - )) - ))) - "type index 0 is not a function type") diff --git a/test/wasm-tools/instantiate.wast b/test/wasm-tools/instantiate.wast deleted file mode 100644 index cb992394..00000000 --- a/test/wasm-tools/instantiate.wast +++ /dev/null @@ -1,976 +0,0 @@ -;; RUN: wast --assert default --snapshot tests/snapshots % - -(component definition - (import "a" (core module $m)) - (core instance $a (instantiate $m)) -) - -(component - (component - (import "a" (func $i)) - (import "b" (component $c (import "a" (func)))) - (instance (instantiate $c (with "a" (func $i)))) - ) -) - -(component - (component - (import "a" (component $i)) - (import "b" (component $c (import "a" (component)))) - (instance (instantiate $c (with "a" (component $i)))) - ) -) - -(component - (component - (import "a" (core module $i)) - (import "b" (component $c (import "a" (core module)))) - (instance (instantiate $c (with "a" (core module $i)))) - ) -) - -(component - (component - (import "a" (instance $i)) - (import "b" (component $c (import "a" (instance)))) - (instance (instantiate $c (with "a" (instance $i)))) - ) -) - -(component definition - (import "a" (core module $m - (import "" "a" (func)) - (import "" "b" (global i32)) - (import "" "c" (table 1 funcref)) - (import "" "d" (memory 1)) - )) - (import "b" (core module $m2 - (export "a" (func)) - (export "b" (global i32)) - (export "c" (table 1 funcref)) - (export "d" (memory 1)) - )) - (core instance $x (instantiate $m2)) - (core instance (instantiate $m (with "" (instance $x)))) -) - -(component definition - (import "a" (core module $m - (import "" "d" (func)) - (import "" "c" (global i32)) - (import "" "b" (table 1 funcref)) - (import "" "a" (memory 1)) - )) - (import "b" (core module $m2 - (export "a" (func)) - (export "b" (global i32)) - (export "c" (table 1 funcref)) - (export "d" (memory 1)) - )) - (core instance $x (instantiate $m2)) - - (core instance (instantiate $m (with "" (instance - (export "d" (func $x "a")) - (export "c" (global $x "b")) - (export "b" (table $x "c")) - (export "a" (memory $x "d")) - )))) -) - -(component - (component - (import "a" (component $m - (import "a" (instance - (export "a" (core module)) - )) - )) - (import "b" (component $m2 - (export "b" (core module)) - )) - (instance $x (instantiate $m2)) - - (instance (instantiate $m (with "a" (instance - (export "a" (core module $x "b")) - )))) - ) -) - -(component - (component - (import "a" (component $c - (import "a" (core module)) - (import "b" (func)) - (import "c" (component)) - (import "d" (instance)) - )) - (core module $m (import "b")) - (func $f (import "c")) - (component $c2 (import "d")) - (instance $i (import "e")) - - (instance - (instantiate $c - (with "a" (core module $m)) - (with "b" (func $f)) - (with "c" (component $c2)) - (with "d" (instance $i)) - ) - ) - - (core instance $c (instantiate $m)) - (core instance (instantiate $m)) - - ;; inline exports/imports - (type $empty (instance)) - (instance $d (import "g") (type $empty)) - (instance (import "h")) - (instance (import "i") - (export "x" (func))) - (instance (export "j") (export "k") (import "x")) - ) -) - -(assert_invalid - (component - (core instance (instantiate 0)) - ) - "unknown module") -(assert_invalid - (component - (instance (instantiate 0)) - ) - "unknown component") -(assert_invalid - (component - (import "a" (core module)) - (core instance (instantiate 1)) - ) - "unknown module") - -(component - (component - (import "a" (func $f)) - (import "b" (component $c)) - (instance (instantiate $c (with "a" (func $f)))) - ) -) -(assert_invalid - (component - (import "a" (core module $m (import "" "" (func)))) - (core instance (instantiate $m)) - ) - "missing module instantiation argument") -(assert_invalid - (component - (import "a" (component $m (import "a" (func)))) - (instance (instantiate $m)) - ) - "missing import named `a`") - -(assert_invalid - (component - (import "a" (component $m - (import "a" (func)) - )) - (import "b" (component $c)) - (instance $i (instantiate $m (with "a" (component $c)))) - ) - "expected func, found component") - -(assert_invalid - (component - (import "a" (component $m - (import "a" (func)) - )) - (import "b" (func $f (result string))) - (instance $i (instantiate $m (with "a" (func $f)))) - ) - "expected a result, found none") - -(assert_invalid - (component - (import "a" (component $m - (import "a" (func)) - )) - (import "b" (func (param "i" string))) - (instance $i (instantiate $m (with "a" (func 0)))) - ) - "expected 0 parameters, found 1") - -(assert_invalid - (component - (import "a" (component $m - (import "a" (core module - (import "" "" (func)) - )) - )) - (import "b" (core module $i - (import "" "" (global i32)) - )) - (instance $i (instantiate $m (with "a" (core module $i)))) - ) - "type mismatch in import `::`") - -(assert_invalid - (component - (import "a" (component $m - (import "a" (core module)) - )) - (import "b" (core module $i - (import "" "foobar" (global i32)) - )) - (instance $i (instantiate $m (with "a" (core module $i)))) - ) - "missing expected import `::foobar`") -(assert_invalid - (component - (import "a" (component $m - (import "a" (core module (export "x" (func)))) - )) - (import "b" (core module $i)) - (instance $i (instantiate $m (with "a" (core module $i)))) - ) - "missing expected export `x`") - -;; it's ok to give a module with fewer imports -(component - (component - (import "a" (component $m - (import "a" (core module - (import "" "" (global i32)) - (import "" "f" (func)) - )) - )) - (import "b" (core module $i - (import "" "" (global i32)) - )) - (instance $i (instantiate $m (with "a" (core module $i)))) - ) -) - -;; export subsets -(component - (component - (import "a" (component $m - (import "a" (core module - (export "" (func)) - )) - )) - (import "b" (core module $i - (export "" (func)) - (export "a" (func)) - )) - (instance $i (instantiate $m (with "a" (core module $i)))) - ) -) -(component - (component - (import "a" (component $m - (import "a" (instance - (export "a" (func)) - )) - )) - (import "b" (instance $i - (export "a" (func)) - (export "b" (func)) - )) - (instance (instantiate $m (with "a" (instance $i)))) - ) -) - - -;; ============================================================================ -;; core wasm type checking - -(assert_invalid - (component - (import "m1" (core module $m1 (import "" "" (func)))) - (import "m2" (core module $m2 (export "" (func (param i32))))) - (core instance $i (instantiate $m2)) - (core instance (instantiate $m1 (with "" (instance $i)))) - ) - "expected: (func)") -(assert_invalid - (component - (import "m1" (core module $m1 (import "" "" (func)))) - (import "m2" (core module $m2 (export "" (func (result i32))))) - (core instance $i (instantiate $m2)) - (core instance (instantiate $m1 (with "" (instance $i)))) - ) - "expected: (func)") -(assert_invalid - (component - (import "m1" (core module $m1 (import "" "" (global i32)))) - (import "m2" (core module $m2 (export "" (global i64)))) - (core instance $i (instantiate $m2)) - (core instance (instantiate $m1 (with "" (instance $i)))) - ) - "expected global type i32, found i64") -(assert_invalid - (component - (import "m1" (core module $m1 (import "" "" (table 1 funcref)))) - (import "m2" (core module $m2 (export "" (table 2 externref)))) - (core instance $i (instantiate $m2)) - (core instance (instantiate $m1 (with "" (instance $i)))) - ) - "expected table element type funcref, found externref") -(assert_invalid - (component - (import "m1" (core module $m1 (import "" "" (table 1 2 funcref)))) - (import "m2" (core module $m2 (export "" (table 2 funcref)))) - (core instance $i (instantiate $m2)) - (core instance (instantiate $m1 (with "" (instance $i)))) - ) - "mismatch in table limits") -(assert_invalid - (component - (import "m1" (core module $m1 (import "" "" (table 2 2 funcref)))) - (import "m2" (core module $m2 (export "" (table 1 funcref)))) - (core instance $i (instantiate $m2)) - (core instance (instantiate $m1 (with "" (instance $i)))) - ) - "mismatch in table limits") -(assert_invalid - (component - (import "m1" (core module $m1 (import "" "" (table 2 2 funcref)))) - (import "m2" (core module $m2 (export "" (table 2 3 funcref)))) - (core instance $i (instantiate $m2)) - (core instance (instantiate $m1 (with "" (instance $i)))) - ) - "mismatch in table limits") -(assert_invalid - (component - (import "m1" (core module $m1 (import "" "" (memory 1 2 shared)))) - (import "m2" (core module $m2 (export "" (memory 1)))) - (core instance $i (instantiate $m2)) - (core instance (instantiate $m1 (with "" (instance $i)))) - ) - "mismatch in the shared flag for memories") -(assert_invalid - (component - (import "m1" (core module $m1 (import "" "" (memory 1)))) - (import "m2" (core module $m2 (export "" (memory 0)))) - (core instance $i (instantiate $m2)) - (core instance (instantiate $m1 (with "" (instance $i)))) - ) - "mismatch in memory limits") -(assert_invalid - (component - (import "m1" (core module $m1 (export "g" (func)))) - (component $c - (import "m" (core module (export "g" (global i32)))) - ) - (instance (instantiate $c (with "m" (core module $m1)))) - ) - "type mismatch in export `g`") - -(assert_invalid - (component - (core instance (instantiate 0)) - ) - "unknown module") - -(component - (component $m - (core module $sub (export "module") - (func $f (export "") (result i32) - i32.const 5)) - ) - (instance $a (instantiate $m)) - (alias export $a "module" (core module $sub)) - (core instance $b (instantiate $sub)) - - (core module $final - (import "" "" (func $b (result i32))) - (func (export "get") (result i32) - call $b)) - - (core instance (instantiate $final (with "" (instance $b)))) -) - -(assert_invalid - (component (instance $i (export "" (func 0)))) - "function index out of bounds") - -(assert_invalid - (component (instance (export "" (instance 0)))) - "index out of bounds") - -(assert_invalid - (component (instance $i (export "" (component 0)))) - "index out of bounds") - -(assert_invalid - (component (instance (export "" (instance 0)))) - "index out of bounds") - -(assert_invalid - (component (instance $i (export "" (core module 0)))) - "index out of bounds") - -(assert_invalid - (component (core instance (export "" (func 0)))) - "index out of bounds") - -(assert_invalid - (component (core instance (export "" (table 0)))) - "index out of bounds") - -(assert_invalid - (component (core instance (export "" (global 0)))) - "index out of bounds") - -(assert_invalid - (component (core instance (export "" (memory 0)))) - "index out of bounds") - -(assert_invalid - (component - (core module $m) - (core instance $i (instantiate $m)) - (core instance (instantiate $m - (with "" (instance $i)) - (with "" (instance $i)) - )) - ) - "duplicate module instantiation argument named ``" -) - -(assert_invalid - (component - (core module $m (func (export ""))) - (core instance $i (instantiate $m)) - (core instance (instantiate $m - (with "" (instance $i)) - (with "" (instance $i)) - )) - ) - "duplicate module instantiation argument named ``") - -(assert_invalid - (component - (core module $m1 (func (export ""))) - (core module $m2 (import "" "" (global i32))) - (core instance $i (instantiate $m1)) - (core instance (instantiate $m2 - (with "" (instance $i)) - )) - ) - "expected global, found func") - -(assert_invalid - (component - (component $m) - (instance $i (instantiate $m)) - (instance (instantiate $m - (with "a" (instance $i)) - (with "a" (instance $i)) - )) - ) - "instantiation argument `a` conflicts with previous argument `a`") - -(assert_invalid - (component - (component $c (import "a" (func))) - (instance (instantiate $c - (with "a" (component $c)) - )) - ) - "expected func, found component") - -(assert_invalid - (component - (component $c) - (instance (instantiate $c - (with "" (core module 0)) - )) - ) - "index out of bounds") - -(assert_invalid - (component - (component $c) - (instance (instantiate $c - (with "" (instance 0)) - )) - ) - "index out of bounds") - -(assert_invalid - (component - (component $c) - (instance (instantiate $c - (with "" (func 0)) - )) - ) - "index out of bounds") - -(assert_invalid - (component - (component $c) - (instance (instantiate $c - (with "" (component 100)) - )) - ) - "index out of bounds") - -(assert_invalid - (component - (component $c) - (instance - (export "a" (component $c)) - (export "a" (component $c)) - ) - ) - "export name `a` conflicts with previous name `a`") - -(component - (component - (import "a" (instance $i)) - (import "b" (func $f)) - (import "c" (component $c)) - (import "d" (core module $m)) - (instance - (export "a" (instance $i)) - (export "b" (func $f)) - (export "c" (component $c)) - (export "d" (core module $m)) - ) - ) -) - -(component - (core module $m - (func (export "1")) - (memory (export "2") 1) - (table (export "3") 1 funcref) - (global (export "4") i32 i32.const 0) - ) - (core instance $i (instantiate $m)) - (core instance - (export "a" (func $i "1")) - (export "b" (memory $i "2")) - (export "c" (table $i "3")) - (export "d" (global $i "4")) - ) -) - -(assert_invalid - (component - (core module $m (func (export ""))) - (core instance $i (instantiate $m)) - (core instance - (export "" (func $i "")) - (export "" (func $i "")) - ) - ) - "export name `` already defined") - -(assert_invalid - (component - (component $c) - (instance $i (instantiate $c)) - (export "a" (instance $i "a")) - ) - "no export named `a`") - -(assert_invalid - (component - (export "a" (instance 100 "a")) - ) - "index out of bounds") - -(assert_invalid - (component - (import "a" (core module $libc - (export "memory" (memory 1)) - (export "table" (table 0 funcref)) - (export "func" (func)) - (export "global" (global i32)) - (export "global mut" (global (mut i64))) - )) - (core instance $libc (instantiate $libc)) - (alias core export $libc "memory" (core memory $mem)) - (alias core export $libc "table" (core table $tbl)) - (alias core export $libc "func" (core func $func)) - (alias core export $libc "global" (core global $global)) - (alias core export $libc "global mut" (core global $global_mut)) - - (import "x" (core module $needs_libc - (import "" "memory" (memory 1)) - (import "" "table" (table 0 funcref)) - (import "" "func" (func)) - (import "" "global" (global i32)) - (import "" "global mut" (global (mut i64))) - )) - - (core instance - (instantiate $needs_libc - (with "" (instance (export "memory" (memory $mem)))) - ) - ) - ) - "module instantiation argument `` does not export an item named `table`") - -;; Ensure a type can be an instantiation argument -(component - (type (tuple u32 u32)) - (import "a" (type (eq 0))) - (component - (type (tuple u32 u32)) - (import "a" (type (eq 0))) - ) - (instance (instantiate 0 - (with "a" (type 1)) - ) - ) -) - -(assert_invalid - (component - (type $t (tuple string string)) - (import "a" (type $a (eq $t))) - (component $c - (type $t (tuple u32 u32)) - (import "a" (type (eq $t))) - ) - (instance (instantiate $c - (with "a" (type $a)) - ) - ) - ) - "expected primitive `u32` found primitive `string`") - - -;; subtyping for module imports reverses order of imports/exports for the -;; subtyping check -;; -;; Here `C` imports a module, and the module itself imports a table of min size -;; 1. A module import which imports a min-size table of 0, however, is valid to -;; supply for this since it'll already be given at least 1 anyway. -;; -;; Similarly for exports `C` imports a module that exports a table of at least -;; size 1. If it's given a module that exports a larger table that's ok too. -(component - (core module $a - (import "" "" (table 0 funcref)) - (table (export "x") 2 funcref) - ) - (component $C - (import "a" (core module - (import "" "" (table 1 funcref)) - (export "x" (table 1 funcref)) - )) - ) - (instance (instantiate $C (with "a" (core module $a)))) -) - -;; same as above but for memories -(component - (core module $a1 (import "" "" (memory 0))) - (core module $a2 (memory (export "x") 2)) - (component $C - (import "a1" (core module (import "" "" (memory 1)))) - (import "a2" (core module (export "x" (memory 1)))) - ) - (instance (instantiate $C - (with "a1" (core module $a1)) - (with "a2" (core module $a2)) - )) -) - -(assert_invalid - (component - (import "x" (func $x (param "x" u32))) - (import "y" (component $c - (import "x" (func (param "y" u32))) - )) - - (instance (instantiate $c (with "x" (func $x)))) - ) - "expected parameter named `y`, found `x`") -(assert_invalid - (component - (import "x" (func $x (param "x" u32))) - (import "y" (component $c - (import "x" (func (param "x" s32))) - )) - - (instance (instantiate $c (with "x" (func $x)))) - ) - "type mismatch in function parameter `x`") -(assert_invalid - (component - (import "x" (func $x (result u32))) - (import "y" (component $c - (import "x" (func (result s32))) - )) - - (instance (instantiate $c (with "x" (func $x)))) - ) - "type mismatch with result type") - -(assert_invalid - (component - (import "x" (instance $x (export "a" (func)))) - (import "y" (component $c - (import "x" (instance $x (export "a" (component)))) - )) - - (instance (instantiate $c (with "x" (instance $x)))) - ) - "type mismatch in instance export `a`") - -(assert_invalid - (component - (import "y" (component $c - (type $t u32) - (import "x" (type (eq $t))) - )) - - (type $x (record (field "f" u32))) - (instance (instantiate $c (with "x" (type $x)))) - ) - "expected primitive, found record") - -(assert_invalid - (component - (import "y" (component $c - (type $t (record (field "f" u32))) - (import "x" (type (eq $t))) - )) - - (type $x u32) - (instance (instantiate $c (with "x" (type $x)))) - ) - "expected record, found u32") - -(assert_invalid - (component - (import "y" (component $c - (type $t (record (field "x" u32))) - (import "x" (type (eq $t))) - )) - - (type $f (tuple u8)) - (type $x (record (field "x" $f))) - (instance (instantiate $c (with "x" (type $x)))) - ) - "expected u32, found tuple") - -(assert_invalid - (component - (import "y" (component $c - (type $f (option s32)) - (type $t (record (field "x" $f))) - (import "x" (type (eq $t))) - )) - - (type $x (record (field "x" u32))) - (instance (instantiate $c (with "x" (type $x)))) - ) - "type mismatch in record field `x`") - -(assert_invalid - (component - (import "y" (component $c - (type $t (record (field "x" u32))) - (import "x" (type (eq $t))) - )) - - (type $x (record (field "y" u32) (field "z" u64))) - (instance (instantiate $c (with "x" (type $x)))) - ) - "expected 1 fields, found 2") - -(assert_invalid - (component - (import "y" (component $c - (type $t (record (field "a" u32))) - (import "x" (type (eq $t))) - )) - - (type $x (record (field "b" u32))) - (instance (instantiate $c (with "x" (type $x)))) - ) - "expected field name `a`, found `b`") - -(assert_invalid - (component - (import "y" (component $c - (type $t (variant (case "x" u32))) - (import "x" (type (eq $t))) - )) - - (type $x (variant (case "x" u32) (case "y" u32))) - (instance (instantiate $c (with "x" (type $x)))) - ) - "expected 1 cases, found 2") - -(assert_invalid - (component - (import "y" (component $c - (type $t (variant (case "x" u32))) - (import "x" (type (eq $t))) - )) - - (type $x (variant (case "y" u32))) - (instance (instantiate $c (with "x" (type $x)))) - ) - "expected case named `x`, found `y`") - -(assert_invalid - (component - (import "y" (component $c - (type $t (variant (case "x" u32))) - (import "x" (type (eq $t))) - )) - - (type $x (variant (case "x"))) - (instance (instantiate $c (with "x" (type $x)))) - ) - "expected case `x` to have a type, found none") - -(assert_invalid - (component - (import "y" (component $c - (type $t (variant (case "x"))) - (import "x" (type (eq $t))) - )) - - (type $x (variant (case "x" u32))) - (instance (instantiate $c (with "x" (type $x)))) - ) - "expected case `x` to have no type") - -(assert_invalid - (component - (import "y" (component $c - (type $t (variant (case "x" u32))) - (import "x" (type (eq $t))) - )) - - (type $x (variant (case "x" s32))) - (instance (instantiate $c (with "x" (type $x)))) - ) - "type mismatch in variant case `x`") - -(assert_invalid - (component - (import "y" (component $c - (type $t (tuple u8)) - (import "x" (type (eq $t))) - )) - - (type $x (tuple u32 u32)) - (instance (instantiate $c (with "x" (type $x)))) - ) - "expected 1 types, found 2") - -(assert_invalid - (component - (import "y" (component $c - (type $t (tuple u8)) - (import "x" (type (eq $t))) - )) - - (type $x (tuple u16)) - (instance (instantiate $c (with "x" (type $x)))) - ) - "type mismatch in tuple field 0") - -(assert_invalid - (component - (import "y" (component $c - (type $t (flags "a")) - (import "x" (type (eq $t))) - )) - - (type $x (flags "x")) - (instance (instantiate $c (with "x" (type $x)))) - ) - "mismatch in flags elements") - -(assert_invalid - (component - (import "y" (component $c - (type $t (enum "a")) - (import "x" (type (eq $t))) - )) - - (type $x (enum "x")) - (instance (instantiate $c (with "x" (type $x)))) - ) - "mismatch in enum elements") - -(assert_invalid - (component - (import "y" (component $c - (type $t (result s32)) - (import "x" (type (eq $t))) - )) - - (type $x (result u32)) - (instance (instantiate $c (with "x" (type $x)))) - ) - "type mismatch in ok variant") - -(assert_invalid - (component - (import "y" (component $c - (type $t (result (error s32))) - (import "x" (type (eq $t))) - )) - - (type $x (result (error u32))) - (instance (instantiate $c (with "x" (type $x)))) - ) - "type mismatch in err variant") - -(assert_invalid - (component - (import "y" (component $c - (type $t (result)) - (import "x" (type (eq $t))) - )) - - (type $x (result u32)) - (instance (instantiate $c (with "x" (type $x)))) - ) - "expected ok type to not be present") - -(assert_invalid - (component - (import "y" (component $c - (type $t (result u32)) - (import "x" (type (eq $t))) - )) - - (type $x (result)) - (instance (instantiate $c (with "x" (type $x)))) - ) - "expected ok type, but found none") - -(assert_invalid - (component - (import "y" (component $c - (type $t (result)) - (import "x" (type (eq $t))) - )) - - (type $x (result (error u32))) - (instance (instantiate $c (with "x" (type $x)))) - ) - "expected err type to not be present") - -(assert_invalid - (component - (import "y" (component $c - (type $t (result (error u32))) - (import "x" (type (eq $t))) - )) - - (type $x (result)) - (instance (instantiate $c (with "x" (type $x)))) - ) - "expected err type, but found none") diff --git a/test/wasm-tools/invalid.wast b/test/wasm-tools/invalid.wast deleted file mode 100644 index 267b31f8..00000000 --- a/test/wasm-tools/invalid.wast +++ /dev/null @@ -1,34 +0,0 @@ -;; RUN: wast --assert default --snapshot tests/snapshots % - -(assert_invalid - (component - (core type (module - (import "" "" (func (type 1))) - )) - (type (func)) - ) - "type index out of bounds") - -(assert_malformed - (component quote - "(export \"\" (func $foo))" - ) - "unknown func") - -(assert_malformed - (component quote - "(alias outer 100 $foo (type $foo))" - ) - "outer count of `100` is too large") - -(assert_malformed - (component quote - "(alias outer $nonexistent $foo (type $foo))" - ) - "outer component `nonexistent` not found") - -(assert_malformed - (component quote - "(import \"x\" (func $x))" - "(component (export \"x\" (func $x)))") - "outer item `x` is not a module, type, or component") diff --git a/test/wasm-tools/link.wast b/test/wasm-tools/link.wast deleted file mode 100644 index 72023652..00000000 --- a/test/wasm-tools/link.wast +++ /dev/null @@ -1,14 +0,0 @@ -;; RUN: wast --assert default --snapshot tests/snapshots % - -;; Based on this, we can link two modules $A and $B together with the following component: - -(component - (core module $A - (func (export "one") (result i32) (i32.const 1)) - ) - (core module $B - (func (import "a" "one") (result i32)) - ) - (core instance $a (instantiate $A)) - (core instance $b (instantiate $B (with "a" (instance $a)))) -) diff --git a/test/wasm-tools/lots-of-aliases.wast b/test/wasm-tools/lots-of-aliases.wast deleted file mode 100644 index 32e1a27a..00000000 --- a/test/wasm-tools/lots-of-aliases.wast +++ /dev/null @@ -1,179 +0,0 @@ -;; RUN: wast --assert default --snapshot tests/snapshots % - -(component - (core module $m - (memory (export "m") 1) - (table (export "t") 1 funcref) - (global (export "g") i32 i32.const 0) - (func (export "f")) - ) - (core instance $i (instantiate $m)) - - ;; 160 memories (4 per row 40 rows) - (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) - (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) - (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) - (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) - (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) - (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) - (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) - (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) - (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) - (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) - (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) - (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) - (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) - (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) - (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) - (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) - (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) - (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) - (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) - (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) - (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) - (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) - (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) - (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) - (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) - (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) - (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) - (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) - (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) - (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) - (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) - (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) - (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) - (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) - (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) - (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) - (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) - (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) - (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) - (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) (alias core export $i "m" (core memory)) - - ;; 160 tables (4 per row 40 rows) - (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) - (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) - (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) - (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) - (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) - (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) - (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) - (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) - (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) - (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) - (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) - (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) - (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) - (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) - (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) - (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) - (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) - (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) - (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) - (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) - (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) - (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) - (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) - (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) - (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) - (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) - (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) - (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) - (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) - (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) - (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) - (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) - (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) - (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) - (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) - (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) - (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) - (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) - (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) - (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) (alias core export $i "t" (core table)) - - ;; 160 globals (4 per row 40 rows) - (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) - (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) - (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) - (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) - (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) - (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) - (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) - (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) - (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) - (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) - (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) - (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) - (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) - (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) - (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) - (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) - (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) - (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) - (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) - (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) - (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) - (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) - (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) - (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) - (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) - (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) - (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) - (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) - (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) - (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) - (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) - (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) - (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) - (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) - (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) - (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) - (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) - (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) - (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) - (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) (alias core export $i "g" (core global)) - - ;; 160 functions (4 per row 40 rows) - (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) - (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) - (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) - (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) - (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) - (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) - (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) - (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) - (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) - (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) - (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) - (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) - (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) - (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) - (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) - (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) - (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) - (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) - (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) - (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) - (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) - (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) - (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) - (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) - (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) - (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) - (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) - (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) - (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) - (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) - (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) - (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) - (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) - (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) - (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) - (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) - (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) - (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) - (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) - (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) (alias core export $i "f" (core func)) -) diff --git a/test/wasm-tools/lower.wast b/test/wasm-tools/lower.wast deleted file mode 100644 index 5b9e13bf..00000000 --- a/test/wasm-tools/lower.wast +++ /dev/null @@ -1,17 +0,0 @@ -;; RUN: wast --assert default --snapshot tests/snapshots % - -(assert_invalid - (component - (import "f" (func $f (param "x" (list u8)))) - (core func $f (canon lower (func $f) - )) - ) - "canonical option `memory` is required") - -(assert_invalid - (component - (import "f" (func $f (result (list u8)))) - (core func $f (canon lower (func $f) - )) - ) - "canonical option `memory` is required") diff --git a/test/wasm-tools/memory64.wast b/test/wasm-tools/memory64.wast deleted file mode 100644 index 36edaec5..00000000 --- a/test/wasm-tools/memory64.wast +++ /dev/null @@ -1,55 +0,0 @@ -;; RUN: wast --assert default --snapshot tests/snapshots % - -(assert_invalid - (component - (core module $A - (import "" "" (memory 1))) - (core module $B - (memory (export "") i64 1)) - (core instance $b (instantiate $B)) - (core instance $a (instantiate $A (with "" (instance $b)))) - ) - "mismatch in index type used for memories") - -(assert_invalid - (component - (core module $A - (import "" "" (memory i64 1))) - (core module $B - (memory (export "") 1)) - (core instance $b (instantiate $B)) - (core instance $a (instantiate $A (with "" (instance $b)))) - ) - "mismatch in index type used for memories") - -(component - (core module $A - (memory (export "m") i64 1)) - (core instance $A (instantiate $A)) - (alias core export $A "m" (core memory $m)) - - (core module $B (import "" "" (memory i64 1))) - (core instance (instantiate $B (with "" (instance (export "" (memory $m)))))) -) - -(component - (core module $A - (table (export "m") i64 1 funcref)) - (core instance $A (instantiate $A)) - (alias core export $A "m" (core table $m)) - - (core module $B (import "" "" (table i64 1 funcref))) - (core instance (instantiate $B (with "" (instance (export "" (table $m)))))) -) - -(component definition - (import "x" (func $x (param "x" string))) - (core module $A - (memory (export "m") i64 1) - (func (export "realloc") (param i64 i64 i64 i64) (result i64) unreachable) - ) - (core instance $A (instantiate $A)) - (alias core export $A "m" (core memory $m)) - (core func $realloc (alias core export $A "realloc")) - (core func (canon lower (func $x) (memory $m) (realloc (core func $realloc)))) -) diff --git a/test/wasm-tools/module-link.wast b/test/wasm-tools/module-link.wast deleted file mode 100644 index 119da23b..00000000 --- a/test/wasm-tools/module-link.wast +++ /dev/null @@ -1,98 +0,0 @@ -;; RUN: wast --assert default --snapshot tests/snapshots % - -(component - (type $Wasi (instance)) - (component $B) - (component $B_wrap - (import "wasi" (instance $wasi (type $Wasi))) - (instance $b (instantiate $B)) - ) -) - -(component - (type $Wasi (instance)) - (import "wasi" (instance $wasi (type $Wasi))) - - (component $A - (type $Wasi (instance)) - (import "wasi" (instance (type $Wasi))) - - (core module $m - (func (export "a")) - ) - - (core instance $i (instantiate $m)) - (func (export "a") - (canon lift (core func $i "a")) - ) - ) - - (component $B - (type $Wasi (instance)) - (import "wasi" (instance $wasi (type $Wasi))) - (import "a1-x" (component $A - (import "wasi" (instance (type $Wasi))) - (export "a" (func)) - )) - (instance $a (instantiate $A (with "wasi" (instance $wasi)))) - - (core func $lower (canon lower (func $a "a"))) - (core module $b - (import "a" "a" (func)) - (func (export "b")) - ) - (core instance $b (instantiate $b - (with "a" (instance (export "a" (func $lower)))) - )) - (func (export "b") - (canon lift (core func $b "b")) - ) - ) - (component $B_wrap - (type $Wasi (instance)) - (import "wasi" (instance $wasi (type $Wasi))) - (instance $b (instantiate $B - (with "wasi" (instance $wasi)) - (with "a1-x" (component $A))) - ) - (export "b" (func $b "b")) - ) - - (component $C - (type $Wasi (instance)) - (import "wasi" (instance $wasi (type $Wasi))) - (import "b1-x" (component $B - (import "wasi" (instance $wasi (type $Wasi))) - (export "b" (func)) - )) - (instance $b (instantiate $B (with "wasi" (instance $wasi)))) - (export "c" (func $b "b")) - ) - (component $C_wrap - (type $Wasi (instance)) - (import "wasi" (instance $wasi (type $Wasi))) - (instance $c (instantiate $C - (with "wasi" (instance $wasi)) - (with "b1-x" (component $B_wrap)) - )) - (export "c" (func $c "c")) - ) - - (component $D - (type $Wasi (instance)) - (import "wasi" (instance $wasi (type $Wasi))) - (import "c1-x" (component $C - (import "wasi" (instance $wasi (type $Wasi))) - (export "c" (func)) - )) - (instance $c (instantiate $C (with "wasi" (instance $wasi)))) - (export "d" (func $c "c")) - ) - - (instance $d (instantiate $D - (with "wasi" (instance $wasi)) - (with "c1-x" (component $C_wrap)) - )) - - (export "d" (func $d "d")) -) diff --git a/test/wasm-tools/more-flags.wast b/test/wasm-tools/more-flags.wast deleted file mode 100644 index ebcced0f..00000000 --- a/test/wasm-tools/more-flags.wast +++ /dev/null @@ -1,41 +0,0 @@ -;; RUN: wast --assert default --snapshot tests/snapshots % - -(assert_invalid - (component - (type (flags - "f1" - "f2" - "f3" - "f4" - "f5" - "f6" - "f7" - "f8" - "f9" - "f10" - "f11" - "f12" - "f13" - "f14" - "f15" - "f16" - "f17" - "f18" - "f19" - "f20" - "f21" - "f22" - "f23" - "f24" - "f25" - "f26" - "f27" - "f28" - "f29" - "f30" - "f31" - "f32" - "f33" - )) - ) - "cannot have more than 32 flags") diff --git a/test/wasm-tools/naming.wast b/test/wasm-tools/naming.wast deleted file mode 100644 index 5decf55d..00000000 --- a/test/wasm-tools/naming.wast +++ /dev/null @@ -1,127 +0,0 @@ -;; RUN: wast --assert default --snapshot tests/snapshots % - -(component definition - (func (import "a")) - (component) - (instance (instantiate 0 (with "NotKebab-Case" (func 0)))) -) - -(assert_invalid - (component - (import "f" (func)) - (instance (export "1" (func 0))) - ) - "`1` is not in kebab case" -) - -(assert_invalid - (component - (instance) - (alias export 0 "Xml" (func)) - ) - "instance 0 has no export named `Xml`" -) - -(component definition - (type (flags "a-1-c")) -) - -(assert_invalid - (component - (type (enum "NevEr")) - ) - "enum tag name `NevEr` is not in kebab case" -) - -(assert_invalid - (component - (type (record (field "GoNnA" string))) - ) - "record field name `GoNnA` is not in kebab case" -) - -(assert_invalid - (component - (type (variant (case "GIVe" string))) - ) - "variant case name `GIVe` is not in kebab case" -) - - -(assert_invalid - (component - (type (func (param "yOu" string))) - ) - "function parameter name `yOu` is not in kebab case" -) - -(assert_invalid - (component - (type (component (export "NevEr" (func)))) - ) - "`NevEr` is not in kebab case" -) - -(assert_invalid - (component - (type (component (import "GonnA" (func)))) - ) - "`GonnA` is not in kebab case" -) - -(assert_invalid - (component - (type (instance (export "lET" (func)))) - ) - "`lET` is not in kebab case" -) - -(assert_invalid - (component - (instance (export "YoU")) - ) - "`YoU` is not in kebab case" -) - -(assert_invalid - (component - (instance (import "DOWn")) - ) - "`DOWn` is not in kebab case" -) - -(assert_invalid - (component - (instance (import "A:b/c")) - ) - "character `A` is not lowercase in package name/namespace" -) -(assert_invalid - (component - (instance (import "a:B/c")) - ) - "character `B` is not lowercase in package name/namespace" -) -(component - (instance (import "a:b/c")) - (instance (import "a1:b1/c")) -) - -(component definition - (import "a" (type $a (sub resource))) - (import "[constructor]a" (func (result (own $a)))) -) - -(assert_invalid - (component - (import "a" (type $a (sub resource))) - (import "[method]a.a" (func (param "self" (borrow $a)))) - ) - "import name `[method]a.a` conflicts with previous name `a`") - -(assert_invalid - (component - (import "a" (type $a (sub resource))) - (import "[static]a.a" (func)) - ) - "import name `[static]a.a` conflicts with previous name `a`") diff --git a/test/wasm-tools/nested-modules.wast b/test/wasm-tools/nested-modules.wast deleted file mode 100644 index 5e629ea5..00000000 --- a/test/wasm-tools/nested-modules.wast +++ /dev/null @@ -1,50 +0,0 @@ -;; RUN: wast --assert default --snapshot tests/snapshots % - -(component definition - (import "i1" (core module)) - - (core module) - (core module) - - (core module (export "x")) - - (component - (core module) - ) - - (component - (core module $m) - (import "a" (func (param "p" string))) - (export "b" (core module $m)) - ) -) - -;; does the `import` use the type annotation specified later? -(component definition - (import "a" (core module)) - (core type (module)) -) - -;; be sure to typecheck nested modules -(assert_invalid - (component - (core module - (func - i32.add) - ) - ) - "type mismatch") - -;; interleave module definitions with imports/aliases and ensure that we -;; typecheck the module code section correctly -(component definition - (core module - (func (export "")) - ) - (import "a" (core module)) - (core module - (func (export "") (result i32) i32.const 5) - ) - (import "b" (instance (export "a" (core module)))) - (alias export 0 "a" (core module)) -) diff --git a/test/wasm-tools/resources.wast b/test/wasm-tools/resources.wast deleted file mode 100644 index dd2ad7fd..00000000 --- a/test/wasm-tools/resources.wast +++ /dev/null @@ -1,1195 +0,0 @@ -;; RUN: wast --assert default --snapshot tests/snapshots % - -(component - (type $x (resource (rep i32))) -) - -(component - (type $x (resource (rep i32))) - - (core func (canon resource.new $x)) - (core func (canon resource.rep $x)) - (core func (canon resource.drop $x)) -) - -(component definition - (import "x" (type $x (sub resource))) - - (core func (canon resource.drop $x)) -) - -(component - (core module $m - (func (export "dtor") (param i32)) - ) - (core instance $m (instantiate $m)) - (type $x (resource (rep i32) (dtor (core func $m "dtor")))) - (core func (canon resource.new $x)) -) - -(component - (type $x (resource (rep i32))) - (core func $f1 (canon resource.new $x)) - (core func $f2 (canon resource.rep $x)) - (core func $f3 (canon resource.drop $x)) - - (core module $m - (import "" "f1" (func (param i32) (result i32))) - (import "" "f2" (func (param i32) (result i32))) - (import "" "f3" (func (param i32))) - ) - - (core instance (instantiate $m - (with "" (instance - (export "f1" (func $f1)) - (export "f2" (func $f2)) - (export "f3" (func $f3)) - )) - )) -) - -(assert_invalid - (component - (type $x (resource (rep i64))) - ) - "resources can only be represented by `i32`") - -(assert_invalid - (component - (type $x (own 100)) - ) - "type index out of bounds") - -(assert_invalid - (component - (type $x (borrow 100)) - ) - "type index out of bounds") - -(assert_invalid - (component - (type $t u8) - (type $x (borrow $t)) - ) - "not a resource type") - -(assert_invalid - (component - (type $t u8) - (type $x (own $t)) - ) - "not a resource type") - -(assert_invalid - (component - (import "x" (type $x (sub resource))) - (core func (canon resource.new $x)) - ) - "not a local resource") - -(assert_invalid - (component - (import "x" (type $x (sub resource))) - (core func (canon resource.rep $x)) - ) - "not a local resource") - -(assert_invalid - (component - (type $t (tuple u32)) - (core func (canon resource.drop $t)) - ) - "not a resource type") - -(assert_invalid - (component - (core func (canon resource.drop 100)) - ) - "type index out of bounds") - -(assert_invalid - (component - (type (component)) - (core func (canon resource.drop 0)) - ) - "not a resource type") - -(assert_invalid - (component - (type (component)) - (core func (canon resource.new 0)) - ) - "not a resource type") - -(assert_invalid - (component - (core module $m - (func (export "dtor")) - ) - (core instance $m (instantiate $m)) - (type $x (resource (rep i32) (dtor (core func $m "dtor")))) - (core func (canon resource.new $x)) - ) - "wrong signature for a destructor") - -(assert_invalid - (component - (type (resource (rep i32) (dtor (core func 100)))) - ) - "function index out of bounds") - -(assert_invalid - (component - (import "x" (type $x (sub resource))) - (import "y" (type $y (sub resource))) - (import "z" (func $z (param "x" (own $x)) (param "y" (own $y)))) - - (component $c - (import "x" (type $x (sub resource))) - (import "z" (func (param "x" (own $x)) (param "y" (own $x)))) - ) - - (instance (instantiate $c (with "x" (type $x)) (with "z" (func $z)))) - ) - "resource types are not the same") - -(component - (type (component - (import "x" (type $x (sub resource))) - (export "y" (type (eq $x))) - (export "z" (type (sub resource))) - )) -) - -(assert_invalid - (component - (type (component - (type $x (resource (rep i32))) - )) - ) - "resources can only be defined within a concrete component") - -(assert_invalid - (component - (type (instance - (type $x (resource (rep i32))) - )) - ) - "resources can only be defined within a concrete component") - -(component - (type (component - (import "x" (instance $i - (export "t" (type $t (sub resource))) - (export "f" (func (result (own $t)))) - )) - (alias export $i "t" (type $t)) - (export "f" (func (result (own $t)))) - )) -) - -(component definition - (import "fancy-fs" (instance $fancy-fs - (export "fs" (instance $fs - (export "file" (type (sub resource))) - )) - (alias export $fs "file" (type $file)) - (export "fancy-op" (func (param "f" (borrow $file)))) - )) -) - -(component $C - (type $T (list (tuple string bool))) - (type $U (option $T)) - (type $G (func (param "x" (list $T)) (result $U))) - (type $D (component - (alias outer $C $T (type $C_T)) - (type $L (list $C_T)) - (import "f" (func (param "x" $L) (result (list u8)))) - (import "g" (func (type $G))) - (export "g2" (func (type $G))) - (export "h" (func (result $U))) - (import "T" (type $T (sub resource))) - (import "i" (func (param "x" (list (own $T))))) - (export "T2" (type $T' (eq $T))) - (export "U" (type $U' (sub resource))) - (export "j" (func (param "x" (borrow $T')) (result (own $U')))) - )) -) - -(component definition - (import "T1" (type $T1 (sub resource))) - (import "T2" (type $T2 (sub resource))) -) - -(component definition $C - (import "T1" (type $T1 (sub resource))) - (import "T2" (type $T2 (sub resource))) - (import "T3" (type $T3 (eq $T2))) - (type $ListT1 (list (own $T1))) - (type $ListT2 (list (own $T2))) - (type $ListT3 (list (own $T3))) -) - -(component definition - (import "T" (type $T (sub resource))) - (import "U" (type $U (sub resource))) - (type $Own1 (own $T)) - (type $Own2 (own $T)) - (type $Own3 (own $U)) - (type $ListOwn1 (list $Own1)) - (type $ListOwn2 (list $Own2)) - (type $ListOwn3 (list $Own3)) - (type $Borrow1 (borrow $T)) - (type $Borrow2 (borrow $T)) - (type $Borrow3 (borrow $U)) - (type $ListBorrow1 (list $Borrow1)) - (type $ListBorrow2 (list $Borrow2)) - (type $ListBorrow3 (list $Borrow3)) -) - -(component - (component - (import "C" (component $C - (export "T1" (type (sub resource))) - (export "T2" (type $T2 (sub resource))) - (export "T3" (type (eq $T2))) - )) - (instance $c (instantiate $C)) - (alias export $c "T1" (type $T1)) - (alias export $c "T2" (type $T2)) - (alias export $c "T3" (type $T3)) - ) -) - -(component - (component $C - (type $r1 (export "r1") (resource (rep i32))) - (type $r2 (export "r2") (resource (rep i32))) - ) - (instance $c1 (instantiate $C)) - (instance $c2 (instantiate $C)) - (alias export $c1 "r1" (type $c1r1)) - (alias export $c1 "r2" (type $c1r2)) - (alias export $c2 "r1" (type $c2r1)) - (alias export $c2 "r2" (type $c2r2)) -) - -(component - (type $r (resource (rep i32))) - (export "r1" (type $r)) - (export "r2" (type $r)) -) - -(component - (type (component - (export "r1" (type (sub resource))) - (export "r2" (type (sub resource))) - )) -) - -(component - (type $r (resource (rep i32))) - (export $r1 "r1" (type $r)) - (export "r2" (type $r1)) -) - -(component - (type (component - (export "r1" (type $r1 (sub resource))) - (export "r2" (type (eq $r1))) - )) -) - -(component - (component $P - (import "C1" (component $C1 - (import "T" (type $T (sub resource))) - (export "foo" (func (param "t" (own $T)))) - )) - (import "C2" (component $C2 - (import "T" (type $T (sub resource))) - (import "foo" (func (param "t" (own $T)))) - )) - (type $R (resource (rep i32))) - (instance $c1 (instantiate $C1 (with "T" (type $R)))) - (instance $c2 (instantiate $C2 - (with "T" (type $R)) - (with "foo" (func $c1 "foo")) - )) - ) -) - -(component - (component - (import "C1" (component $C1 - (import "T1" (type $T1 (sub resource))) - (import "T2" (type $T2 (sub resource))) - (export "foo" (func (param "t" (tuple (own $T1) (own $T2))))) - )) - (import "C2" (component $C2 - (import "T" (type $T (sub resource))) - (export "foo" (func (param "t" (tuple (own $T) (own $T))))) - )) - (type $R (resource (rep i32))) - (instance $c1 (instantiate $C1 - (with "T1" (type $R)) - (with "T2" (type $R)) - )) - (instance $c2 (instantiate $C2 - (with "T" (type $R)) - (with "foo" (func $c1 "foo")) - )) - ) -) - -(assert_invalid - (component - (component $C - (type $R (resource (rep i32))) - (export "R" (type $R)) - ) - (instance $c (instantiate $C)) - (alias export $c "R" (type $R)) - (core func (canon resource.rep $R)) - ) - "not a local resource") - -(component - (component $C - (type $R (resource (rep i32))) - (export "R" (type $R)) - ) - (instance $c (instantiate $C)) - (alias export $c "R" (type $R)) - (core func (canon resource.drop $R)) -) - -(component - (component $C1 - (import "X" (type (sub resource))) - ) - (component $C2 - (import "C1" (component - (import "X" (type (sub resource))) - )) - ) - (instance $c (instantiate $C2 (with "C1" (component $C1)))) -) - -(component - (component $C1 - (import "X" (type $X (sub resource))) - (import "f" (func $f (result (own $X)))) - (export "g" (func $f)) - ) - (component $C2 - (import "C1" (component - (import "X" (type $X (sub resource))) - (import "f" (func (result (own $X)))) - (export "g" (func (result (own $X)))) - )) - ) - (instance $c (instantiate $C2 (with "C1" (component $C1)))) -) - -(component - (component $C1 - (type $X' (resource (rep i32))) - (export $X "X" (type $X')) - - (core func $f (canon resource.drop $X)) - (func (export "f") (param "X" (own $X)) (canon lift (core func $f))) - ) - (instance $c1 (instantiate $C1)) - - (component $C2 - (import "X" (type $X (sub resource))) - (import "f" (func (param "X" (own $X)))) - ) - (instance $c2 (instantiate $C2 - (with "X" (type $c1 "X")) - (with "f" (func $c1 "f")) - )) -) - -(assert_invalid - (component - (component $C1 - (type $X' (resource (rep i32))) - (export $X "X" (type $X')) - - (core func $f (canon resource.drop $X)) - (func (export "f") (param "X" (own $X)) (canon lift (core func $f))) - ) - (instance $c1 (instantiate $C1)) - (instance $c2 (instantiate $C1)) - - (component $C2 - (import "X" (type $X (sub resource))) - (import "f" (func (param "X" (own $X)))) - ) - (instance $c3 (instantiate $C2 - (with "X" (type $c1 "X")) - (with "f" (func $c2 "f")) - )) - ) - "resource types are not the same") - -(component - (component $C1 - (type $X (resource (rep i32))) - (export $X1 "X1" (type $X)) - (export $X2 "X2" (type $X)) - - (core func $f (canon resource.drop $X)) - (func (export "f1") (param "X" (own $X1)) (canon lift (core func $f))) - (func (export "f2") (param "X" (own $X2)) (canon lift (core func $f))) - ) - (instance $c1 (instantiate $C1)) - - (component $C2 - (import "X" (type $X (sub resource))) - (import "f" (func (param "X" (own $X)))) - ) - (instance $c2 (instantiate $C2 - (with "X" (type $c1 "X1")) - (with "f" (func $c1 "f1")) - )) - (instance $c3 (instantiate $C2 - (with "X" (type $c1 "X2")) - (with "f" (func $c1 "f2")) - )) -) - -(component - (component $C1 - (type $X (resource (rep i32))) - (export $X1 "X1" (type $X)) - (export $X2 "X2" (type $X)) - - (core func $f (canon resource.drop $X)) - (func (export "f1") (param "X" (own $X1)) (canon lift (core func $f))) - (func (export "f2") (param "X" (own $X2)) (canon lift (core func $f))) - ) - (instance $c1 (instantiate $C1)) - - (component $C2 - (import "X" (type $X (sub resource))) - (import "f" (func (param "X" (own $X)))) - ) - (instance $c2 (instantiate $C2 - (with "X" (type $c1 "X1")) - (with "f" (func $c1 "f2")) - )) - (instance $c3 (instantiate $C2 - (with "X" (type $c1 "X2")) - (with "f" (func $c1 "f1")) - )) -) - -(assert_invalid - (component - (component $c - (import "x" (type (sub resource))) - ) - (type $x u32) - (instance (instantiate $c (with "x" (type $x)))) - ) - "expected resource, found defined type") - -(assert_invalid - (component - (component $c - (type $t u32) - (import "x" (type (eq $t))) - ) - (type $x (resource (rep i32))) - (instance (instantiate $c (with "x" (type $x)))) - ) - "expected defined type, found resource") - -(assert_invalid - (component - (component $c - (import "x1" (type $x1 (sub resource))) - (import "x2" (type $x2 (eq $x1))) - ) - (type $x1 (resource (rep i32))) - (type $x2 (resource (rep i32))) - (instance (instantiate $c - (with "x1" (type $x1)) - (with "x2" (type $x2)) - )) - ) - "resource types are not the same") - -(component - (type $x (resource (rep i32))) - (component $c - (import "x" (type $t (sub resource))) - (export "y" (type $t)) - ) - (instance $c (instantiate $c (with "x" (type $x)))) - - (alias export $c "y" (type $x2)) - (core func (canon resource.rep $x2)) - -) - -(assert_invalid - (component - (type $r (resource (rep i32))) - (import "x" (func (result (own $r)))) - ) - "func not valid to be used as import") - -(assert_invalid - (component - (type (component - (export "x" (type $x (sub resource))) - (import "f" (func (result (own $x)))) - )) - ) - "func not valid to be used as import") - -(assert_invalid - (component - (type $r (resource (rep i32))) - - (core func $f (canon resource.drop $r)) - (func (export "f") (param "x" (own $r)) - (canon lift (core func $f))) - ) - "func not valid to be used as export") - -;; direct exports count as "explicit in" for resources -(component - (type $r' (resource (rep i32))) - (export $r "r" (type $r')) - - (core func $f (canon resource.drop $r)) - (func (export "f") (param "x" (own $r)) - (canon lift (core func $f))) -) - -;; instances-as-a-bundle count as "explicit in" for resources -(component - (type $r' (resource (rep i32))) - (instance $i' - (export "r" (type $r')) - ) - (export $i "i" (instance $i')) - (alias export $i "r" (type $r)) - - (core func $f (canon resource.drop $r)) - (func (export "f") (param "x" (own $r)) - (canon lift (core func $f))) -) - -;; Transitive bundles count for "explicit in" -(component - (type $r' (resource (rep i32))) - (instance $i' - (export "r" (type $r')) - ) - (instance $i2' - (export "i" (instance $i')) - ) - (export $i2 "i2" (instance $i2')) - (alias export $i2 "i" (instance $i)) - (alias export $i "r" (type $r)) - - (core func $f (canon resource.drop $r)) - (func (export "f") (param "x" (own $r)) - (canon lift (core func $f))) -) - -;; Component instantiations count for "explicit in" -(component - (type $r' (resource (rep i32))) - (component $C - (import "x" (type $x (sub resource))) - (export "y" (type $x)) - ) - (instance $c' (instantiate $C (with "x" (type $r')))) - (export $c "c" (instance $c')) - (alias export $c "y" (type $r)) - - (core func $f (canon resource.drop $r)) - (func (export "f") (param "x" (own $r)) - (canon lift (core func $f))) -) - -;; Make sure threading things around is valid for "explicit in" -(component - (type $r' (resource (rep i32))) - (component $C - (import "x" (type $x (sub resource))) - (export "y" (type $x)) - ) - (instance $c (instantiate $C (with "x" (type $r')))) - (instance $i (export "x" (type $c "y"))) - - (component $C2 - (import "x" (instance $i - (export "i1" (instance - (export "i2" (type (sub resource))) - )) - )) - (export "y" (type $i "i1" "i2")) - ) - - (instance $i2 (export "i2" (type $i "x"))) - (instance $i1 (export "i1" (instance $i2))) - (instance $c2 (instantiate $C2 - (with "x" (instance $i1)) - )) - (export $r "x" (type $c2 "y")) - - (core func $f (canon resource.drop $r)) - (func (export "f") (param "x" (own $r)) - (canon lift (core func $f))) -) - -;; Importing-and-exporting instances through instantiation counts for "explicit -;; in" -(component - (type $r' (resource (rep i32))) - (component $C - (import "x" (instance $x (export "t" (type (sub resource))))) - (export "y" (instance $x)) - ) - (instance $c' (instantiate $C - (with "x" (instance - (export "t" (type $r')) - )) - )) - (export $c "c" (instance $c')) - (alias export $c "y" (instance $y)) - (alias export $y "t" (type $r)) - - (core func $f (canon resource.drop $r)) - (func (export "f") (param "x" (own $r)) - (canon lift (core func $f))) -) - -(component definition - (type $i (instance - (export "r" (type $r (sub resource))) - (export "f" (func (result (own $r)))) - )) - (import "i1" (instance $i1 (type $i))) - (import "i2" (instance $i2 (type $i))) - - (component $c - (import "r" (type $t (sub resource))) - (import "f" (func (result (own $t)))) - ) - (instance (instantiate $c - (with "r" (type $i1 "r")) - (with "f" (func $i1 "f")) - )) - (instance (instantiate $c - (with "r" (type $i2 "r")) - (with "f" (func $i2 "f")) - )) -) - - -(assert_invalid - (component - (type $i (instance - (export "r" (type $r (sub resource))) - (export "f" (func (result (own $r)))) - )) - (import "i1" (instance $i1 (type $i))) - (import "i2" (instance $i2 (type $i))) - - (component $c - (import "r" (type $t (sub resource))) - (import "f" (func (result (own $t)))) - ) - (instance (instantiate $c - (with "r" (type $i1 "r")) - (with "f" (func $i2 "f")) - )) - ) - "resource types are not the same") - -;; substitution works -(component - (type $t (resource (rep i32))) - (component $c - (import "x" (type $t (sub resource))) - (export "y" (type $t)) - ) - (instance $c1 (instantiate $c (with "x" (type $t)))) - (instance $c2 (instantiate $c (with "x" (type $t)))) - - (component $c2 - (import "x1" (type $t (sub resource))) - (import "x2" (type (eq $t))) - (import "x3" (type (eq $t))) - ) - (instance (instantiate $c2 - (with "x1" (type $t)) - (with "x2" (type $c1 "y")) - (with "x3" (type $c2 "y")) - )) -) - -;; must supply a resource to instantiation -(assert_invalid - (component - (component $c - (import "x" (type (sub resource))) - ) - (instance (instantiate $c)) - ) - "missing import named `x`") -(assert_invalid - (component - (type $x (resource (rep i32))) - (component $c - (import "x" (type (sub resource))) - (import "y" (type (sub resource))) - ) - (instance (instantiate $c (with "x" (type $x)))) - ) - "missing import named `y`") - -;; supply the wrong resource -(assert_invalid - (component - (type $x (resource (rep i32))) - (type $y (resource (rep i32))) - (component $c - (import "x" (type $t (sub resource))) - (import "y" (type (eq $t))) - ) - (instance (instantiate $c - (with "x" (type $x)) - (with "y" (type $y)) - )) - ) - "resource types are not the same") - -;; aliasing outer resources is ok -(component $A - (type $C (component - (import "x" (type $x (sub resource))) - - (type $y (component - (alias outer $C $x (type $my-x)) - (import "x" (type (eq $my-x))) - )) - - (import "y" (component (type $y))) - (export "z" (component (type $y))) - )) - - (type $t (resource (rep i32))) - - (alias outer $A $t (type $other-t)) - - (type (instance (export "t" (type (eq $t))))) - (type (component (export "t" (type (eq $t))))) - (type (component (import "t" (type (eq $t))))) -) - -;; aliasing beyond components, however, is not ok -(assert_invalid - (component $A - (type $t (resource (rep i32))) - (component (alias outer $A $t (type $foo))) - ) - "refers to resources not defined in the current component") -(assert_invalid - (component $A - (type $t (resource (rep i32))) - (type $u (record (field "x" (own $t)))) - (component (alias outer $A $u (type $foo))) - ) - "refers to resources not defined in the current component") -(assert_invalid - (component $A - (type $t (resource (rep i32))) - (type $u (borrow $t)) - (component (alias outer $A $u (type $foo))) - ) - "refers to resources not defined in the current component") -(assert_invalid - (component $A - (type $t (resource (rep i32))) - (type $u (component (export "a" (type (eq $t))))) - (component (alias outer $A $u (type $foo))) - ) - "refers to resources not defined in the current component") -(assert_invalid - (component $A - (type $t (resource (rep i32))) - (type $u (component (import "a" (type (eq $t))))) - (component (alias outer $A $u (type $foo))) - ) - "refers to resources not defined in the current component") - -(assert_invalid - (component - (component $X - (type $t (resource (rep i32))) - (export "t" (type $t)) - ) - (component $F - (import "x" (component (export "t" (type $t (sub resource))))) - ) - (instance $x1 (instantiate $X)) - (instance $f1 (instantiate $F (with "x" (instance $x1)))) - ) - "expected component, found instance") - -;; Show that two instantiations of the same component produce unique exported -;; resource types. -(assert_invalid - (component - (component $F - (type $t1 (resource (rep i32))) - (export "t1" (type $t1)) - ) - (instance $f1 (instantiate $F)) - (instance $f2 (instantiate $F)) - (alias export $f1 "t1" (type $t1)) - (alias export $f2 "t1" (type $t2)) - (component $T - (import "x" (type $x (sub resource))) - (import "y" (type (eq $x))) - ) - (instance $test - (instantiate $T (with "x" (type $t1)) (with "y" (type $t2)))) - ) - "type mismatch for import `y`") - -;; Show that re-exporting imported resources from an imported component doesn't -;; change the identity of that resource. -(component - (component $X - (type $t (resource (rep i32))) - (export "t" (type $t)) - ) - (component $F - (import "x" (instance $i (export "t" (type $t (sub resource))))) - (alias export $i "t" (type $t)) - (export "t" (type $t)) - ) - (instance $x1 (instantiate $X)) - (instance $f1 (instantiate $F (with "x" (instance $x1)))) - (instance $f2 (instantiate $F (with "x" (instance $x1)))) - (alias export $f1 "t" (type $t1)) - (alias export $f2 "t" (type $t2)) - (component $T - (import "x" (type $x (sub resource))) - (import "y" (type (eq $x))) - ) - (instance $test - (instantiate $T (with "x" (type $t1)) (with "y" (type $t2)))) -) - -(assert_invalid - (component (import "[static]" (func))) - "failed to find `.` character") - -;; validation of `[constructor]foo` -(assert_invalid - (component (import "[constructor]" (func))) - "not in kebab case") -(assert_invalid - (component (import "[constructor]a" (func))) - "should return one value") -(assert_invalid - (component (import "[constructor]a" (func (result u32)))) - "should return `(own $T)`") -(assert_invalid - (component - (import "b" (type $a (sub resource))) - (import "[constructor]a" (func (result (own $a))))) - "import name `[constructor]a` is not valid") -(assert_invalid - (component - (import "b" (type $a (sub resource))) - (import "[constructor]a" (func (result (own $a))))) - "function does not match expected resource name `b`") -(assert_invalid - (component - (import "b" (type $a (sub resource))) - (import "[constructor]a" (func (result (result(own $a)))))) - "function does not match expected resource name `b`") -(component definition - (import "a" (type $a (sub resource))) - (import "[constructor]a" (func (result (own $a))))) -(component definition - (import "a" (type $a (sub resource))) - (import "[constructor]a" (func (result (result (own $a)))))) -(component definition - (import "a" (type $a (sub resource))) - (import "[constructor]a" (func (result (result (own $a) (error string)))))) -(component definition - (import "a" (type $a (sub resource))) - (import "[constructor]a" (func (param "x" u32) (result (own $a))))) -(assert_invalid - (component - (import "a" (type $a (sub resource))) - (import "[constructor]a" (func (result string)))) - "function should return `(own $T)` or `(result (own $T))`") -(assert_invalid - (component - (import "a" (type $a (sub resource))) - (import "[constructor]a" (func (result (result string))))) - "function should return `(own $T)` or `(result (own $T))`") - -;; validation of `[method]a.b` -(assert_invalid - (component (import "[method]" (func))) - "failed to find `.` character") -(assert_invalid - (component (import "[method]a" (func))) - "failed to find `.` character") -(assert_invalid - (component (import "[method]a." (func))) - "not in kebab case") -(assert_invalid - (component (import "[method].a" (func))) - "not in kebab case") -(assert_invalid - (component (import "[method]a.b.c" (func))) - "not in kebab case") -(assert_invalid - (component (import "[method]a.b" (instance))) - "is not a func") -(assert_invalid - (component (import "[method]a.b" (func))) - "should have at least one argument") -(assert_invalid - (component (import "[method]a.b" (func (param "x" u32)))) - "should have a first argument called `self`") -(assert_invalid - (component (import "[method]a.b" (func (param "self" u32)))) - "should take a first argument of `(borrow $T)`") -(assert_invalid - (component - (import "b" (type $T (sub resource))) - (import "[method]a.b" (func (param "self" (borrow $T))))) - "does not match expected resource name") -(component definition - (import "a" (type $T (sub resource))) - (import "[method]a.b" (func (param "self" (borrow $T))))) - -;; validation of `[static]a.b` -(assert_invalid - (component (import "[static]" (func))) - "failed to find `.` character") -(assert_invalid - (component (import "[static]a" (func))) - "failed to find `.` character") -(assert_invalid - (component (import "[static]a." (func))) - "not in kebab case") -(assert_invalid - (component (import "[static].a" (func))) - "not in kebab case") -(assert_invalid - (component (import "[static]a.b.c" (func))) - "not in kebab case") -(assert_invalid - (component (import "[static]a.b" (instance))) - "is not a func") -(assert_invalid - (component (import "[static]a.b" (func))) - "static resource name is not known in this context") - -(component definition - (import "a" (type (sub resource))) - (import "[static]a.b" (func))) - -;; exports/imports are disjoint -(assert_invalid - (component - (import "b" (type $T (sub resource))) - (import "f" (func $f (param "self" (borrow $T)))) - (export "[method]b.foo" (func $f)) - ) - "resource used in function does not have a name in this context") - -(component - (component - (import "b" (type $T (sub resource))) - (import "f" (func $f (param "self" (borrow $T)))) - (export $c "c" (type $T)) - (export "[method]c.foo" (func $f) (func (param "self" (borrow $c)))) - ) -) - -;; imports aren't transitive -(assert_invalid - (component - (import "i" (instance $i - (export "t" (type (sub resource))) - )) - (alias export $i "t" (type $t)) - (import "[method]t.foo" (func (param "self" (borrow $t)))) - ) - "resource used in function does not have a name in this context") - -;; validation happens in a type context -(assert_invalid - (component - (type (component - (import "b" (type $T (sub resource))) - (import "[constructor]a" (func (result (own $T)))) - )) - ) - "function does not match expected resource name `b`") - -;; bag-of-exports validation -(assert_invalid - (component - (type $T (resource (rep i32))) - (core module $m (func (export "a") (result i32) unreachable)) - (core instance $i (instantiate $m)) - (func $f (result (own $T)) (canon lift (core func $i "a"))) - (instance - (export "a" (type $T)) - (export "[constructor]a" (func $f)) - ) - ) - "resource used in function does not have a name in this context") - -(component - (component $C) - (instance (instantiate $C (with "this is not kebab case" (component $C)))) -) - -;; Test that unused arguments to instantiation are not validated to have -;; appropriate types with respect to kebab naming conventions which require -;; functions/interfaces/etc. -(component - (component $C) - (instance (instantiate $C (with "[method]foo.bar" (component $C)))) -) - -;; thread a resource through a few layers -(component - (component $C - (import "in" (type $r (sub resource))) - (export "out" (type $r)) - ) - - (type $r (resource (rep i32))) - - (instance $c1 (instantiate $C (with "in" (type $r)))) - (instance $c2 (instantiate $C (with "in" (type $c1 "out")))) - (instance $c3 (instantiate $C (with "in" (type $c2 "out")))) - (instance $c4 (instantiate $C (with "in" (type $c3 "out")))) - (instance $c5 (instantiate $C (with "in" (type $c4 "out")))) - - (component $C2 - (import "in1" (type $r (sub resource))) - (import "in2" (type (eq $r))) - (import "in3" (type (eq $r))) - (import "in4" (type (eq $r))) - (import "in5" (type (eq $r))) - (import "in6" (type (eq $r))) - ) - - (instance (instantiate $C2 - (with "in1" (type $r)) - (with "in2" (type $c1 "out")) - (with "in3" (type $c2 "out")) - (with "in4" (type $c3 "out")) - (with "in5" (type $c4 "out")) - (with "in6" (type $c5 "out")) - )) -) - -;; exporting an instance type "freshens" resources -(assert_invalid - (component - (import "x" (instance $i - (type $i (instance - (export "r" (type (sub resource))) - )) - (export "a" (instance (type $i))) - (export "b" (instance (type $i))) - )) - - (component $C - (import "x" (type $x (sub resource))) - (import "y" (type (eq $x))) - ) - (instance (instantiate $C - (with "x" (type $i "a" "r")) - (with "y" (type $i "b" "r")) - )) - ) - "resource types are not the same") - -(component - (type (export "x") (component - (type $t' (instance - (export "r" (type (sub resource))) - )) - (export "t" (instance $t (type $t'))) - (alias export $t "r" (type $r)) - (type $t2' (instance - (export "r2" (type (eq $r))) - (export "r" (type (sub resource))) - )) - (export "t2" (instance (type $t2'))) - )) -) - -(component - (type (component - (type (instance - (export "bar" (type (sub resource))) - (export "[static]bar.a" (func)) - )) - (export "x" (instance (type 0))) - )) -) - -(assert_invalid - (component - (type $r (resource (rep i32))) - (type (func (result (borrow $r)))) - ) - "function result cannot contain a `borrow` type") -(assert_invalid - (component - (type $r (resource (rep i32))) - (type (func (result (list (borrow $r))))) - ) - "function result cannot contain a `borrow` type") -(assert_invalid - (component - (type $r (resource (rep i32))) - (type (func (result (option (borrow $r))))) - ) - "function result cannot contain a `borrow` type") -(assert_invalid - (component - (type $r (resource (rep i32))) - (type $t (record (field "f" (borrow $r)))) - (type (func (result (option (list $t))))) - ) - "function result cannot contain a `borrow` type") - -;; forms of canon builtins -(component - (type $r (resource (rep i32))) - (core func (canon resource.new $r)) - (canon resource.new $r (core func)) - (core func (canon resource.drop $r)) - (canon resource.drop $r (core func)) - (core func (canon resource.rep $r)) - (canon resource.rep $r (core func)) -) diff --git a/test/wasm-tools/tags.wast b/test/wasm-tools/tags.wast deleted file mode 100644 index 5c70d3ab..00000000 --- a/test/wasm-tools/tags.wast +++ /dev/null @@ -1,30 +0,0 @@ -;; RUN: wast --assert default --snapshot tests/snapshots % - -(assert_invalid - (component - (core module $m (func (export ""))) - (core instance $i (instantiate $m)) - (alias core export $i "" (core tag $t)) - ) - "export `` for core instance 0 is not a tag") - -(component - (core module $m (tag (export ""))) - (core instance $i (instantiate $m)) - (alias core export $i "" (core tag $t)) -) - -(component - (core module $m (tag (export ""))) - (core instance $i (instantiate $m)) - (core instance - (export "" (tag $i "")))) - -(assert_invalid - (component - (core module $m (func (export ""))) - (core instance $i (instantiate $m)) - (core instance - (export "" (tag 0))) - ) - "unknown tag 0") diff --git a/test/wasm-tools/type-export-restrictions.wast b/test/wasm-tools/type-export-restrictions.wast deleted file mode 100644 index d2971f8d..00000000 --- a/test/wasm-tools/type-export-restrictions.wast +++ /dev/null @@ -1,504 +0,0 @@ -;; RUN: wast --assert default --snapshot tests/snapshots % - -;; Test that unnamed types in various types are all detected - -(assert_invalid - (component - (type $t (record (field "f" u32))) - (type $f (record (field "f" $t))) - (export "f" (type $f)) - ) - "type not valid to be used as export") - -(assert_invalid - (component - (type $t (record (field "f" u32))) - (type $f (list $t)) - (export "f" (type $f)) - ) - "type not valid to be used as export") - -(assert_invalid - (component - (type $t (record (field "f" u32))) - (type $f (tuple $t)) - (export "f" (type $f)) - ) - "type not valid to be used as export") - -(assert_invalid - (component - (type $t (record (field "f" u32))) - (type $f (variant (case "c" $t))) - (export "f" (type $f)) - ) - "type not valid to be used as export") - -(assert_invalid - (component - (type $t (record (field "f" u32))) - (type $f (option $t)) - (export "f" (type $f)) - ) - "type not valid to be used as export") - -(assert_invalid - (component - (type $t (record (field "f" u32))) - (type $f (result $t)) - (export "f" (type $f)) - ) - "type not valid to be used as export") - -;; Test that various types are all flagged as "requires a name" - -(assert_invalid - (component - (type $t (record (field "f" u32))) - (type $f (list $t)) - (export "f" (type $f)) - ) - "type not valid to be used as export") - -(assert_invalid - (component - (type $t (enum "a")) - (type $f (list $t)) - (export "f" (type $f)) - ) - "type not valid to be used as export") - -(assert_invalid - (component - (type $t (flags "a")) - (type $f (list $t)) - (export "f" (type $f)) - ) - "type not valid to be used as export") - -(assert_invalid - (component - (type $t (variant (case "a"))) - (type $f (list $t)) - (export "f" (type $f)) - ) - "type not valid to be used as export") - -(assert_invalid - (component - (type $t (resource (rep i32))) - (type $f (list (own $t))) - (export "f" (type $f)) - ) - "type not valid to be used as export") - -;; Some types don't need names -(component - (type $t1 (tuple (tuple u32))) - (export "t1" (type $t1)) - - (type $t2 (option (tuple (list u8) (result (list u32) (error (option string)))))) - (export "t2" (type $t2)) - - (type $t3 u32) - (export "t3" (type $t3)) -) - -(component - (type $t' (record (field "f" u32))) - (export $t "t" (type $t')) - (type $t2 (record (field "x" $t))) - (export "t2" (type $t2)) -) - -;; imports are validated as well -(assert_invalid - (component - (type $t (record (field "f" u32))) - (type $t2 (record (field "f" $t))) - (import "x" (type (eq $t2))) - ) - "type not valid to be used as import") -(component - (type $t (record (field "f" u32))) - (import "t" (type $t' (eq $t))) - (type $t2 (record (field "f" $t'))) - (import "x" (type (eq $t2))) -) -(assert_invalid - (component - (type $t (record (field "f" u32))) - (type $t2 (record (field "f" $t))) - (import "x" (func (param "x" $t2))) - ) - "func not valid to be used as import") - -(assert_invalid - (component - (type $t (resource (rep i32))) - (export "t" (type $t)) - (type $f (list (own $t))) - (export "f" (type $f)) - ) - "type not valid to be used as export") - -;; validate within the type context -(assert_invalid - (component - (type (component - (type $t (record (field "f" u32))) - (export "f" (func (param "x" $t))) - )) - ) - "func not valid to be used as export") -(assert_invalid - (component - (type (component - (type $t (record (field "f" u32))) - (type $f (record (field "t" $t))) - (export "f" (type (eq $f))) - )) - ) - "type not valid to be used as export") - -;; instances of unexported types is ok -(component - (type $t (record (field "f" u32))) - (type $f (record (field "t" $t))) - (instance - (export "f" (type $f)) - ) -) -;; .. but exporting them is not -(assert_invalid - (component - (type $t (record (field "f" u32))) - (type $f (record (field "t" $t))) - (instance $i - (export "f" (type $f)) - ) - (export "i" (instance $i)) - ) - "instance not valid to be used as export") - -;; Can't export a lifted function with unexported types -(assert_invalid - (component - (type $t (record (field "f" u32))) - (type $f (record (field "t" $t))) - - (core module $m (func $f (export "f") (param i32))) - (core instance $i (instantiate $m)) - (func $f (param "f" $f) (canon lift (core func $i "f"))) - (export "f" (func $f)) - ) - "func not valid to be used as export") - -;; Unexported instances don't work -(assert_invalid - (component - (type $t' (record (field "f" u32))) - (instance $i - (export "t" (type $t')) - ) - (alias export $i "t" (type $t)) - - (core module $m (func $f (export "f") (param i32))) - (core instance $i (instantiate $m)) - (func $f (param "f" $t) (canon lift (core func $i "f"))) - (export "f" (func $f)) - ) - "func not valid to be used as export") - -;; Even through a component it doesn't work -(assert_invalid - (component - (component $C - (type $t (record (field "f" u32))) - (export "t" (type $t)) - ) - (instance $i (instantiate $C)) - (alias export $i "t" (type $t)) - - (core module $m (func $f (export "f") (param i32))) - (core instance $i (instantiate $m)) - (func $f (param "f" $t) (canon lift (core func $i "f"))) - (export "f" (func $f)) - ) - "func not valid to be used as export") - -;; through exported instances is ok though -(component - (type $t' (record (field "f" u32))) - (instance $i' - (export "t" (type $t')) - ) - (export $i "i" (instance $i')) - (alias export $i "t" (type $t)) - - (core module $m (func $f (export "f") (param i32))) - (core instance $i (instantiate $m)) - (func $f (param "f" $t) (canon lift (core func $i "f"))) - (export "f" (func $f)) -) -(component - (component $C - (type $t (record (field "f" u32))) - (export "t" (type $t)) - ) - (instance $i' (instantiate $C)) - (export $i "i" (instance $i')) - (alias export $i "t" (type $t)) - - (core module $m (func $f (export "f") (param i32))) - (core instance $i (instantiate $m)) - (func $f (param "f" $t) (canon lift (core func $i "f"))) - (export "f" (func $f)) -) - -;; a type-ascribed export which is otherwise invalid can become valid -(component - (type $t (record (field "f" u32))) - - (core module $m (func (export "f") (param i32))) - (core instance $i (instantiate $m)) - (func $f (param "x" $t) (canon lift (core func $i "f"))) - - (export $t' "t" (type $t)) - (export "f" (func $f) (func (param "x" $t'))) -) - -;; imports can't reference exports -(assert_invalid - (component - (type $t1 (record (field "f" u32))) - (export $t2 "t1" (type $t1)) - (import "i" (func (result $t2))) - ) - "func not valid to be used as import") - -;; exports can reference imports -(component - (type $t1 (record (field "f" u32))) - (import "t1" (type $t2 (eq $t1))) - (export "e-t1" (type $t2)) -) -(component - (component - (type $t1 (record (field "f" u32))) - (import "t1" (type $t2 (eq $t1))) - (import "i" (func $f (result $t2))) - - (export "e-i" (func $f)) - ) -) - -;; outer aliases don't work for imports/exports -(assert_invalid - (component - (type $t1 (record (field "f" u32))) - (import "t1" (type $t2 (eq $t1))) - (component - (import "i" (func $f (result $t2))) - ) - ) - "func not valid to be used as import") -(assert_invalid - (component - (type $t1 (record (field "f" u32))) - (export $t2 "t1" (type $t1)) - (component - (core module $m (func (export "f") (result i32) unreachable)) - (core instance $i (instantiate $m)) - (func $f (export "i") (result $t2) (canon lift (core func $i "f"))) - ) - ) - "func not valid to be used as export") - -;; outer aliases work for components, modules, and resources -(component - (type $c (component)) - (type (component - (import "c" (component (type $c))) - )) - (component - (import "c" (component (type $c))) - ) - (type $i (instance)) - (type (component - (import "c" (instance (type $i))) - )) - - (type $r (resource (rep i32))) - (type (component - (import "r" (type (eq $r))) - )) -) - -;; reexport of an import is fine -(component - (component - (import "r" (func $r)) - (export "r2" (func $r)) - ) -) -(component - (type $t (record (field "f" u32))) - (import "r" (type $r (eq $t))) - (export "r2" (type $r)) -) -(component - (import "r" (instance $r)) - (export "r2" (instance $r)) -) -(component definition - (import "r" (type $r (sub resource))) - (export "r2" (type $r)) -) - -;; bag of exports cannot be exported by carrying through context that's not -;; otherwise exported -(assert_invalid - (component - (component $A - (type $t (record (field "f" u32))) - (export $t2 "t" (type $t)) - (core module $m (func (export "f") (result i32) unreachable)) - (core instance $i (instantiate $m)) - (func $f (result $t2) (canon lift (core func $i "f"))) - - (instance (export "i") - (export "f" (func $f)) - ) - ) - - (instance $a (instantiate $A)) - ;; this component only exports `f`, not the record type that is the result - ;; of `f`, so it should be invalid. - (export "a" (instance $a "i")) - ) - "instance not valid to be used as export") - -;; instance types can be "temporarily invalid", but not if they're attached -;; to a concrete component -(component - (type (instance - (type $t (record (field "f" u32))) - (export "f" (func (param "x" $t))) - )) -) -(assert_invalid - (component - (type $i (instance - (type $t (record (field "f" u32))) - (type $f (record (field "t" $t))) - (export "f" (type (eq $f))) - )) - (import "f" (instance (type $i))) - ) - "instance not valid to be used as import") - -;; allow for one import to refer to another -(component definition $C - (import "foo" (instance $i - (type $baz' (record (field "f" u32))) - (export "baz" (type $baz (eq $baz'))) - (type $bar' (record (field "baz" $baz))) - (export "bar" (type $bar (eq $bar'))) - )) - (alias export $i "bar" (type $bar)) - (import "bar" (instance - (alias outer $C $bar (type $bar')) - (export "bar" (type $bar (eq $bar'))) - (export "a" (func $f (result $bar))) - )) -) - -;; allow for one import to refer to another -(component - (type $r' (record (field "f" u32))) - (import "r" (type $r (eq $r'))) - (component $C - (type $r' (record (field "f" u32))) - (import "r" (type $r (eq $r'))) - (type $r2' (record (field "r" $r))) - (export "r2" (type $r2')) - ) - (instance $c (instantiate $C (with "r" (type $r)))) - (export "r2" (type $c "r2")) -) - -;; types are validated when they are exported -(assert_invalid - (component - (type $i (instance - (type $t (record (field "f" u32))) - (type $f (record (field "t" $t))) - (export "f" (type (eq $f))) - )) - (import "f" (type (eq $i))) - ) - "type not valid to be used as import") -(assert_invalid - (component - (type $i (instance - (type $t (record (field "f" u32))) - (type $f (record (field "t" $t))) - (export "f" (type (eq $f))) - )) - (export "f" (type $i)) - ) - "type not valid to be used as export") - -(assert_invalid - (component - (type $t (record (field "f" u32))) - (type $f (func (result $t))) - (import "f" (type (eq $f))) - ) - "type not valid to be used as import") -(assert_invalid - (component - (type $t (record (field "f" u32))) - (type $f (func (result $t))) - (export "f" (type $f)) - ) - "type not valid to be used as export") - -(component - (type (;0;) - (instance - (type (;0;) (enum "qux")) - (export (;1;) "baz" (type (eq 0))) - (type (;2;) (record (field "bar" 1) )) - (export (;3;) "foo" (type (eq 2))) - ) - ) - (import (interface "demo:component/types") (instance (;0;) (type 0))) - (component - (type (;0;) - (instance - (type (;0;) (enum "qux")) - (export (;1;) "baz" (type (eq 0))) - (type (;2;) (record (field "bar" 1) )) - (export (;3;) "foo" (type (eq 2))) - ) - ) - (import (interface "demo:component/types") (instance (;0;) (type 0))) - (component (;0;) - (type (;0;) (enum "qux")) - (import "import-type-baz" (type (;1;) (eq 0))) - (type (;2;) (record (field "bar" 1) )) - (import "import-type-bar" (type (;3;) (eq 2))) - (export (;4;) "foo" (type 3)) - ) - (instance (;1;) (instantiate 0 - (with "import-type-baz" (type 0 "baz")) - (with "import-type-bar" (type 0 "foo")) - ) - ) - (export (;0;) (interface "demo:component/types") (instance 1)) - ) - (instance (instantiate 0 (with "demo:component/types" (instance 0)))) - (export (interface "demo:component/types") (instance 1 "demo:component/types")) -) diff --git a/test/wasm-tools/types.wast b/test/wasm-tools/types.wast deleted file mode 100644 index 5df1ec9d..00000000 --- a/test/wasm-tools/types.wast +++ /dev/null @@ -1,374 +0,0 @@ -;; RUN: wast --assert default --snapshot tests/snapshots % - -(assert_invalid - (component - (type $t (instance)) - (import "a" (func (type $t))) - ) - "type index 0 is not a function type") - -(assert_invalid - (component - (core type $t (func)) - (import "a" (core module (type $t))) - ) - "core type index 0 is not a module type") - -(assert_invalid - (component - (type $t (func)) - (import "a" (instance (type $t))) - ) - "type index 0 is not an instance type") - -(assert_invalid - (component - (type $t (func)) - (type (component - (import "a" (instance (type $t))) - )) - ) - "type index 0 is not an instance type") - -(assert_invalid - (component - (core type $t (func)) - (type (component - (import "a" (core module (type $t))) - )) - ) - "core type index 0 is not a module type") - -(assert_invalid - (component - (type $t (instance)) - (type (component - (import "a" (func (type $t))) - )) - ) - "type index 0 is not a function type") - -(assert_invalid - (component - (export "a" (core module 0)) - ) - "module index out of bounds") - -(assert_invalid - (component - (export "a" (instance 0)) - ) - "instance index out of bounds") - -(assert_invalid - (component - (core type (module - (export "a" (func (type 0))) - )) - ) - "type index out of bounds") - -(assert_invalid - (component - (core type (module - (export "a" (func)) - (export "a" (func)) - )) - ) - "export name `a` already defined") - -(assert_invalid - (component - (core type (module - (import "" "" (func)) - (import "" "" (func)) - )) - ) - "duplicate import name") - -(assert_invalid - (component - (core type (module - (import "" "" (memory 70000)) - )) - ) - "memory size must be at most") - -(assert_invalid - (component - (type (component - (export "a" (func (type 0))) - )) - ) - "type index out of bounds") - -(assert_invalid - (component - (type (component - (export "a" (func)) - (export "A" (func)) - )) - ) - "export name `A` conflicts with previous name `a`") - -(assert_invalid - (component - (type (component - (import "A" (func)) - (import "a" (func)) - )) - ) - "import name `a` conflicts with previous name `A`") - -(assert_malformed - (component quote - "(component $c (core type $t (module (alias outer $c $t (type)))))" - ) - "unknown core type") - -(assert_invalid - (component - (core type (module - (alias outer 1 0 (type)) - )) - ) - "type index out of bounds") - -(component $c - (core type $f (func)) - (core type $t (module - (alias outer $c $f (type)) - )) -) - -(assert_malformed - (component quote - "(component $c (type $t (component (alias outer $c $t (type)))))" - ) - "unknown type") - -(assert_invalid - (component - (type (component - (alias outer 1 0 (type)) - )) - ) - "type index out of bounds") - -(assert_invalid - (component $c - (type $f (func)) - (type $t (component - (alias outer 100 0 (type)) - )) - ) - "invalid outer alias count of 100") - -(assert_invalid - (component $c - (type $f (func)) - (type $t (component - (core type (module - (export "" (func)) - (export "" (func)) - )) - )) - ) - "name `` already defined") - -(assert_invalid - (component - (type (instance - (export "" (func (type 0))) - )) - ) - "type index out of bounds") - -(assert_invalid - (component - (type (instance - (export "foo-BAR-baz" (func)) - (export "FOO-bar-BAZ" (func)) - )) - ) - "export name `FOO-bar-BAZ` conflicts with previous name `foo-BAR-baz`") - -(assert_malformed - (component quote - "(component $c (type $t (instance (alias outer $c $t (type)))))" - ) - "unknown type") - -(assert_invalid - (component - (type (instance - (alias outer 1 0 (type)) - )) - ) - "type index out of bounds") - -(assert_invalid - (component $c - (type $f (func)) - (type $t (instance - (alias outer 100 0 (type)) - )) - ) - "invalid outer alias count of 100") - -(assert_invalid - (component $c - (type $f (func)) - (type $t (instance - (core type (module - (export "" (func)) - (export "" (func)) - )) - )) - ) - "name `` already defined") - -(assert_invalid - (component $c - (type $f (func (param "" string))) - ) - "function parameter name cannot be empty") - -(component - (type $t (func (result (tuple (list u8) u32)))) -) - -(component $C - (core type $t (func)) - (core type (module - (alias outer $C $t (type $a)) - (import "" "" (func (type $a))) - )) -) - -(component $C - (component $C2 - (core type $t (func)) - (core type (module - (alias outer $C2 $t (type $a)) - (import "" "" (func (type $a))) - )) - ) -) - -(component $C - (core type $t (func)) - (component $C2 - (core type (module - (alias outer $C $t (type $a)) - (import "" "" (func (type $a))) - )) - ) -) - -(component - (type (instance - (type string) - (export "a" (type (eq 0))) - )) -) - -(component - (type (component - (type string) - (import "a" (type (eq 0))) - (export "b" (type (eq 0))) - )) -) - -(assert_invalid - (component - (type (variant)) - ) - "variant type must have at least one case") - -(assert_invalid - (component - (type (enum)) - ) - "enum type must have at least one variant") - -(assert_invalid - (component - (type (record)) - ) - "record type must have at least one field") - -(assert_invalid - (component - (type (flags)) - ) - "flags must have at least one entry") - -(assert_invalid - (component - (type (tuple)) - ) - "tuple type must have at least one type") - -(component $c - (core type $f (func)) - (component $c2 - (core type $t (module - (alias outer $c $f (type)) - )) - ) -) - -(assert_invalid - (component - (type (flags - "f1" - "f2" - "f3" - "f4" - "f5" - "f6" - "f7" - "f8" - "f9" - "f10" - "f11" - "f12" - "f13" - "f14" - "f15" - "f16" - "f17" - "f18" - "f19" - "f20" - "f21" - "f22" - "f23" - "f24" - "f25" - "f26" - "f27" - "f28" - "f29" - "f30" - "f31" - "f32" - "f33" - )) - ) - "cannot have more than 32 flags") - -(assert_invalid - (component - (core type $t (module)) - (core type (func (param (ref $t)))) - ) - "type index 0 is a module type") - -(assert_invalid - (component - (core type (func (param (ref 100)))) - ) - "type index out of bounds") diff --git a/test/wasm-tools/very-nested.wast b/test/wasm-tools/very-nested.wast deleted file mode 100644 index 42c5aede..00000000 --- a/test/wasm-tools/very-nested.wast +++ /dev/null @@ -1,1954 +0,0 @@ -;; RUN: wast --assert default --snapshot tests/snapshots % - -(assert_invalid - (component $$esl - (component - (export "c t.*************") - (export "00AG") - (component - (export "c 3@EGG*****+*****e $$qq") - ) - (component - (export "q**") - (export "00AGG554M******+*****e 4$qq") - ) - (component - (export "q**") - (export "dojgn-ejs9-nd188") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "sdg-q12") - ) - (component - (export "c t.*************") - (export "00AG") - (component - (export "c 3@EGG*****+*****e $$qq") - ) - (component - (export "q**") - (export "dojgn-ejs9-nd188") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "bsdew2-sdbsdb") - ) - (component - (export "c=t.*************") - (export "00AG") - (component - (export "alskgn-mbnaj4-a33i5nf") - (export "dojgn-ejs9-nd188") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "jsjsjs") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "anonmm-x23foinas-ASDOJASD") - ) - (component - (export "c t.****0*********") - (export "00AG") - (component - (export "c 3@EGG*****+*****e $$qq") - ) - (component - (export "q**") - (export "dojgn-ejs9-nd188") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "bsdew2-sdbsdb") - ) - (component - (export "c=t.*************") - (export "00AG") - (component - (export "alskgn-mbnaj4-a33i5nf") - (export "dojgn-ejs9-nd188") - ) - (component - (export "q") - ) - (component - (export "afhinds-T39OIDN-f1jsj11") - (import "sf-gqo3ngin23ogin13g-bvcad") - ) - (component - (export "EGG-y-GG-qq") - (export "agds-ASF-TT-yy") - ) - (component - (export "q") - ) - (component - (export "b 3@E*******************") - (import "bsdew2-sdbsdb") - ) - (component - (export "c 0.*************") - (export "00AGGWGle A*$$qq") - ) - (component) - ) - (component - (export "q") - ) - (component - (export "c 3@E*********GG$qq**") - (export "dojgn-ejs9-nd188") - ) - (component - (export "q") - ) - (component - (export "c 3@E************[******") - (import "bsdew2-sdbsdb") - ) - (component - (export "c t.*************") - (export "00AGGGGle *$$qq") - ) - (component) - ) - (component - (export "q") - ) - (component - (export "c 3@E$*************7777777777777777777777777777777777777777777MM~MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM777777777777777777777777777777777777777777*****") - (import "00e*$$qq") - ) - (component - (export "EGG-y-GG-qq") - (export "0+AGGG.Gle $$qq") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "00A$qq") - ) - (component - (export "c t.*************") - (export "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG00AGGGGle *$$qq") - ) - (component) - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "15AG:GG!le*$$qq") - ) - (component - (export "c t.*") - (component - (export "c 3@EGGGG$qq**") - (export "bsdew2-sdbsdb") - ) - (component - (export "c t.********)*eleo &m Nx2GGGGle*$$qq") - ) - (component - (export "c 1.*************") - (export "00AGGGGle A*$$qq") - ) - (component) - ) - (component - (export "q") - ) - (component - (export "c Gle $$qq") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "sdg-q12") - ) - (component - (export "c t.*************") - (export "00AG") - (component - (export "c 3@EGG*****+*****e $$qq") - ) - (component - (export "q**") - (export "dojgn-ejs9-nd188") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "bsdew2-sdbsdb") - ) - (component - (export "c=t.*************") - (export "00AG") - (component - (export "alskgn-mbnaj4-a33i5nf") - (export "dojgn-ejs9-nd188") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "jsjsjs") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "bsdew2-sdbsdb") - ) - (component - (export "c t.*************") - (export "0*************") - (import "bsdew2-sdbsdb") - ) - (component - (export "c t.*************") - (export "00AG") - (component - (export "c 3@EGG*****+*****e $$qq") - ) - (component - (export "q**") - (export "00AGG554M******+*****e 4$qq") - ) - (component - (export "q**") - (export "dojgn-ejs9-nd188") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "sdg-q12") - ) - (component - (export "c t.*************") - (export "00AG") - (component - (export "c 3@EGG*****+*****e $$qq") - ) - (component - (export "q**") - (export "dojgn-ejs9-nd188") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "bsdew2-sdbsdb") - ) - (component - (export "c=t.*************") - (export "00AG") - (component - (export "alskgn-mbnaj4-a33i5nf") - (export "dojgn-ejs9-nd188") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "jsjsjs") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "anonmm-x23foinas-ASDOJASD") - ) - (component - (export "c t.****0*********") - (export "00AG") - (component - (export "c 3@EGG*****+*****e $$qq") - ) - (component - (export "q**") - (export "dojgn-ejs9-nd188") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "bsdew2-sdbsdb") - ) - (component - (export "c=t.*************") - (export "00AG") - (component - (export "alskgn-mbnaj4-a33i5nf") - (export "dojgn-ejs9-nd188") - ) - (component - (export "q") - ) - (component - (export "afhinds-T39OIDN-f1jsj11") - (import "sf-gqo3ngin23ogin13g-bvcad") - ) - (component - (export "EGG-y-GG-qq") - (export "agds-ASF-TT-yy") - ) - (component - (export "q") - ) - (component - (export "b 3@E*******************") - (import "bsdew2-sdbsdb") - ) - (component - (export "c 0.*************") - (export "00AGGWGle A*$$qq") - ) - (component) - ) - (component - (export "q") - ) - (component - (export "c 3@E*********GG$qq**") - (export "dojgn-ejs9-nd188") - ) - (component - (export "q") - ) - (component - (export "c 3@E************[******") - (import "bsdew2-sdbsdb") - ) - (component - (export "c t.*************") - (export "00AGGGGle *$$qq") - ) - (component) - ) - (component - (export "q") - ) - (component - (export "c 3@E$*************7777777777777777777777777777777777777777777MM~MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM777777777777777777777777777777777777777777*****") - (import "00e*$$qq") - ) - (component - (export "EGG-y-GG-qq") - (export "0+AGGG.Gle $$qq") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "00A$qq") - ) - (component - (export "c t.*************") - (export "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG00AGGGGle *$$qq") - ) - (component) - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "15AG:GG!le*$$qq") - ) - (component - (export "c .t*") - (component - (export "c 3@EGGGG$qq**") - (export "bsdew2-sdbsdb") - ) - (component - (export "c t.********)*eleo &m Nx2GGGGle*$$qq") - ) - (component - (export "c 1.*************") - (export "00AGGGGle A*$$qq") - ) - (component) - ) - (component - (export "q") - ) - (component - (export "c Gle $$qq") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "sdg-q12") - ) - (component - (export "c t.*************") - (export "00AG") - (component - (export "c 3@EGG*****+*****e $$qq") - ) - (component - (export "q**") - (export "dojgn-ejs9-nd188") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "bsdew2-sdbsdb") - ) - (component - (export "c=t.*************") - (export "00AG") - (component - (export "alskgn-mbnaj4-a33i5nf") - (export "dojgn-ejs9-nd188") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "jsjsjs") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "bsdew2-sdbsdb") - ) - (component - (export "c t.*************") - (export "00AG") - (component - (export "c 3@EGG*****+*****e $$qq") - ) - (component - (export "q**") - (export "dojgn-ejs9-nd188") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "bsdew2-sdbsdb") - ) - (component - (export "c=t.*************") - (export "00AG") - (component - (export "alskgn-mbnaj4-a33i5nf") - (export "dojgn-ejs9-nd188") - ) - (component - (export "q") - ) - (component - (export "afhinds-T39OIDN-f1jsj11") - (import "sf-gqo3ngin23ogin13g-bvcad") - ) - (component - (export "EGG-y-GG-qq") - (export "00AGGG.Gle '$$qq") - ) - (component - (export "q") - ) - (component - (export "b 3@E*******************") - (import "bsdew2-sdbsdb") - ) - (component - (export "c 0.*************") - (export "00AGGWGle A*$$qq") - ) - (component) - ) - (component - (export "q") - ) - (component - (export "c 3@E*********GG$qq**") - (export "dojgn-ejs9-nd188") - ) - (component - (export "q") - ) - (component - (export "c 3@E************[******") - (import "bsdew2-sdbsdb") - ) - (component - (export "c t.*************") - (export "00AGGGGle *$$qq") - ) - (component) - ) - (component - (export "q") - ) - (component - (export "c 6@E$*************7777777777777777777777777777777777777777777MM~MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM777777777777777777777777777777777777777777*****") - (import "00e*$$qq") - ) - (component - (export "EGG-y-GG-qq") - (export "00AGGG.Gle $$qq") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "bsdew2-sdbsdb") - ) - (component - (export "c *****") - (export "00AG") - (component - (export "c 3@EGG*****+*****e $$qq") - ) - (component - (export "q**") - (export "00AGG554M******+*****e 4$qq") - ) - (component - (export "q**") - (export "dojgn-ejs9-nd188") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "sdg-q12") - ) - (component - (export "c t.*************") - (export "00AG") - (component - (export "c 3@EGG*****+*****e $$qq") - ) - (component - (export "q**") - (export "dojgn-ejs9-nd188") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "bsdew2-sdbsdb") - ) - (component - (export "c=t.*************") - (export "00AG") - (component - (export "alskgn-mbnaj4-a33i5nf") - (export "dojgn-ejs9-nd188") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "jsjsjs") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "anonmm-x23foinas-ASDOJASD") - ) - (component - (export "c t.****0*********") - (export "00AG") - (component - (export "c 3@EGG*****+*****e $$qq") - ) - (component - (export "q**") - (export "dojgn-ejs9-nd188") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "bsdew2-sdbsdb") - ) - (component - (export "c=t.*************") - (export "00AG") - (component - (export "alskgn-mbnaj4-a33i5nf") - (export "dojgn-ejs9-nd188") - ) - (component - (export "q") - ) - (component - (export "afhinds-T39OIDN-f1jsj11") - (import "sf-gqo3ngin23ogin13g-bvcad") - ) - (component - (export "EGG-y-GG-qq") - (export "agds-ASF-TT-yy") - ) - (component - (export "q") - ) - (component - (export "b 3@E*******************") - (import "bsdew2-sdbsdb") - ) - (component - (export "c 0.*************") - (export "00AGGWGle A*$$qq") - ) - (component) - ) - (component - (export "q") - ) - (component - (export "c 3@E*********GG$qq**") - (export "dojgn-ejs9-nd188") - ) - (component - (export "q") - ) - (component - (export "c 3@E************[******") - (import "bsdew2-sdbsdb") - ) - (component - (export "c t.*************") - (export "00AGGGGle *$$qq") - ) - (component) - ) - (component - (export "q") - ) - (component - (export "c 3@E$*************7777777777777777777777777777777777777777777MM~MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM777777777777777777777777777777777777777777*****") - (import "00e*$$qq") - ) - (component - (export "EGG-y-GG-qq") - (export "0+AGGG.Gle $$qq") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "00A$qq") - ) - (component - (export "c t.*************") - (export "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG00AGGGGle *$$qq") - ) - (component) - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "15AG:GG!le*$$qq") - ) - (component - (export "c t.*") - (component - (export "c 3@EGGGG$qq**") - (export "bsdew2-sdbsdb") - ) - (component - (export "c t.********)*eleo &m Nx2GGGGle*$$qq") - ) - (component - (export "c 1.*************") - (export "00AGGGGle A*$$qq") - ) - (component) - ) - (component - (export "q") - ) - (component - (export "c Gle $$qq") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "sdg-q12") - ) - (component - (export "c t.*************") - (export "00AG") - (component - (export "c 3@EGG*****+*****e $$qq") - ) - (component - (export "q**") - (export "dojgn-ejs9-nd188") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "bsdew2-sdbsdb") - ) - (component - (export "c=t.*************") - (export "00AG") - (component - (export "alskgn-mbnaj4-a33i5nf") - (export "dojgn-ejs9-nd188") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "jsjsjs") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "bsdew2-sdbsdb") - ) - (component - (export "c t.*************") - (export "0*************") - (import "bsdew2-sdbsdb") - ) - (component - (export "c t.*************") - (export "00AG") - (component - (export "c 3@EGG*****+*****e $$qq") - ) - (component - (export "q**") - (export "00AGG554M******+*****e 4$qq") - ) - (component - (export "q**") - (export "dojgn-ejs9-nd188") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "sdg-q12") - ) - (component - (export "c t.*************") - (export "00AG") - (component - (export "c 3@EGG*****+*****e $$qq") - ) - (component - (export "q**") - (export "dojgn-ejs9-nd188") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "bsdew2-sdbsdb") - ) - (component - (export "c=t.*************") - (export "00AG") - (component - (export "alskgn-mbnaj4-a33i5nf") - (export "dojgn-ejs9-nd188") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "jsjsjs") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "anonmm-x23foinas-ASDOJASD") - ) - (component - (export "c t.****0*********") - (export "00AG") - (component - (export "c 3@EGG*****+*****e $$qq") - ) - (component - (export "q**") - (export "dojgn-ejs9-nd188") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "bsdew2-sdbsdb") - ) - (component - (export "c=t.*************") - (export "00AG") - (component - (export "alskgn-mbnaj4-a33i5nf") - (export "dojgn-ejs9-nd188") - ) - (component - (export "q") - ) - (component - (export "afhinds-T39OIDN-f1jsj11") - (import "sf-gqo3ngin23ogin13g-bvcad") - ) - (component - (export "EGG-y-GG-qq") - (export "agds-ASF-TT-yy") - ) - (component - (export "q") - ) - (component - (export "b 3@E*******************") - (import "bsdew2-sdbsdb") - ) - (component - (export "c 0.*************") - (export "00AGGWGle A*$$qq") - ) - (component) - ) - (component - (export "q") - ) - (component - (export "c 3@E*********GG$qq**") - (export "dojgn-ejs9-nd188") - ) - (component - (export "q") - ) - (component - (export "c 3@E************[******") - (import "bsdew2-sdbsdb") - ) - (component - (export "c t.*************") - (export "00AGGGGle *$$qq") - ) - (component) - ) - (component - (export "q") - ) - (component - (export "c 3@E$*************7777777777777777777777777777777777777777777MM~MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM777777777777777777777777777777777777777777*****") - (import "00e*$$qq") - ) - (component - (export "EGG-y-GG-qq") - (export "0+AGGG.Gle $$qq") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "00A$qq") - ) - (component - (export "c t.*************") - (export "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG00AGGGGle *$$qq") - ) - (component) - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "15AG:GG!le*$$qq") - ) - (component - (export "c .t*") - (component - (export "c 3@EGGGG$qq**") - (export "bsdew2-sdbsdb") - ) - (component - (export "c t.********)*eleo &m Nx2GGGGle*$$qq") - ) - (component - (export "c 1.*************") - (export "00AGGGGle A*$$qq") - ) - (component) - ) - (component - (export "q") - ) - (component - (export "c Gle $$qq") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "sdg-q12") - ) - (component - (export "c t.*************") - (export "00AG") - (component - (export "c 3@EGG*****+*****e $$qq") - ) - (component - (export "q**") - (export "dojgn-ejs9-nd188") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "bsdew2-sdbsdb") - ) - (component - (export "c=t.*************") - (export "00AG") - (component - (export "alskgn-mbnaj4-a33i5nf") - (export "dojgn-ejs9-nd188") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "jsjsjs") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "bsdew2-sdbsdb") - ) - (component - (export "c t.*************") - (export "00AG") - (component - (export "c 3@EGG*****+*****e $$qq") - ) - (component - (export "q**") - (export "dojgn-ejs9-nd188") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "bsdew2-sdbsdb") - ) - (component - (export "c=t.*************") - (export "00AG") - (component - (export "alskgn-mbnaj4-a33i5nf") - (export "dojgn-ejs9-nd188") - ) - (component - (export "q") - ) - (component - (export "afhinds-T39OIDN-f1jsj11") - (import "sf-gqo3ngin23ogin13g-bvcad") - ) - (component - (export "EGG-y-GG-qq") - (export "00AGGG.Gle '$$qq") - ) - (component - (export "q") - ) - (component - (export "b 3@E*******************") - (import "bsdew2-sdbsdb") - ) - (component - (export "c 0.*************") - (export "00AGGWGle A*$$qq") - ) - (component) - ) - (component - (export "q") - ) - (component - (export "c 3@E*********GG$qq**") - (export "dojgn-ejs9-nd188") - ) - (component - (export "q") - ) - (component - (export "c 3@E************[******") - (import "bsdew2-sdbsdb") - ) - (component - (export "c t.*************") - (export "00AGGGGle *$$qq") - ) - (component) - ) - (component - (export "q") - ) - (component - (export "c 6@E$*************7777777777777777777777777777777777777777777MM~MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM777777777777777777777777777777777777777777*****") - (import "00e*$$qq") - ) - (component - (export "EGG-y-GG-qq") - (export "00AGGG.Gle $$qq") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "bsdew2-sdbsdb") - ) - (component - (export "c 1.*************") - (export "00AGGGGle A*$$qq") - ) - (component) - ) - (component - (export "q") - ) - (component - (export "c 4@E****\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*****GG$qq**") - (export "dojgn-ejs9-nd188") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "00CGGGGle*$$qq") - ) - (component - (export "c t.*************") - (export "00AGGGGle *$$qq") - ) - (component) - ) - (component - (export "q") - ) - (component - (export "c 3@E*******77777777777777777777777777777777GG)le 0AGGGGle $$qq") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "00CGGGGle*$$qq") - ) - (component - (export "c t.*************") - (export "00AGGGGl4@E****\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*****GG$qq**") - (export "dojgn-ejs9-nd188") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "00CGGGGle*$$qq") - ) - (component - (export "c t.*************") - (export "00AGGGGle *$$qq") - ) - (component) - ) - (component - (export "q") - ) - (component - (export "c 3@E*******77777777777777777777777777777777GG)le 0AGGGGle $$qq") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "00CGGGGle*$$qq") - ) - (component - (export "c t.*************") - (export "00AGGGGle *$$qq") - ) - (component) - ) - (component - (export "q") - ) - (component - (export "c 3@E***0AG") - (component - (export "c 3@EGG*****+*****e $$qq") - ) - (component - (export "q**") - (export "dojgn-ejs9-nd188") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "bsdew2-sdbsdb") - ) - (component - (export "c=t.*************") - (export "00AG") - (component - (export "alskgn-mbnaj4-a33i5nf") - (export "dojgn-ejs9-nd188") - ) - (component - (export "q") - ) - (component - (export "afhinds-T39OIDN-f1jsj11") - (import "sf-gqo3ngin23ogin13g-bvcad") - ) - (component - (export "EGG-y-GG-qq") - (export "00AGGG.Gle '$$qq") - ) - (component - (export "q") - ) - (component - (export "b 3@E*******************") - (import "bsdew2-sdbsdb") - ) - (component - (export "c 0.*************") - (export "00AGGWGle A*$$qq") - ) - (component) - ) - (component - (export "q") - ) - (component - (export "c 3@E*********GG$qq**") - (export "dojgn-ejs9-nd188") - ) - (component - (export "q") - ) - (component - (export "c 3@E************[******") - (import "bsdew2-sdbsdb") - ) - (component - (export "c t.*************") - (export "00AGGGGle *$$qq") - ) - (component) - ) - (component - (export "q") - ) - (component - (export "c 6@E$*************7777777777777777777777777777777777777777777MM~MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM777777777777777777777777777777777777777777*****") - (import "00e*$$qq") - ) - (component - (export "EGG-y-GG-qq") - (export "00AGGG.Gle $$qq") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "bsdew2-sdbsdb") - ) - (component - (export "c 1.*************") - (export "00AGGGGle A*$$qq") - ) - (component) - ) - (component - (export "q") - ) - (component - (export "c 4@E****\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*****GG$qq**") - (export "dojgn-ejs9-nd188") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "00CGGGGle*$$qq") - ) - (component - (export "c t.*************") - (export "00AGGGGle *$$qq") - ) - (component) - ) - (component - (export "q") - ) - (component - (export "c 3@E*******77777777777777777777777777777777GG)le 0AGGGGle $$qq") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "00CGGGGle*$$qq") - ) - (component - (export "c t.*************") - (export "00AGGGGl4@E****\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*****GG$qq**") - (export "dojgn-ejs9-nd188") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "00CGGGGle*$$qq") - ) - (component - (export "c t.*************") - (export "00AGGGGle *$$qq") - ) - (component) - ) - (component - (export "q") - ) - (component - (export "c 3@E*******77777777777777777777777777777777GG)le 0AGGGGle $$qq") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "00CGGGGle*$$qq") - ) - (component - (export "c t.*************") - (export "00AGGGGle *$$qq") - ) - (component) - ) - (component - (export "q") - ) - (component - (export "c 3@E**************777777777777777777777777777777777777777777777777777777777777771.*************") - (export "00AGGGGle A*$$qq") - ) - (component) - ) - (component - (export "q") - ) - (component - (export "c 4@E****\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*****GG$qq**") - (export "dojgn-ejs9-nd188") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "00CGGGGle*$$qq") - ) - (component - (export "c t.*************") - (export "00AGGGGle *$$qq") - ) - (component) - ) - (component - (export "q") - ) - (component - (export "c 3@E*******77777777777777777777777777777777GG)le 0AGGGGle $$qq") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "00CGGGGle*$$qq") - ) - (component - (export "c t.*************") - (export "00AGGGGl4@E****\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*****GG$qq**") - (export "dojgn-ejs9-nd188") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "00CGGGGle*$$qq") - ) - (component - (export "c t.*************") - (export "00AGGGGle *$$qq") - ) - (component) - ) - (component - (export "q") - ) - (component - (export "c 3@E*******77777777777777777777777777777777GG)le 0AGGGGle $$qq") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "00CGGGGle*$$qq") - ) - (component - (export "c t.*************") - (export "00AGGGGle *$$qq") - ) - (component) - ) - (component - (export "q") - ) - (component - (export "c 3@E***0AG") - (component - (export "c 3@EGG*****+*****e $$qq") - ) - (component - (export "q**") - (export "dojgn-ejs9-nd188") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "bsdew2-sdbsdb") - ) - (component - (export "c=t.*************") - (export "00AG") - (component - (export "alskgn-mbnaj4-a33i5nf") - (export "dojgn-ejs9-nd188") - ) - (component - (export "q") - ) - (component - (export "afhinds-T39OIDN-f1jsj11") - (import "sf-gqo3ngin23ogin13g-bvcad") - ) - (component - (export "EGG-y-GG-qq") - (export "00AGGG.Gle '$$qq") - ) - (component - (export "q") - ) - (component - (export "b 3@E*******************") - (import "bsdew2-sdbsdb") - ) - (component - (export "c 0.*************") - (export "00AGGWGle A*$$qq") - ) - (component) - ) - (component - (export "q") - ) - (component - (export "c 3@E*********GG$qq**") - (export "dojgn-ejs9-nd188") - ) - (component - (export "q") - ) - (component - (export "c 3@E************[******") - (import "bsdew2-sdbsdb") - ) - (component - (export "c t.*************") - (export "00AGGGGle *$$qq") - ) - (component) - ) - (component - (export "q") - ) - (component - (export "c 6@E$*************7777777777777777777777777777777777777777777MM~MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM777777777777777777777777777777777777777777*****") - (import "00e*$$qq") - ) - (component - (export "EGG-y-GG-qq") - (export "00AGGG.Gle $$qq") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "bsdew2-sdbsdb") - ) - (component - (export "c 1.*************") - (export "00AGGGGle A*$$qq") - ) - (component) - ) - (component - (export "q") - ) - (component - (export "c 4@E****\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*****GG$qq**") - (export "dojgn-ejs9-nd188") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "00CGGGGle*$$qq") - ) - (component - (export "c t.*************") - (export "00AGGGGle *$$qq") - ) - (component) - ) - (component - (export "q") - ) - (component - (export "c 3@E*******77777777777777777777777777777777GG)le 0AGGGGle $$qq") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "00CGGGGle*$$qq") - ) - (component - (export "c t.*************") - (export "00AGGGGl4@E****\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*****GG$qq**") - (export "dojgn-ejs9-nd188") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "00CGGGGle*$$qq") - ) - (component - (export "c t.*************") - (export "00AGGGGle *$$qq") - ) - (component) - ) - (component - (export "q") - ) - (component - (export "c 3@E*******77777777777777777777777777777777GG)le 0AGGGGle $$qq") - ) - (component - (export "q") - ) - (component - (export "c 3@E*******************") - (import "00CGGGGle*$$qq") - ) - (component - (export "c t.*************") - (export "00AGGGGle *$$qq") - ) - (component) - ) - ) - "conflicts with previous name") - -(assert_invalid - (component - (type $m0 (component)) - (type $m1 (component - (import "i1" (component (type $m0))) - (import "i2" (component (type $m0))) - (import "i3" (component (type $m0))) - (import "i4" (component (type $m0))) - (import "i5" (component (type $m0))) - (import "i6" (component (type $m0))) - (import "i7" (component (type $m0))) - (import "i8" (component (type $m0))) - (import "i9" (component (type $m0))) - (import "i10" (component (type $m0))) - )) - (type $m2 (component - (import "i1" (component (type $m1))) - (import "i2" (component (type $m1))) - (import "i3" (component (type $m1))) - (import "i4" (component (type $m1))) - (import "i5" (component (type $m1))) - (import "i6" (component (type $m1))) - (import "i7" (component (type $m1))) - (import "i8" (component (type $m1))) - (import "i9" (component (type $m1))) - (import "i10" (component (type $m1))) - )) - (type $m3 (component - (import "i1" (component (type $m2))) - (import "i2" (component (type $m2))) - (import "i3" (component (type $m2))) - (import "i4" (component (type $m2))) - (import "i5" (component (type $m2))) - (import "i6" (component (type $m2))) - (import "i7" (component (type $m2))) - (import "i8" (component (type $m2))) - (import "i9" (component (type $m2))) - (import "i10" (component (type $m2))) - )) - (type $m4 (component - (import "i1" (component (type $m3))) - (import "i2" (component (type $m3))) - (import "i3" (component (type $m3))) - (import "i4" (component (type $m3))) - (import "i5" (component (type $m3))) - (import "i6" (component (type $m3))) - (import "i7" (component (type $m3))) - (import "i8" (component (type $m3))) - (import "i9" (component (type $m3))) - (import "i10" (component (type $m3))) - )) - (type $m5 (component - (import "i1" (component (type $m4))) - (import "i2" (component (type $m4))) - (import "i3" (component (type $m4))) - (import "i4" (component (type $m4))) - (import "i5" (component (type $m4))) - (import "i6" (component (type $m4))) - (import "i7" (component (type $m4))) - (import "i8" (component (type $m4))) - (import "i9" (component (type $m4))) - (import "i10" (component (type $m4))) - )) - (type $m6 (component - (import "i1" (component (type $m5))) - (import "i2" (component (type $m5))) - (import "i3" (component (type $m5))) - (import "i4" (component (type $m5))) - (import "i5" (component (type $m5))) - (import "i6" (component (type $m5))) - (import "i7" (component (type $m5))) - (import "i8" (component (type $m5))) - (import "i9" (component (type $m5))) - (import "i10" (component (type $m5))) - )) - (type $m7 (component - (import "i1" (component (type $m6))) - (import "i2" (component (type $m6))) - (import "i3" (component (type $m6))) - (import "i4" (component (type $m6))) - (import "i5" (component (type $m6))) - (import "i6" (component (type $m6))) - (import "i7" (component (type $m6))) - (import "i8" (component (type $m6))) - (import "i9" (component (type $m6))) - (import "i10" (component (type $m6))) - )) - (type $m8 (component - (import "i1" (component (type $m7))) - (import "i2" (component (type $m7))) - (import "i3" (component (type $m7))) - (import "i4" (component (type $m7))) - (import "i5" (component (type $m7))) - (import "i6" (component (type $m7))) - (import "i7" (component (type $m7))) - (import "i8" (component (type $m7))) - (import "i9" (component (type $m7))) - (import "i10" (component (type $m7))) - )) - (type $m9 (component - (import "i1" (component (type $m8))) - (import "i2" (component (type $m8))) - (import "i3" (component (type $m8))) - (import "i4" (component (type $m8))) - (import "i5" (component (type $m8))) - (import "i6" (component (type $m8))) - (import "i7" (component (type $m8))) - (import "i8" (component (type $m8))) - (import "i9" (component (type $m8))) - (import "i10" (component (type $m8))) - )) - - (type $m (component - (import "a" (component (type $m9))) - )) - (import "a" (component $a (type $m9))) - (import "b" (component $b (type $m))) - (instance (instantiate $b (with "a" (component $a)))) - ) - "effective type size exceeds the limit") - -(assert_invalid - (component - (component $m0) - (component $m1 - (instance (export "e0") (instantiate $m0)) - (instance (export "e1") (instantiate $m0)) - (instance (export "e2") (instantiate $m0)) - (instance (export "e3") (instantiate $m0)) - (instance (export "e4") (instantiate $m0)) - (instance (export "e5") (instantiate $m0)) - (instance (export "e6") (instantiate $m0)) - (instance (export "e7") (instantiate $m0)) - (instance (export "e8") (instantiate $m0)) - (instance (export "e9") (instantiate $m0)) - ) - (component $m2 - (instance (export "e0") (instantiate $m1)) - (instance (export "e1") (instantiate $m1)) - (instance (export "e2") (instantiate $m1)) - (instance (export "e3") (instantiate $m1)) - (instance (export "e4") (instantiate $m1)) - (instance (export "e5") (instantiate $m1)) - (instance (export "e6") (instantiate $m1)) - (instance (export "e7") (instantiate $m1)) - (instance (export "e8") (instantiate $m1)) - (instance (export "e9") (instantiate $m1)) - ) - (component $m3 - (instance (export "e0") (instantiate $m2)) - (instance (export "e1") (instantiate $m2)) - (instance (export "e2") (instantiate $m2)) - (instance (export "e3") (instantiate $m2)) - (instance (export "e4") (instantiate $m2)) - (instance (export "e5") (instantiate $m2)) - (instance (export "e6") (instantiate $m2)) - (instance (export "e7") (instantiate $m2)) - (instance (export "e8") (instantiate $m2)) - (instance (export "e9") (instantiate $m2)) - ) - (component $m4 - (instance (export "e0") (instantiate $m3)) - (instance (export "e1") (instantiate $m3)) - (instance (export "e2") (instantiate $m3)) - (instance (export "e3") (instantiate $m3)) - (instance (export "e4") (instantiate $m3)) - (instance (export "e5") (instantiate $m3)) - (instance (export "e6") (instantiate $m3)) - (instance (export "e7") (instantiate $m3)) - (instance (export "e8") (instantiate $m3)) - (instance (export "e9") (instantiate $m3)) - ) - (component $m5 - (instance (export "e0") (instantiate $m4)) - (instance (export "e1") (instantiate $m4)) - (instance (export "e2") (instantiate $m4)) - (instance (export "e3") (instantiate $m4)) - (instance (export "e4") (instantiate $m4)) - (instance (export "e5") (instantiate $m4)) - (instance (export "e6") (instantiate $m4)) - (instance (export "e7") (instantiate $m4)) - (instance (export "e8") (instantiate $m4)) - (instance (export "e9") (instantiate $m4)) - ) - (component $m6 - (instance (export "e0") (instantiate $m5)) - (instance (export "e1") (instantiate $m5)) - (instance (export "e2") (instantiate $m5)) - (instance (export "e3") (instantiate $m5)) - (instance (export "e4") (instantiate $m5)) - (instance (export "e5") (instantiate $m5)) - (instance (export "e6") (instantiate $m5)) - (instance (export "e7") (instantiate $m5)) - (instance (export "e8") (instantiate $m5)) - (instance (export "e9") (instantiate $m5)) - ) - (component $m7 - (instance (export "e0") (instantiate $m6)) - (instance (export "e1") (instantiate $m6)) - (instance (export "e2") (instantiate $m6)) - (instance (export "e3") (instantiate $m6)) - (instance (export "e4") (instantiate $m6)) - (instance (export "e5") (instantiate $m6)) - (instance (export "e6") (instantiate $m6)) - (instance (export "e7") (instantiate $m6)) - (instance (export "e8") (instantiate $m6)) - (instance (export "e9") (instantiate $m6)) - ) - ) - "effective type size exceeds the limit") - -(assert_invalid - (component - ;; size(t0) == 1 - (type $t0 (flags "x")) - - ;; size(t1) == 10 - (type $t1 (record - (field "f0" $t0) - (field "f1" $t0) - (field "f2" $t0) - (field "f3" $t0) - (field "f4" $t0) - (field "f5" $t0) - (field "f6" $t0) - (field "f7" $t0) - (field "f8" $t0) - (field "f9" $t0) - )) - - ;; size(t2) == 100 - (type $t2 (record - (field "f0" $t1) - (field "f1" $t1) - (field "f2" $t1) - (field "f3" $t1) - (field "f4" $t1) - (field "f5" $t1) - (field "f6" $t1) - (field "f7" $t1) - (field "f8" $t1) - (field "f9" $t1) - )) - - ;; size(t3) == 1000 - (type $t3 (record - (field "f0" $t2) - (field "f1" $t2) - (field "f2" $t2) - (field "f3" $t2) - (field "f4" $t2) - (field "f5" $t2) - (field "f6" $t2) - (field "f7" $t2) - (field "f8" $t2) - (field "f9" $t2) - )) - - ;; size(t4) == 10000 - (type $t4 (record - (field "f0" $t3) - (field "f1" $t3) - (field "f2" $t3) - (field "f3" $t3) - (field "f4" $t3) - (field "f5" $t3) - (field "f6" $t3) - (field "f7" $t3) - (field "f8" $t3) - (field "f9" $t3) - )) - - ;; size(t5) == 100000 - (type $t5 (record - (field "f0" $t4) - (field "f1" $t4) - (field "f2" $t4) - (field "f3" $t4) - (field "f4" $t4) - (field "f5" $t4) - (field "f6" $t4) - (field "f7" $t4) - (field "f8" $t4) - (field "f9" $t4) - )) - - (type $f (func - (param "a" $t5) - (param "b" $t5) - (param "c" $t5) - (param "d" $t5) - (param "e" $t5) - (param "f" $t5) - (param "g" $t5) - (param "h" $t5) - (param "i" $t5) - (param "j" $t5) - )) - ) - "effective type size exceeds the limit") - -(assert_malformed - (component quote - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - "(component(component(component(component(component(component(component" - ) - "nesting too deep") diff --git a/test/wasm-tools/virtualize.wast b/test/wasm-tools/virtualize.wast deleted file mode 100644 index d86f108f..00000000 --- a/test/wasm-tools/virtualize.wast +++ /dev/null @@ -1,119 +0,0 @@ -;; RUN: wast --assert default --snapshot tests/snapshots % - -(component - (core module $libc - (memory (export "mem") 0) - (func (export "realloc") (param i32 i32 i32 i32) (result i32) - unreachable - ) - ) - (core instance $libc (instantiate $libc)) - - (component $child - (import "wasi-file" (instance $wasi-file - (export "read" (func (param "count" u32) (result (list u8)))) - (export "write" (func (param "bytes" (list u8)) (result u32))) - )) - - (core instance $libc (instantiate $libc)) - - (core module $m - (import "wasi-file" "read" (func $read (param i32 i32))) - (func $play (export "play") - unreachable - ) - ) - - (core func $wasi_file_read - (canon lower (func $wasi-file "read") - (memory (core memory $libc "mem")) - (realloc (core func $libc "realloc")) - ) - ) - - (core instance $i (instantiate $m - (with "wasi-file" (instance - (export "read" (func $wasi_file_read)) - )) - )) - - (func (export "play") - (canon lift (core func $i "play")) - ) - ) - - (component $virtualize - (import "wasi-file" (instance $wasi-file - (export "read" (func (param "len" u32) (result (list u8)))) - (export "write" (func (param "buf" (list u8)) (result u32))) - )) - (export "read" (func $wasi-file "read")) - (export "write" (func $wasi-file "write")) - ) - - (component - (type $WasiFile (instance - (export "read" (func (param "len" u32) (result (list u8)))) - (export "write" (func (param "buf" (list u8)) (result u32))) - )) - (import "wasi-file" (instance $real-wasi (type $WasiFile))) - (import "virtualize" (component $VIRTUALIZE - (import "wasi-file" (instance (type $WasiFile))) - (export "read" (func (param "len" u32) (result (list u8)))) - (export "write" (func (param "buf" (list u8)) (result u32))) - )) - (import "child" (component $CHILD - (import "wasi-file" (instance (type $WasiFile))) - (export "play" (func)) - ) - ) - - (instance $virt-wasi (instantiate $VIRTUALIZE (with "wasi-file" (instance $real-wasi)))) - (instance $child (instantiate $CHILD (with "wasi-file" (instance $virt-wasi)))) - - (export "work" (func $child "play")) - ) - - (component - (type $WasiFile (instance - (export "read" (func (param "len" u32) (result (list u8)))) - (export "write" (func (param "buf" (list u8)) (result u32))) - )) - (import "wasi-file" (instance $real-wasi (type $WasiFile))) - - (core instance $libc (instantiate $libc)) - - (core module $CHILD - (import "wasi-file" "read" (func $wasi-file (param i32 i32))) - (func $play (export "play") - unreachable - ) - ) - - (core module $VIRTUALIZE - (import "wasi-file" "read" (func (param i32 i32))) - (func (export "read") (param i32 i32) - unreachable - ) - (func (export "write") (param i32 i32 i32) - unreachable - ) - ) - - (core func $real-wasi-read - (canon lower (func $real-wasi "read") - (memory (core memory $libc "mem")) - (realloc (core func $libc "realloc")) - ) - ) - - (core instance $virt-wasi (instantiate $VIRTUALIZE (with "wasi-file" (instance (export "read" (func $real-wasi-read)))))) - (core instance $child (instantiate $CHILD (with "wasi-file" (instance $virt-wasi)))) - (func (export "work") - (canon lift (core func $child "play") - (memory (core memory $libc "mem")) - (realloc (core func $libc "realloc")) - ) - ) - ) -) diff --git a/test/wasm-tools/wrong-order.wast b/test/wasm-tools/wrong-order.wast deleted file mode 100644 index 098fc419..00000000 --- a/test/wasm-tools/wrong-order.wast +++ /dev/null @@ -1,11 +0,0 @@ -;; RUN: wast --assert default --snapshot tests/snapshots % - -(assert_malformed - (module binary - "\00asm\01\00\00\00" - - "\01\01\00" ;; type section, 1 byte, 0 entries - "\0b\01\00" ;; data section, 1 byte, 0 entries - "\01\01\00" ;; type section, 1 byte, 0 entries - ) - "section out of order") diff --git a/test/wasmtime/LICENSE-Apache-2.0_WITH_LLVM-exception b/test/wasmtime/LICENSE-Apache-2.0_WITH_LLVM-exception deleted file mode 100644 index f9d81955..00000000 --- a/test/wasmtime/LICENSE-Apache-2.0_WITH_LLVM-exception +++ /dev/null @@ -1,220 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - - ---- LLVM Exceptions to the Apache 2.0 License ---- - -As an exception, if, as a result of your compiling your source code, portions -of this Software are embedded into an Object form of such source code, you -may redistribute such embedded portions in such Object form without complying -with the conditions of Sections 4(a), 4(b) and 4(d) of the License. - -In addition, if you combine or link compiled forms of this Software with -software that is licensed under the GPLv2 ("Combined Software") and if a -court of competent jurisdiction determines that the patent provision (Section -3), the indemnity provision (Section 9) or other Section of the License -conflicts with the conditions of the GPLv2, you may retroactively and -prospectively choose to deem waived or otherwise exclude such Section(s) of -the License, but only in their entirety and only with respect to the Combined -Software. - diff --git a/test/wasmtime/adapter.wast b/test/wasmtime/adapter.wast deleted file mode 100644 index 9d8a7f5c..00000000 --- a/test/wasmtime/adapter.wast +++ /dev/null @@ -1,137 +0,0 @@ -;;! multi_memory = true - -;; basic function lifting -(component - (core module $m - (func (export "")) - ) - (core instance $i (instantiate $m)) - - (func (export "thunk") - (canon lift (core func $i "")) - ) -) - -;; use an aliased type -(component $c - (core module $m - (func (export "")) - ) - (core instance $i (instantiate $m)) - - (type $to_alias (func)) - (alias outer $c $to_alias (type $alias)) - - (func (export "thunk") (type $alias) - (canon lift (core func $i "")) - ) -) - -;; test out some various canonical abi -(component $c - (core module $m - (func (export "") (param i32 i32)) - (memory (export "memory") 1) - (func (export "realloc") (param i32 i32 i32 i32) (result i32) - unreachable) - ) - (core instance $i (instantiate $m)) - - (func (export "thunk") (param "a" string) - (canon lift - (core func $i "") - (memory (core memory $i "memory")) - (realloc (core func $i "realloc")) - ) - ) - - (func (export "thunk8") (param "a" string) - (canon lift - (core func $i "") - string-encoding=utf8 - (memory (core memory $i "memory")) - (realloc (core func $i "realloc")) - ) - ) - - (func (export "thunk16") (param "a" string) - (canon lift - (core func $i "") - string-encoding=utf16 - (memory (core memory $i "memory")) - (realloc (core func $i "realloc")) - ) - ) - - (func (export "thunklatin16") (param "a" string) - (canon lift - (core func $i "") - string-encoding=latin1+utf16 - (memory (core memory $i "memory")) - (realloc (core func $i "realloc")) - ) - ) -) - -;; lower something then immediately lift it -(component $c - (import "host-return-two" (func $f (result u32))) - - (core func $f_lower - (canon lower (func $f)) - ) - (func $f2 (result s32) - (canon lift (core func $f_lower)) - ) - (export "f" (func $f2)) -) - -;; valid, but odd -(component - (core module $m (func (export ""))) - (core instance $m (instantiate $m)) - - (func $f1 (canon lift (core func $m ""))) - (core func $f2 (canon lower (func $f1))) -) -(assert_trap - (component - (core module $m (func (export ""))) - (core instance $m (instantiate $m)) - - (func $f1 (canon lift (core func $m ""))) - (core func $f2 (canon lower (func $f1))) - - (core module $m2 - (import "" "" (func $f)) - (func $start - call $f) - (start $start) - ) - (core instance (instantiate $m2 - (with "" (instance (export "" (func $f2)))) - )) - ) - "cannot enter component instance") - -;; fiddling with 0-sized lists -(component $c - (core module $m - (func (export "x") (param i32 i32)) - (func (export "realloc") (param i32 i32 i32 i32) (result i32) - i32.const -1) - (memory (export "memory") 0) - ) - (core instance $m (instantiate $m)) - (type $t' (result)) - (export $t "t" (type $t')) - (func $f (param "a" (list $t)) - (canon lift - (core func $m "x") - (realloc (core func $m "realloc")) - (memory (core memory $m "memory")) - ) - ) - (export "empty-list" (func $f)) -) -(assert_trap (invoke "empty-list" (list.const)) "realloc return: beyond end of memory") diff --git a/test/wasmtime/aliasing.wast b/test/wasmtime/aliasing.wast deleted file mode 100644 index ad18f935..00000000 --- a/test/wasmtime/aliasing.wast +++ /dev/null @@ -1,29 +0,0 @@ -(component - (component - (component - (component) - (instance (instantiate 0)) - (export "a" (instance 0)) - ) - (instance (instantiate 0)) - (export "a" (instance 0)) - ) - - (instance (instantiate 0)) ;; instance 0 - (alias export 0 "a" (instance)) ;; instance 1 - (export "a" (instance 1)) ;; instance 2 - (alias export 2 "a" (instance)) ;; instance 3 - (export "inner-a" (instance 3)) ;; instance 4 -) - -(component - (component - (core module) - (export "a" (core module 0)) - ) - - (instance (instantiate 0)) - (alias export 0 "a" (core module)) ;; module 0 - (export "a" (core module 0)) ;; module 1 - (core instance (instantiate 1)) -) diff --git a/test/wasmtime/fused.wast b/test/wasmtime/fused.wast deleted file mode 100644 index ba9155a0..00000000 --- a/test/wasmtime/fused.wast +++ /dev/null @@ -1,1391 +0,0 @@ -;;! multi_memory = true - -;; smoke test with no arguments and no results -(component - (component $a - (core module $m - (func (export "")) - ) - (core instance $m (instantiate $m)) - (func (export "foo") (canon lift (core func $m ""))) - ) - (instance $a (instantiate $a)) - - (component $c - (import "a" (instance $a - (export "foo" (func)) - )) - - (core func $foo (canon lower (func $a "foo"))) - (core module $m2 - (import "" "" (func)) - (start 0) - ) - (core instance $m2 (instantiate $m2 (with "" (instance (export "" (func $foo)))))) - ) - - (instance $c (instantiate $c (with "a" (instance $a)))) -) - -;; boolean parameters -(component - (component $a - (core module $m - (func (export "assert_true") (param i32) - local.get 0 - i32.const 1 - i32.eq - i32.eqz - if unreachable end - ) - (func (export "assert_false") (param i32) - local.get 0 - if unreachable end - ) - (func (export "ret-bool") (param i32) (result i32) - local.get 0 - ) - ) - (core instance $m (instantiate $m)) - (func (export "assert-true") (param "a" bool) (canon lift (core func $m "assert_true"))) - (func (export "assert-false") (param "a" bool) (canon lift (core func $m "assert_false"))) - (func (export "ret-bool") (param "a" u32) (result bool) (canon lift (core func $m "ret-bool"))) - ) - (instance $a (instantiate $a)) - - (component $c - (import "a" (instance $a - (export "assert-true" (func (param "a" bool))) - (export "assert-false" (func (param "a" bool))) - (export "ret-bool" (func (param "a" u32) (result bool))) - )) - - (core func $assert_true (canon lower (func $a "assert-true"))) - (core func $assert_false (canon lower (func $a "assert-false"))) - (core func $ret_bool (canon lower (func $a "ret-bool"))) - - (core module $m2 - (import "" "assert-true" (func $assert_true (param i32))) - (import "" "assert-false" (func $assert_false (param i32))) - (import "" "ret-bool" (func $ret_bool (param i32) (result i32))) - - (func $start - (call $assert_true (i32.const 1)) - (call $assert_true (i32.const 2)) - (call $assert_true (i32.const -1)) - (call $assert_false (i32.const 0)) - - (if (i32.ne (call $ret_bool (i32.const 1)) (i32.const 1)) - (then (unreachable))) - (if (i32.ne (call $ret_bool (i32.const 2)) (i32.const 1)) - (then (unreachable))) - (if (i32.ne (call $ret_bool (i32.const -1)) (i32.const 1)) - (then (unreachable))) - (if (i32.ne (call $ret_bool (i32.const 0)) (i32.const 0)) - (then (unreachable))) - ) - (start $start) - ) - (core instance $m2 (instantiate $m2 - (with "" (instance - (export "assert-true" (func $assert_true)) - (export "assert-false" (func $assert_false)) - (export "ret-bool" (func $ret_bool)) - )) - )) - ) - - (instance $c (instantiate $c (with "a" (instance $a)))) -) - -;; lots of parameters and results -(component - (component $a - (type $roundtrip (func - ;; 20 u32 params - (param "a1" u32) (param "a2" u32) (param "a3" u32) (param "a4" u32) (param "a5" u32) - (param "a6" u32) (param "a7" u32) (param "a8" u32) (param "a9" u32) (param "a10" u32) - (param "a11" u32) (param "a12" u32) (param "a13" u32) (param "a14" u32) (param "a15" u32) - (param "a16" u32) (param "a17" u32) (param "a18" u32) (param "a19" u32) (param "a20" u32) - - ;; 10 u32 results - (result (tuple u32 u32 u32 u32 u32 u32 u32 u32 u32 u32)) - )) - - (core module $m - (memory (export "memory") 1) - (func (export "roundtrip") (param $src i32) (result i32) - (local $dst i32) - (if (i32.ne (local.get $src) (i32.const 16)) - (then (unreachable))) - - (if (i32.ne (i32.load offset=0 (local.get $src)) (i32.const 1)) (then (unreachable))) - (if (i32.ne (i32.load offset=4 (local.get $src)) (i32.const 2)) (then (unreachable))) - (if (i32.ne (i32.load offset=8 (local.get $src)) (i32.const 3)) (then (unreachable))) - (if (i32.ne (i32.load offset=12 (local.get $src)) (i32.const 4)) (then (unreachable))) - (if (i32.ne (i32.load offset=16 (local.get $src)) (i32.const 5)) (then (unreachable))) - (if (i32.ne (i32.load offset=20 (local.get $src)) (i32.const 6)) (then (unreachable))) - (if (i32.ne (i32.load offset=24 (local.get $src)) (i32.const 7)) (then (unreachable))) - (if (i32.ne (i32.load offset=28 (local.get $src)) (i32.const 8)) (then (unreachable))) - (if (i32.ne (i32.load offset=32 (local.get $src)) (i32.const 9)) (then (unreachable))) - (if (i32.ne (i32.load offset=36 (local.get $src)) (i32.const 10)) (then (unreachable))) - (if (i32.ne (i32.load offset=40 (local.get $src)) (i32.const 11)) (then (unreachable))) - (if (i32.ne (i32.load offset=44 (local.get $src)) (i32.const 12)) (then (unreachable))) - (if (i32.ne (i32.load offset=48 (local.get $src)) (i32.const 13)) (then (unreachable))) - (if (i32.ne (i32.load offset=52 (local.get $src)) (i32.const 14)) (then (unreachable))) - (if (i32.ne (i32.load offset=56 (local.get $src)) (i32.const 15)) (then (unreachable))) - (if (i32.ne (i32.load offset=60 (local.get $src)) (i32.const 16)) (then (unreachable))) - (if (i32.ne (i32.load offset=64 (local.get $src)) (i32.const 17)) (then (unreachable))) - (if (i32.ne (i32.load offset=68 (local.get $src)) (i32.const 18)) (then (unreachable))) - (if (i32.ne (i32.load offset=72 (local.get $src)) (i32.const 19)) (then (unreachable))) - (if (i32.ne (i32.load offset=76 (local.get $src)) (i32.const 20)) (then (unreachable))) - - (local.set $dst (i32.const 500)) - - (i32.store offset=0 (local.get $dst) (i32.const 21)) - (i32.store offset=4 (local.get $dst) (i32.const 22)) - (i32.store offset=8 (local.get $dst) (i32.const 23)) - (i32.store offset=12 (local.get $dst) (i32.const 24)) - (i32.store offset=16 (local.get $dst) (i32.const 25)) - (i32.store offset=20 (local.get $dst) (i32.const 26)) - (i32.store offset=24 (local.get $dst) (i32.const 27)) - (i32.store offset=28 (local.get $dst) (i32.const 28)) - (i32.store offset=32 (local.get $dst) (i32.const 29)) - (i32.store offset=36 (local.get $dst) (i32.const 30)) - - local.get $dst - ) - - (func (export "realloc") (param i32 i32 i32 i32) (result i32) - i32.const 16) - ) - (core instance $m (instantiate $m)) - - (func (export "roundtrip") (type $roundtrip) - (canon lift (core func $m "roundtrip") (memory (core memory $m "memory")) - (realloc (core func $m "realloc"))) - ) - ) - (instance $a (instantiate $a)) - - (component $c - (type $roundtrip (func - ;; 20 u32 params - (param "a1" u32) (param "a2" u32) (param "a3" u32) (param "a4" u32) (param "a5" u32) - (param "a6" u32) (param "a7" u32) (param "a8" u32) (param "a9" u32) (param "a10" u32) - (param "a11" u32) (param "a12" u32) (param "a13" u32) (param "a14" u32) (param "a15" u32) - (param "a16" u32) (param "a17" u32) (param "a18" u32) (param "a19" u32) (param "a20" u32) - - ;; 10 u32 results - (result (tuple u32 u32 u32 u32 u32 u32 u32 u32 u32 u32)) - )) - - (import "a" (instance $a - (export "roundtrip" (func (type $roundtrip))) - )) - - (core module $libc - (memory (export "memory") 1) - (func (export "realloc") (param i32 i32 i32 i32) (result i32) unreachable) - ) - (core instance $libc (instantiate $libc)) - (core func $roundtrip - (canon lower (func $a "roundtrip") - (memory (core memory $libc "memory")) - (realloc (core func $libc "realloc")) ;; FIXME(wasm-tools#693) should not be necessary - ) - ) - - (core module $m2 - (import "libc" "memory" (memory 1)) - (import "" "roundtrip" (func $roundtrip (param i32 i32))) - - (func $start - (local $addr i32) - (local $retaddr i32) - - (local.set $addr (i32.const 100)) - (call $store_many (i32.const 20) (local.get $addr)) - - (local.set $retaddr (i32.const 200)) - (call $roundtrip (local.get $addr) (local.get $retaddr)) - - (if (i32.ne (i32.load offset=0 (local.get $retaddr)) (i32.const 21)) (then (unreachable))) - (if (i32.ne (i32.load offset=4 (local.get $retaddr)) (i32.const 22)) (then (unreachable))) - (if (i32.ne (i32.load offset=8 (local.get $retaddr)) (i32.const 23)) (then (unreachable))) - (if (i32.ne (i32.load offset=12 (local.get $retaddr)) (i32.const 24)) (then (unreachable))) - (if (i32.ne (i32.load offset=16 (local.get $retaddr)) (i32.const 25)) (then (unreachable))) - (if (i32.ne (i32.load offset=20 (local.get $retaddr)) (i32.const 26)) (then (unreachable))) - (if (i32.ne (i32.load offset=24 (local.get $retaddr)) (i32.const 27)) (then (unreachable))) - (if (i32.ne (i32.load offset=28 (local.get $retaddr)) (i32.const 28)) (then (unreachable))) - (if (i32.ne (i32.load offset=32 (local.get $retaddr)) (i32.const 29)) (then (unreachable))) - (if (i32.ne (i32.load offset=36 (local.get $retaddr)) (i32.const 30)) (then (unreachable))) - ) - - (func $store_many (param $amt i32) (param $addr i32) - (local $c i32) - (loop $loop - (local.set $c (i32.add (local.get $c) (i32.const 1))) - (i32.store (local.get $addr) (local.get $c)) - (local.set $addr (i32.add (local.get $addr) (i32.const 4))) - - (if (i32.ne (local.get $amt) (local.get $c)) (then (br $loop))) - ) - ) - (start $start) - ) - (core instance $m2 (instantiate $m2 - (with "libc" (instance $libc)) - (with "" (instance (export "roundtrip" (func $roundtrip)))) - )) - ) - - (instance $c (instantiate $c (with "a" (instance $a)))) -) - -;; this will require multiple adapter modules to get generated -(component - (component $c0 - (core module $root (func (export "") (result i32) - i32.const 0 - )) - (core instance $root (instantiate $root)) - (func (export "thunk") (result u32) (canon lift (core func $root ""))) - ) - (instance $c0 (instantiate $c0)) - - (component $c - (import "thunk" (instance $thunk - (export "thunk" (func (result u32))) - )) - (core func $import (canon lower (func $thunk "thunk"))) - (core module $reexport - (import "" "" (func $thunk (result i32))) - (func (export "thunk") (result i32) - call $thunk - i32.const 1 - i32.add) - ) - (core instance $reexport (instantiate $reexport - (with "" (instance - (export "" (func $import)) - )) - )) - (func $export (export "thunk") (result u32) - (canon lift (core func $reexport "thunk")) - ) - ) - - (instance $c1 (instantiate $c (with "thunk" (instance $c0)))) - (instance $c2 (instantiate $c (with "thunk" (instance $c1)))) - (instance $c3 (instantiate $c (with "thunk" (instance $c2)))) - (instance $c4 (instantiate $c (with "thunk" (instance $c3)))) - (instance $c5 (instantiate $c (with "thunk" (instance $c4)))) - (instance $c6 (instantiate $c (with "thunk" (instance $c5)))) - - (component $verify - (import "thunk" (instance $thunk - (export "thunk" (func (result u32))) - )) - (core func $thunk (canon lower (func $thunk "thunk"))) - (core module $verify - (import "" "" (func $thunk (result i32))) - - (func $start - call $thunk - i32.const 6 - i32.ne - if unreachable end - ) - (start $start) - ) - (core instance (instantiate $verify - (with "" (instance - (export "" (func $thunk)) - )) - )) - ) - (instance (instantiate $verify (with "thunk" (instance $c6)))) -) - -;; Fancy case of an adapter using an adapter. Note that this is silly and -;; doesn't actually make any sense at runtime, we just shouldn't panic on a -;; valid component. -(component - (type $tuple20 (tuple - u32 u32 u32 u32 u32 - u32 u32 u32 u32 u32 - u32 u32 u32 u32 u32 - u32 u32 u32 u32 u32)) - - (component $realloc - (core module $realloc - (memory (export "memory") 1) - (func (export "realloc") (param i32 i32 i32 i32) (result i32) - unreachable) - ) - (core instance $realloc (instantiate $realloc)) - (func $realloc (param "a" (tuple u32 u32 u32 u32)) (result u32) - (canon lift (core func $realloc "realloc")) - ) - (export "realloc" (func $realloc)) - ) - (instance $realloc (instantiate $realloc)) - (core func $realloc (canon lower (func $realloc "realloc"))) - - (core module $m - (memory (export "memory") 1) - (func (export "foo") (param i32)) - ) - (core instance $m (instantiate $m)) - (func $foo (param "a" $tuple20) - (canon lift - (core func $m "foo") - (memory (core memory $m "memory")) - (realloc (core func $realloc)) - ) - ) - - (component $c - (import "foo" (func $foo (param "a" $tuple20))) - - (core module $libc - (memory (export "memory") 1) - (func (export "realloc") (param i32 i32 i32 i32) (result i32) - unreachable) - ) - (core instance $libc (instantiate $libc)) - (core func $foo - (canon lower (func $foo) - (memory (core memory $libc "memory")) - (realloc (core func $libc "realloc")) ;; FIXME(wasm-tools#693) should not be necessary - ) - ) - (core module $something - (import "" "foo" (func (param i32))) - ) - (core instance (instantiate $something - (with "" (instance - (export "foo" (func $foo)) - )) - )) - ) - (instance (instantiate $c - (with "foo" (func $foo)) - )) -) - -;; Don't panic or otherwise create extraneous adapter modules when the same -;; adapter is used twice for a module's argument. -(component - (core module $m - (func (export "foo") (param)) - ) - (core instance $m (instantiate $m)) - (func $foo (canon lift (core func $m "foo"))) - - (component $c - (import "foo" (func $foo)) - (core func $foo (canon lower (func $foo))) - - (core module $something - (import "" "a" (func)) - (import "" "b" (func)) - ) - (core instance (instantiate $something - (with "" (instance - (export "a" (func $foo)) - (export "b" (func $foo)) - )) - )) - ) - (instance (instantiate $c (with "foo" (func $foo)))) -) - -;; post-return should get invoked by the generated adapter, if specified -(component - (component $a - (core module $m - (global $post_called (mut i32) (i32.const 0)) - (func (export "foo") - ;; assert `foo-post` not called yet - global.get $post_called - i32.const 1 - i32.eq - if unreachable end - ) - (func (export "foo-post") - ;; assert `foo-post` not called before - global.get $post_called - i32.const 1 - i32.eq - if unreachable end - ;; ... then flag as called - i32.const 1 - global.set $post_called - ) - (func (export "assert-post") - global.get $post_called - i32.const 1 - i32.ne - if unreachable end - ) - ) - (core instance $m (instantiate $m)) - (func (export "foo") (canon lift (core func $m "foo") (post-return (core func $m "foo-post")))) - (func (export "assert-post") (canon lift (core func $m "assert-post"))) - ) - (instance $a (instantiate $a)) - - (component $c - (import "a" (instance $a - (export "foo" (func)) - (export "assert-post" (func)) - )) - (core func $foo (canon lower (func $a "foo"))) - (core func $assert_post (canon lower (func $a "assert-post"))) - - (core module $something - (import "" "foo" (func $foo)) - (import "" "assert-post" (func $assert_post)) - - (func $start - call $foo - call $assert_post - ) - (start $start) - ) - (core instance (instantiate $something - (with "" (instance - (export "foo" (func $foo)) - (export "assert-post" (func $assert_post)) - )) - )) - ) - (instance (instantiate $c (with "a" (instance $a)))) -) - -;; post-return passes the results -(component - (component $a - (core module $m - (func (export "foo") (result i32) i32.const 100) - (func (export "foo-post") (param i32) - (if (i32.ne (local.get 0) (i32.const 100)) (then (unreachable)))) - ) - (core instance $m (instantiate $m)) - (func (export "foo") (result u32) - (canon lift (core func $m "foo") (post-return (core func $m "foo-post")))) - ) - (instance $a (instantiate $a)) - - (component $c - (import "a" (instance $a - (export "foo" (func (result u32))) - )) - (core func $foo (canon lower (func $a "foo"))) - - (core module $something - (import "" "foo" (func $foo (result i32))) - (func $start - (if (i32.ne (call $foo) (i32.const 100)) (then (unreachable)))) - (start $start) - ) - (core instance (instantiate $something - (with "" (instance - (export "foo" (func $foo)) - )) - )) - ) - (instance (instantiate $c (with "a" (instance $a)))) -) - -;; callee retptr misaligned -(assert_trap - (component - (component $c1 - (core module $m - (memory (export "memory") 1) - (func (export "r") (result i32) i32.const 1) - ) - (core instance $m (instantiate $m)) - (func (export "r") (result (tuple u32 u32)) - (canon lift (core func $m "r") (memory (core memory $m "memory"))) - ) - ) - (component $c2 - (import "r" (func $r (result (tuple u32 u32)))) - (core module $libc (memory (export "memory") 1)) - (core instance $libc (instantiate $libc)) - (core func $r (canon lower (func $r) (memory (core memory $libc "memory")))) - - (core module $m - (import "" "r" (func $r (param i32))) - (func $start - i32.const 4 - call $r - ) - (start $start) - ) - (core instance (instantiate $m - (with "" (instance (export "r" (func $r)))) - )) - ) - (instance $c1 (instantiate $c1)) - (instance $c2 (instantiate $c2 (with "r" (func $c1 "r")))) - ) - "unaligned pointer") - -;; caller retptr misaligned -(assert_trap - (component - (component $c1 - (core module $m - (memory (export "memory") 1) - (func (export "r") (result i32) i32.const 0) - ) - (core instance $m (instantiate $m)) - (func (export "r") (result (tuple u32 u32)) - (canon lift (core func $m "r") (memory (core memory $m "memory"))) - ) - ) - (component $c2 - (import "r" (func $r (result (tuple u32 u32)))) - (core module $libc (memory (export "memory") 1)) - (core instance $libc (instantiate $libc)) - (core func $r (canon lower (func $r) (memory (core memory $libc "memory")))) - - (core module $m - (import "" "r" (func $r (param i32))) - (func $start - i32.const 1 - call $r - ) - (start $start) - ) - (core instance (instantiate $m - (with "" (instance (export "r" (func $r)))) - )) - ) - (instance $c1 (instantiate $c1)) - (instance $c2 (instantiate $c2 (with "r" (func $c1 "r")))) - ) - "unaligned pointer") - -;; callee argptr misaligned -(assert_trap - (component - (type $big (tuple u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32)) - - (component $c1 - (core module $m - (memory (export "memory") 1) - (func (export "r") (param i32)) - (func (export "realloc") (param i32 i32 i32 i32) (result i32) - i32.const 1) - ) - (core instance $m (instantiate $m)) - (func (export "r") (param "a" $big) - (canon lift (core func $m "r") (memory (core memory $m "memory")) (realloc (core func $m "realloc"))) - ) - ) - (component $c2 - (import "r" (func $r (param "a" $big))) - (core module $libc - (memory (export "memory") 1) - (func (export "realloc") (param i32 i32 i32 i32) (result i32) unreachable) - ) - (core instance $libc (instantiate $libc)) - (core func $r - (canon lower (func $r) - (memory (core memory $libc "memory")) - (realloc (core func $libc "realloc")) ;; FIXME(wasm-tools#693) should not be necessary - ) - ) - - (core module $m - (import "" "r" (func $r (param i32))) - (func $start - i32.const 4 - call $r - ) - (start $start) - ) - (core instance (instantiate $m - (with "" (instance (export "r" (func $r)))) - )) - ) - (instance $c1 (instantiate $c1)) - (instance $c2 (instantiate $c2 (with "r" (func $c1 "r")))) - ) - "unaligned pointer") - -;; caller argptr misaligned -(assert_trap - (component - (type $big (tuple u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32)) - - (component $c1 - (core module $m - (memory (export "memory") 1) - (func (export "r") (param i32)) - (func (export "realloc") (param i32 i32 i32 i32) (result i32) - i32.const 4) - ) - (core instance $m (instantiate $m)) - (func (export "r") (param "a" $big) - (canon lift (core func $m "r") (memory (core memory $m "memory")) (realloc (core func $m "realloc"))) - ) - ) - (component $c2 - (import "r" (func $r (param "a" $big))) - (core module $libc - (memory (export "memory") 1) - (func (export "realloc") (param i32 i32 i32 i32) (result i32) unreachable) - ) - (core instance $libc (instantiate $libc)) - (core func $r - (canon lower (func $r) - (memory (core memory $libc "memory")) - (realloc (core func $libc "realloc")) ;; FIXME(wasm-tools#693) should not be necessary - ) - ) - - - (core module $m - (import "" "r" (func $r (param i32))) - (func $start - i32.const 1 - call $r - ) - (start $start) - ) - (core instance (instantiate $m - (with "" (instance (export "r" (func $r)))) - )) - ) - (instance $c1 (instantiate $c1)) - (instance $c2 (instantiate $c2 (with "r" (func $c1 "r")))) - ) - "unaligned pointer") - -;; simple variant translation -(component - (component $c1 - (type $a' (variant (case "x"))) - (export $a "a" (type $a')) - (type $b' (variant (case "y"))) - (export $b "b" (type $b')) - - (core module $m - (func (export "r") (param i32) (result i32) - (if (i32.ne (local.get 0) (i32.const 0)) (then (unreachable))) - i32.const 0 - ) - ) - (core instance $m (instantiate $m)) - (func (export "r") (param "a" $a) (result $b) (canon lift (core func $m "r"))) - ) - (component $c2 - (type $a' (variant (case "x"))) - (import "a" (type $a (eq $a'))) - (type $b' (variant (case "y"))) - (import "b" (type $b (eq $b'))) - - (import "r" (func $r (param "a" $a) (result $b))) - (core func $r (canon lower (func $r))) - - (core module $m - (import "" "r" (func $r (param i32) (result i32))) - (func $start - i32.const 0 - call $r - i32.const 0 - i32.ne - if unreachable end - ) - (start $start) - ) - (core instance (instantiate $m - (with "" (instance (export "r" (func $r)))) - )) - ) - (instance $c1 (instantiate $c1)) - (instance $c2 (instantiate $c2 - (with "a" (type $c1 "a")) - (with "b" (type $c1 "b")) - (with "r" (func $c1 "r")) - )) -) - -;; invalid variant discriminant in a parameter -(assert_trap - (component - (component $c1 - (type $a' (variant (case "x"))) - (export $a "a" (type $a')) - (core module $m - (func (export "r") (param i32)) - ) - (core instance $m (instantiate $m)) - (func (export "r") (param "a" $a) (canon lift (core func $m "r"))) - ) - (component $c2 - (type $a' (variant (case "x"))) - (import "a" (type $a (eq $a'))) - (import "r" (func $r (param "a" $a))) - (core func $r (canon lower (func $r))) - - (core module $m - (import "" "r" (func $r (param i32))) - (func $start - i32.const 1 - call $r - ) - (start $start) - ) - (core instance (instantiate $m - (with "" (instance (export "r" (func $r)))) - )) - ) - (instance $c1 (instantiate $c1)) - (instance $c2 (instantiate $c2 - (with "a" (type $c1 "a")) - (with "r" (func $c1 "r")) - )) - ) - "invalid variant discriminant") - -;; invalid variant discriminant in a result -(assert_trap - (component - (component $c1 - (type $a' (variant (case "x"))) - (export $a "a" (type $a')) - (core module $m - (func (export "r") (result i32) i32.const 1) - ) - (core instance $m (instantiate $m)) - (func (export "r") (result $a) (canon lift (core func $m "r"))) - ) - (component $c2 - (type $a' (variant (case "x"))) - (import "a" (type $a (eq $a'))) - (import "r" (func $r (result $a))) - (core func $r (canon lower (func $r))) - - (core module $m - (import "" "r" (func $r (result i32))) - (func $start call $r drop) - (start $start) - ) - (core instance (instantiate $m - (with "" (instance (export "r" (func $r)))) - )) - ) - (instance $c1 (instantiate $c1)) - (instance $c2 (instantiate $c2 - (with "a" (type $c1 "a")) - (with "r" (func $c1 "r")) - )) - ) - "invalid variant discriminant") - - -;; extra bits are chopped off -(component - (component $c1 - (core module $m - (func (export "u") (param i32) - (if (i32.ne (local.get 0) (i32.const 0)) (then (unreachable))) - ) - (func (export "s") (param i32) - (if (i32.ne (local.get 0) (i32.const -1)) (then (unreachable))) - ) - ) - (core instance $m (instantiate $m)) - (func (export "u8") (param "a" u8) (canon lift (core func $m "u"))) - (func (export "u16") (param "a" u16) (canon lift (core func $m "u"))) - (func (export "s8") (param "a" s8) (canon lift (core func $m "s"))) - (func (export "s16") (param "a" s16) (canon lift (core func $m "s"))) - ) - (component $c2 - (import "a" (instance $i - (export "u8" (func (param "a" u8))) - (export "s8" (func (param "a" s8))) - (export "u16" (func (param "a" u16))) - (export "s16" (func (param "a" s16))) - )) - - (core func $u8 (canon lower (func $i "u8"))) - (core func $s8 (canon lower (func $i "s8"))) - (core func $u16 (canon lower (func $i "u16"))) - (core func $s16 (canon lower (func $i "s16"))) - - (core module $m - (import "" "u8" (func $u8 (param i32))) - (import "" "s8" (func $s8 (param i32))) - (import "" "u16" (func $u16 (param i32))) - (import "" "s16" (func $s16 (param i32))) - - (func $start - (call $u8 (i32.const 0)) - (call $u8 (i32.const 0xff00)) - (call $s8 (i32.const -1)) - (call $s8 (i32.const 0xff)) - (call $s8 (i32.const 0xffff)) - - (call $u16 (i32.const 0)) - (call $u16 (i32.const 0xff0000)) - (call $s16 (i32.const -1)) - (call $s16 (i32.const 0xffff)) - (call $s16 (i32.const 0xffffff)) - ) - (start $start) - ) - (core instance (instantiate $m - (with "" (instance - (export "u8" (func $u8)) - (export "s8" (func $s8)) - (export "u16" (func $u16)) - (export "s16" (func $s16)) - )) - )) - ) - (instance $c1 (instantiate $c1)) - (instance $c2 (instantiate $c2 (with "a" (instance $c1)))) -) - -;; translation of locals between different types -(component - (component $c1 - (type $a' (variant (case "a" u8) (case "b" float32))) - (type $b' (variant (case "a" u16) (case "b" s64))) - (type $c' (variant (case "a" u64) (case "b" float64))) - (type $d' (variant (case "a" float32) (case "b" float64))) - (type $e' (variant (case "a" float32) (case "b" s64))) - (export $a "t-a" (type $a')) - (export $b "t-b" (type $b')) - (export $c "t-c" (type $c')) - (export $d "t-d" (type $d')) - (export $e "t-e" (type $e')) - - (type $func_a (func (param "x" bool) (param "a" $a))) - (type $func_b (func (param "x" bool) (param "b" $b))) - (type $func_c (func (param "x" bool) (param "c" $c))) - (type $func_d (func (param "x" bool) (param "d" $d))) - (type $func_e (func (param "x" bool) (param "e" $d))) - - (core module $m - (func (export "a") (param i32 i32 i32) - (i32.eqz (local.get 0)) - if - (if (i32.ne (local.get 1) (i32.const 0)) (then (unreachable))) - (if (i32.ne (local.get 2) (i32.const 2)) (then (unreachable))) - else - (if (i32.ne (local.get 1) (i32.const 1)) (then (unreachable))) - (if (f32.ne (f32.reinterpret_i32 (local.get 2)) (f32.const 3)) (then (unreachable))) - end - ) - (func (export "b") (param i32 i32 i64) - (i32.eqz (local.get 0)) - if - (if (i32.ne (local.get 1) (i32.const 0)) (then (unreachable))) - (if (i64.ne (local.get 2) (i64.const 4)) (then (unreachable))) - else - (if (i32.ne (local.get 1) (i32.const 1)) (then (unreachable))) - (if (i64.ne (local.get 2) (i64.const 5)) (then (unreachable))) - end - ) - (func (export "c") (param i32 i32 i64) - (i32.eqz (local.get 0)) - if - (if (i32.ne (local.get 1) (i32.const 0)) (then (unreachable))) - (if (i64.ne (local.get 2) (i64.const 6)) (then (unreachable))) - else - (if (i32.ne (local.get 1) (i32.const 1)) (then (unreachable))) - (if (f64.ne (f64.reinterpret_i64 (local.get 2)) (f64.const 7)) (then (unreachable))) - end - ) - (func (export "d") (param i32 i32 i64) - (i32.eqz (local.get 0)) - if - (if (i32.ne (local.get 1) (i32.const 0)) (then (unreachable))) - (if (f32.ne (f32.reinterpret_i32 (i32.wrap_i64 (local.get 2))) (f32.const 8)) (then (unreachable))) - else - (if (i32.ne (local.get 1) (i32.const 1)) (then (unreachable))) - (if (f64.ne (f64.reinterpret_i64 (local.get 2)) (f64.const 9)) (then (unreachable))) - end - ) - (func (export "e") (param i32 i32 i64) - (i32.eqz (local.get 0)) - if - (if (i32.ne (local.get 1) (i32.const 0)) (then (unreachable))) - (if (f32.ne (f32.reinterpret_i32 (i32.wrap_i64 (local.get 2))) (f32.const 10)) (then (unreachable))) - else - (if (i32.ne (local.get 1) (i32.const 1)) (then (unreachable))) - (if (i64.ne (local.get 2) (i64.const 11)) (then (unreachable))) - end - ) - ) - (core instance $m (instantiate $m)) - (func (export "a") (type $func_a) (canon lift (core func $m "a"))) - (func (export "b") (type $func_b) (canon lift (core func $m "b"))) - (func (export "c") (type $func_c) (canon lift (core func $m "c"))) - (func (export "d") (type $func_d) (canon lift (core func $m "d"))) - (func (export "e") (type $func_e) (canon lift (core func $m "e"))) - ) - (component $c2 - (import "a" (instance $i - (type $a' (variant (case "a" u8) (case "b" float32))) - (type $b' (variant (case "a" u16) (case "b" s64))) - (type $c' (variant (case "a" u64) (case "b" float64))) - (type $d' (variant (case "a" float32) (case "b" float64))) - (type $e' (variant (case "a" float32) (case "b" s64))) - (export "t-a" (type $a (eq $a'))) - (export "t-b" (type $b (eq $b'))) - (export "t-c" (type $c (eq $c'))) - (export "t-d" (type $d (eq $d'))) - (export "t-e" (type $e (eq $e'))) - (type $func_a (func (param "x" bool) (param "a" $a))) - (type $func_b (func (param "x" bool) (param "b" $b))) - (type $func_c (func (param "x" bool) (param "c" $c))) - (type $func_d (func (param "x" bool) (param "d" $d))) - (type $func_e (func (param "x" bool) (param "e" $d))) - - (export "a" (func (type $func_a))) - (export "b" (func (type $func_b))) - (export "c" (func (type $func_c))) - (export "d" (func (type $func_d))) - (export "e" (func (type $func_e))) - )) - - (core func $a (canon lower (func $i "a"))) - (core func $b (canon lower (func $i "b"))) - (core func $c (canon lower (func $i "c"))) - (core func $d (canon lower (func $i "d"))) - (core func $e (canon lower (func $i "e"))) - - (core module $m - (import "" "a" (func $a (param i32 i32 i32))) - (import "" "b" (func $b (param i32 i32 i64))) - (import "" "c" (func $c (param i32 i32 i64))) - (import "" "d" (func $d (param i32 i32 i64))) - (import "" "e" (func $e (param i32 i32 i64))) - - (func $start - ;; upper bits should get masked - (call $a (i32.const 0) (i32.const 0) (i32.const 0xff_02)) - (call $a (i32.const 1) (i32.const 1) (i32.reinterpret_f32 (f32.const 3))) - - ;; upper bits should get masked - (call $b (i32.const 0) (i32.const 0) (i64.const 0xff_00_04)) - (call $b (i32.const 1) (i32.const 1) (i64.const 5)) - - (call $c (i32.const 0) (i32.const 0) (i64.const 6)) - (call $c (i32.const 1) (i32.const 1) (i64.reinterpret_f64 (f64.const 7))) - - (call $d (i32.const 0) (i32.const 0) (i64.extend_i32_u (i32.reinterpret_f32 (f32.const 8)))) - (call $d (i32.const 1) (i32.const 1) (i64.reinterpret_f64 (f64.const 9))) - - (call $e (i32.const 0) (i32.const 0) (i64.extend_i32_u (i32.reinterpret_f32 (f32.const 10)))) - (call $e (i32.const 1) (i32.const 1) (i64.const 11)) - ) - (start $start) - ) - (core instance (instantiate $m - (with "" (instance - (export "a" (func $a)) - (export "b" (func $b)) - (export "c" (func $c)) - (export "d" (func $d)) - (export "e" (func $e)) - )) - )) - ) - (instance $c1 (instantiate $c1)) - (instance $c2 (instantiate $c2 (with "a" (instance $c1)))) -) - -;; different size variants -(component - (component $c1 - (type $a' (variant - (case "a") - (case "b" float32) - (case "c" (tuple float32 u32)) - (case "d" (tuple float32 u64 u8)) - )) - (export $a "t-a" (type $a')) - - (core module $m - (func (export "a") (param i32 i32 f32 i64 i32) - (if (i32.eq (local.get 0) (i32.const 0)) - (then (block - (if (i32.ne (local.get 1) (i32.const 0)) (then (unreachable))) - (if (f32.ne (local.get 2) (f32.const 0)) (then (unreachable))) - (if (i64.ne (local.get 3) (i64.const 0)) (then (unreachable))) - (if (i32.ne (local.get 4) (i32.const 0)) (then (unreachable))) - )) - ) - (if (i32.eq (local.get 0) (i32.const 1)) - (then (block - (if (i32.ne (local.get 1) (i32.const 1)) (then (unreachable))) - (if (f32.ne (local.get 2) (f32.const 1)) (then (unreachable))) - (if (i64.ne (local.get 3) (i64.const 0)) (then (unreachable))) - (if (i32.ne (local.get 4) (i32.const 0)) (then (unreachable))) - )) - ) - (if (i32.eq (local.get 0) (i32.const 2)) - (then (block - (if (i32.ne (local.get 1) (i32.const 2)) (then (unreachable))) - (if (f32.ne (local.get 2) (f32.const 2)) (then (unreachable))) - (if (i64.ne (local.get 3) (i64.const 2)) (then (unreachable))) - (if (i32.ne (local.get 4) (i32.const 0)) (then (unreachable))) - )) - ) - (if (i32.eq (local.get 0) (i32.const 3)) - (then (block - (if (i32.ne (local.get 1) (i32.const 3)) (then (unreachable))) - (if (f32.ne (local.get 2) (f32.const 3)) (then (unreachable))) - (if (i64.ne (local.get 3) (i64.const 3)) (then (unreachable))) - (if (i32.ne (local.get 4) (i32.const 3)) (then (unreachable))) - )) - ) - (if (i32.gt_u (local.get 0) (i32.const 3)) - (then (unreachable))) - ) - ) - (core instance $m (instantiate $m)) - (func (export "a") (param "x" u8) (param "a" $a) (canon lift (core func $m "a"))) - ) - (component $c2 - (import "a" (instance $i - (type $a' (variant - (case "a") - (case "b" float32) - (case "c" (tuple float32 u32)) - (case "d" (tuple float32 u64 u8)) - )) - (export "t-a" (type $a (eq $a'))) - (export "a" (func (param "x" u8) (param "a" $a))) - )) - - (core func $a (canon lower (func $i "a"))) - - (core module $m - (import "" "a" (func $a (param i32 i32 f32 i64 i32))) - - (func $start - ;; variant a - (call $a - (i32.const 0) - (i32.const 0) - (f32.const 0) - (i64.const 0) - (i32.const 0)) - ;; variant b - (call $a - (i32.const 1) - (i32.const 1) - (f32.const 1) - (i64.const 0) - (i32.const 0)) - ;; variant c - (call $a - (i32.const 2) - (i32.const 2) - (f32.const 2) - (i64.const 2) - (i32.const 0)) - ;; variant d - (call $a - (i32.const 3) - (i32.const 3) - (f32.const 3) - (i64.const 3) - (i32.const 3)) - ) - (start $start) - ) - (core instance (instantiate $m - (with "" (instance - (export "a" (func $a)) - )) - )) - ) - (instance $c1 (instantiate $c1)) - (instance $c2 (instantiate $c2 (with "a" (instance $c1)))) -) - -;; roundtrip some valid chars -(component - (component $c1 - (core module $m - (func (export "a") (param i32) (result i32) local.get 0) - ) - (core instance $m (instantiate $m)) - (func (export "a") (param "a" char) (result char) (canon lift (core func $m "a"))) - ) - (component $c2 - (import "a" (instance $i - (export "a" (func (param "a" char) (result char))) - )) - - (core func $a (canon lower (func $i "a"))) - - (core module $m - (import "" "a" (func $a (param i32) (result i32))) - - (func $start - (call $roundtrip (i32.const 0)) - (call $roundtrip (i32.const 0xab)) - (call $roundtrip (i32.const 0xd7ff)) - (call $roundtrip (i32.const 0xe000)) - (call $roundtrip (i32.const 0x10ffff)) - ) - (func $roundtrip (export "roundtrip") (param i32) - local.get 0 - call $a - local.get 0 - i32.ne - if unreachable end - ) - (start $start) - ) - (core instance $m (instantiate $m - (with "" (instance - (export "a" (func $a)) - )) - )) - - (func (export "roundtrip") (param "a" char) (canon lift (core func $m "roundtrip"))) - ) - (instance $c1 (instantiate $c1)) - (instance $c2 (instantiate $c2 (with "a" (instance $c1)))) - - (export "roundtrip" (func $c2 "roundtrip")) -) - -(assert_return (invoke "roundtrip" (char.const "x"))) -(assert_return (invoke "roundtrip" (char.const "⛳"))) -(assert_return (invoke "roundtrip" (char.const "🍰"))) - -;; invalid chars -(assert_trap - (component - (component $c1 - (core module $m (func (export "a") (param i32))) - (core instance $m (instantiate $m)) - (func (export "a") (param "a" char) (canon lift (core func $m "a"))) - ) - (component $c2 - (import "a" (instance $i (export "a" (func (param "a" char))))) - (core func $a (canon lower (func $i "a"))) - (core module $m - (import "" "a" (func $a (param i32))) - (func $start (call $a (i32.const 0xd800))) - (start $start) - ) - (core instance (instantiate $m (with "" (instance (export "a" (func $a)))))) - ) - (instance $c1 (instantiate $c1)) - (instance $c2 (instantiate $c2 (with "a" (instance $c1)))) - ) - "invalid `char` bit pattern") -(assert_trap - (component - (component $c1 - (core module $m (func (export "a") (param i32))) - (core instance $m (instantiate $m)) - (func (export "a") (param "a" char) (canon lift (core func $m "a"))) - ) - (component $c2 - (import "a" (instance $i (export "a" (func (param "a" char))))) - (core func $a (canon lower (func $i "a"))) - (core module $m - (import "" "a" (func $a (param i32))) - (func $start (call $a (i32.const 0xdfff))) - (start $start) - ) - (core instance (instantiate $m (with "" (instance (export "a" (func $a)))))) - ) - (instance $c1 (instantiate $c1)) - (instance $c2 (instantiate $c2 (with "a" (instance $c1)))) - ) - "invalid `char` bit pattern") -(assert_trap - (component - (component $c1 - (core module $m (func (export "a") (param i32))) - (core instance $m (instantiate $m)) - (func (export "a") (param "a" char) (canon lift (core func $m "a"))) - ) - (component $c2 - (import "a" (instance $i (export "a" (func (param "a" char))))) - (core func $a (canon lower (func $i "a"))) - (core module $m - (import "" "a" (func $a (param i32))) - (func $start (call $a (i32.const 0x110000))) - (start $start) - ) - (core instance (instantiate $m (with "" (instance (export "a" (func $a)))))) - ) - (instance $c1 (instantiate $c1)) - (instance $c2 (instantiate $c2 (with "a" (instance $c1)))) - ) - "invalid `char` bit pattern") - -;; test that flags get their upper bits all masked off -(component - (type $f1' (flags "f1")) - (type $f8' (flags "f1" "f2" "f3" "f4" "f5" "f6" "f7" "f8")) - (type $f9' (flags "f1" "f2" "f3" "f4" "f5" "f6" "f7" "f8" "f9")) - (type $f16' (flags - "f1" "f2" "f3" "f4" "f5" "f6" "f7" "f8" - "g1" "g2" "g3" "g4" "g5" "g6" "g7" "g8" - )) - (type $f17' (flags - "f1" "f2" "f3" "f4" "f5" "f6" "f7" "f8" - "g1" "g2" "g3" "g4" "g5" "g6" "g7" "g8" - "g9" - )) - (type $f32' (flags - "f1" "f2" "f3" "f4" "f5" "f6" "f7" "f8" - "g1" "g2" "g3" "g4" "g5" "g6" "g7" "g8" - "h1" "h2" "h3" "h4" "h5" "h6" "h7" "h8" - "i1" "i2" "i3" "i4" "i5" "i6" "i7" "i8" - )) - - (component $c1 - (export $f1 "t-f1" (type $f1')) - (export $f8 "t-f8" (type $f8')) - (export $f9 "t-f9" (type $f9')) - (export $f16 "t-f16" (type $f16')) - (export $f17 "t-f17" (type $f17')) - (export $f32 "t-f32" (type $f32')) - (core module $m - (func (export "f1") (param i32) - (if (i32.ne (local.get 0) (i32.const 0x1)) (then (unreachable))) - ) - (func (export "f8") (param i32) - (if (i32.ne (local.get 0) (i32.const 0x11)) (then (unreachable))) - ) - (func (export "f9") (param i32) - (if (i32.ne (local.get 0) (i32.const 0x111)) (then (unreachable))) - ) - (func (export "f16") (param i32) - (if (i32.ne (local.get 0) (i32.const 0x1111)) (then (unreachable))) - ) - (func (export "f17") (param i32) - (if (i32.ne (local.get 0) (i32.const 0x11111)) (then (unreachable))) - ) - (func (export "f32") (param i32) - (if (i32.ne (local.get 0) (i32.const 0x11111111)) (then (unreachable))) - ) - ) - (core instance $m (instantiate $m)) - (func (export "f1") (param "a" $f1) (canon lift (core func $m "f1"))) - (func (export "f8") (param "a" $f8) (canon lift (core func $m "f8"))) - (func (export "f9") (param "a" $f9) (canon lift (core func $m "f9"))) - (func (export "f16") (param "a" $f16) (canon lift (core func $m "f16"))) - (func (export "f17") (param "a" $f17) (canon lift (core func $m "f17"))) - (func (export "f32") (param "a" $f32) (canon lift (core func $m "f32"))) - ) - (instance $c1 (instantiate $c1)) - - (component $c2 - (import "a" (instance $i - (export "t-f1" (type $f1 (eq $f1'))) - (export "t-f8" (type $f8 (eq $f8'))) - (export "t-f9" (type $f9 (eq $f9'))) - (export "t-f16" (type $f16 (eq $f16'))) - (export "t-f17" (type $f17 (eq $f17'))) - (export "t-f32" (type $f32 (eq $f32'))) - (export "f1" (func (param "a" $f1))) - (export "f8" (func (param "a" $f8))) - (export "f9" (func (param "a" $f9))) - (export "f16" (func (param "a" $f16))) - (export "f17" (func (param "a" $f17))) - (export "f32" (func (param "a" $f32))) - )) - (core func $f1 (canon lower (func $i "f1"))) - (core func $f8 (canon lower (func $i "f8"))) - (core func $f9 (canon lower (func $i "f9"))) - (core func $f16 (canon lower (func $i "f16"))) - (core func $f17 (canon lower (func $i "f17"))) - (core func $f32 (canon lower (func $i "f32"))) - - (core module $m - (import "" "f1" (func $f1 (param i32))) - (import "" "f8" (func $f8 (param i32))) - (import "" "f9" (func $f9 (param i32))) - (import "" "f16" (func $f16 (param i32))) - (import "" "f17" (func $f17 (param i32))) - (import "" "f32" (func $f32 (param i32))) - - (func $start - (call $f1 (i32.const 0xffffff01)) - (call $f8 (i32.const 0xffffff11)) - (call $f9 (i32.const 0xffffff11)) - (call $f16 (i32.const 0xffff1111)) - (call $f17 (i32.const 0xffff1111)) - (call $f32 (i32.const 0x11111111)) - ) - - (start $start) - ) - (core instance $m (instantiate $m - (with "" (instance - (export "f1" (func $f1)) - (export "f8" (func $f8)) - (export "f9" (func $f9)) - (export "f16" (func $f16)) - (export "f17" (func $f17)) - (export "f32" (func $f32)) - )) - )) - ) - (instance (instantiate $c2 (with "a" (instance $c1)))) -) - -;; Adapters are used slightly out-of-order here to stress the internals of -;; dependencies between adapters. -(component - (core module $m - (func (export "execute")) - (func (export "realloc") (param i32 i32 i32 i32) (result i32) unreachable) - (memory (export "memory") 1) - ) - - (component $root - (core instance $m (instantiate $m)) - (func (export "execute") - (canon lift (core func $m "execute")) - ) - ) - (component $c - (import "backend" (instance $i - (export "execute" (func)) - )) - (core module $shim2 (import "" "0" (func))) - (core instance $m (instantiate $m)) - - ;; This adapter, when fused with itself on the second instantiation of this - ;; component, will depended on the prior instance `$m` so it which means - ;; that the adapter module containing this must be placed in the right - ;; location. - (core func $execute - (canon lower (func $i "execute") (memory (core memory $m "memory")) (realloc (core func $m "realloc"))) - ) - (core instance (instantiate $shim2 - (with "" (instance - (export "0" (func $execute)) - )) - )) - (func (export "execute") (canon lift (core func $m "execute"))) - ) - (instance $root (instantiate $root)) - (instance $c1 (instantiate $c (with "backend" (instance $root)))) - (instance $c2 (instantiate $c (with "backend" (instance $c1)))) -) diff --git a/test/wasmtime/import.wast b/test/wasmtime/import.wast deleted file mode 100644 index 20688efe..00000000 --- a/test/wasmtime/import.wast +++ /dev/null @@ -1,20 +0,0 @@ -(assert_invalid - (component - (import "host-return-two" (func $f (result u32))) - (export "x" (func $f))) - "component export `x` is a reexport of an imported function which is not implemented") - -(assert_unlinkable - (component - (import "host-return-two" (instance)) - ) - "expected instance found func") - -;; empty instances don't need to be supplied by the host, even recursively -;; empty instances. -(component - (import "not-provided-by-the-host" (instance)) - (import "not-provided-by-the-host2" (instance - (export "x" (instance)) - )) -) diff --git a/test/wasmtime/instance.wast b/test/wasmtime/instance.wast deleted file mode 100644 index 4216cdc5..00000000 --- a/test/wasmtime/instance.wast +++ /dev/null @@ -1,327 +0,0 @@ -(component - (core module $m) - (core instance (instantiate $m)) -) - -(component - (core module $m - (func (export "")) - ) - (core instance $i (instantiate $m)) - - (core module $m2 - (func (import "" "")) - ) - (core instance (instantiate $m2 (with "" (instance $i)))) -) - -(component - (core module $m - (func (export "a")) - ) - (core instance $i (instantiate $m)) - - (core module $m2 - (func (import "" "b")) - ) - (core instance (instantiate $m2 - (with "" (instance (export "b" (func $i "a")))) - )) -) - -;; all kinds of imports for core wasm modules, and register a start function on -;; one module to ensure that everything is correct -(component - (core module $m - (func (export "a")) - (table (export "b") 1 funcref) - (memory (export "c") 1) - (global (export "d") i32 i32.const 1) - ) - (core instance $i (instantiate $m)) - - (core module $m2 - (import "" "a" (func $f)) - (import "" "b" (table 1 funcref)) - (import "" "c" (memory 1)) - (import "" "d" (global $g i32)) - - (func $start - global.get $g - i32.const 1 - i32.ne - if - unreachable - end - - call $f - ) - - (start $start) - - (data (i32.const 0) "hello") - (elem (i32.const 0) $start) - ) - (core instance (instantiate $m2 - (with "" (instance $i)) - )) -) - -;; Test to see if a component with a type export can be instantiated. -(component - (type string) - (export "a" (type 0)) -) - -;; double-check the start function runs by ensuring that a trap shows up and it -;; sees the wrong value for the global import -(assert_trap - (component - (core module $m - (global (export "g") i32 i32.const 1) - ) - (core instance $i (instantiate $m)) - - (core module $m2 - (import "" "g" (global $g i32)) - - (func $start - global.get $g - i32.const 0 - i32.ne - if - unreachable - end - ) - - (start $start) - ) - (core instance (instantiate $m2 (with "" (instance $i)))) - ) - "unreachable") - -;; shuffle around imports to get to what the target core wasm module needs -(component - (core module $m - (func (export "1")) - (table (export "2") 1 funcref) - (memory (export "3") 1) - (global (export "4") i32 i32.const 1) - ) - (core instance $i (instantiate $m)) - - (core module $m2 - (import "" "a" (func $f)) - (import "" "b" (table 1 funcref)) - (import "" "c" (memory 1)) - (import "" "d" (global $g i32)) - ) - (core instance (instantiate $m2 - (with "" (instance - (export "a" (func $i "1")) - (export "b" (table $i "2")) - (export "c" (memory $i "3")) - (export "d" (global $i "4")) - )) - )) -) - -;; indirect references through a synthetic instance -(component - (core module $m - (func (export "a")) - (table (export "b") 1 funcref) - (memory (export "c") 1) - (global (export "d") i32 i32.const 1) - ) - (core instance $i (instantiate $m)) - (core instance $i2 - (export "a1" (func $i "a")) - (export "a2" (table $i "b")) - (export "a3" (memory $i "c")) - (export "a4" (global $i "d")) - ) - - (core module $m2 - (import "" "1" (func $f)) - (import "" "2" (table 1 funcref)) - (import "" "3" (memory 1)) - (import "" "4" (global $g i32)) - ) - (core instance (instantiate $m2 - (with "" (instance - (export "1" (func $i2 "a1")) - (export "2" (table $i2 "a2")) - (export "3" (memory $i2 "a3")) - (export "4" (global $i2 "a4")) - )) - )) -) - -(component - (import "host" (instance $i (export "return-three" (func (result u32))))) - - (core module $m - (import "host" "return-three" (func $three (result i32))) - (func $start - call $three - i32.const 3 - i32.ne - if unreachable end - ) - (start $start) - ) - (core func $three_lower - (canon lower (func $i "return-three")) - ) - (core instance (instantiate $m - (with "host" (instance (export "return-three" (func $three_lower)))) - )) -) - -(component - (import "host" (instance $i - (type $x' (record (field "x" u32))) - (export "x" (type $x (eq $x'))) - (type $rec' (record (field "x" $x) (field "y" string))) - (export "rec" (type $rec (eq $rec'))) - (export "some-record" (type (eq $rec))))) -) - -(component - (import "host" (instance $i - (export "nested" (instance - (export "return-four" (func (result u32))) - )) - )) - - (core module $m - (import "host" "return-three" (func $three (result i32))) - (func $start - call $three - i32.const 4 - i32.ne - if unreachable end - ) - (start $start) - ) - (core func $three_lower - (canon lower (func $i "nested" "return-four")) - ) - (core instance (instantiate $m - (with "host" (instance (export "return-three" (func $three_lower)))) - )) -) - -(component - (import "host" (instance $i - (export "simple-module" (core module)) - )) - - (core instance (instantiate (module $i "simple-module"))) -) - -(component - (import "host" (instance $i - (export "simple-module" (core module - (export "f" (func (result i32))) - (export "g" (global i32)) - )) - )) - - (core instance $i (instantiate (module $i "simple-module"))) - (core module $verify - (import "host" "f" (func $f (result i32))) - (import "host" "g" (global $g i32)) - - (func $start - call $f - i32.const 101 - i32.ne - if unreachable end - - global.get $g - i32.const 100 - i32.ne - if unreachable end - ) - (start $start) - ) - - (core instance (instantiate $verify (with "host" (instance $i)))) -) - -;; export an instance -(component - (core module $m) - (instance $i (export "m" (core module $m))) - (export "i" (instance $i)) -) -(component - (component $c) - (instance $i (instantiate $c)) - (export "i" (instance $i)) -) -(component - (import "host" (instance $i)) - (export "i" (instance $i)) -) - - -(component definition $C1 - (type $r1 (resource (rep i32))) - (export "r" (type $r1)) -) -(component definition $C2 - (type $r1 (resource (rep i32))) - (export "r" (type $r1)) -) - -(component instance $I1 $C1) -(component instance $I2 $C1) -(component instance $I3 $C2) -(component instance $I4 $C2) - -;; all instances have different resource types -(assert_unlinkable - (component - (import "I1" (instance $i1 (export "r" (type (sub resource))))) - (alias export $i1 "r" (type $r)) - (import "I2" (instance $i2 (export "r" (type (eq $r))))) - ) - "mismatched resource types") -(assert_unlinkable - (component - (import "I1" (instance $i1 (export "r" (type (sub resource))))) - (alias export $i1 "r" (type $r)) - (import "I3" (instance $i2 (export "r" (type (eq $r))))) - ) - "mismatched resource types") -(assert_unlinkable - (component - (import "I1" (instance $i1 (export "r" (type (sub resource))))) - (alias export $i1 "r" (type $r)) - (import "I4" (instance $i2 (export "r" (type (eq $r))))) - ) - "mismatched resource types") -(assert_unlinkable - (component - (import "I2" (instance $i1 (export "r" (type (sub resource))))) - (alias export $i1 "r" (type $r)) - (import "I3" (instance $i2 (export "r" (type (eq $r))))) - ) - "mismatched resource types") -(assert_unlinkable - (component - (import "I2" (instance $i1 (export "r" (type (sub resource))))) - (alias export $i1 "r" (type $r)) - (import "I4" (instance $i2 (export "r" (type (eq $r))))) - ) - "mismatched resource types") -(assert_unlinkable - (component - (import "I3" (instance $i1 (export "r" (type (sub resource))))) - (alias export $i1 "r" (type $r)) - (import "I4" (instance $i2 (export "r" (type (eq $r))))) - ) - "mismatched resource types") diff --git a/test/wasmtime/linking.wast b/test/wasmtime/linking.wast deleted file mode 100644 index 966926f0..00000000 --- a/test/wasmtime/linking.wast +++ /dev/null @@ -1,18 +0,0 @@ -(assert_unlinkable - (component - (import "undefined-name" (core module)) - ) - "was not found") -(component $i) -(component - (import "i" (instance)) -) -(assert_unlinkable - (component (import "i" (core module))) - "expected module found instance") -(assert_unlinkable - (component (import "i" (func))) - "expected function found instance") -(assert_unlinkable - (component (import "i" (instance (export "x" (func))))) - "was not found") diff --git a/test/wasmtime/modules.wast b/test/wasmtime/modules.wast deleted file mode 100644 index 6014f94e..00000000 --- a/test/wasmtime/modules.wast +++ /dev/null @@ -1,479 +0,0 @@ -;;! reference_types = true - -(component $foo - (core module (export "a-module")) -) - -;; the above instance can be imported into this component -(component - (import "foo" (instance - (export "a-module" (core module)) - )) -) - -;; specifying extra imports is ok -(component - (import "foo" (instance - (export "a-module" (core module - (import "foo" "bar" (func)) - )) - )) -) - -;; specifying extra exports is not ok -(assert_unlinkable - (component - (import "foo" (instance - (export "a-module" (core module - (export "the-export" (func)) - )) - )) - ) - "module export `the-export` not defined") - -(component $foo - (core module (export "a-module") - (import "env" "something" (func)) - ) -) - -;; imports must be specified -(assert_unlinkable - (component - (import "foo" (instance - (export "a-module" (core module)) - )) - ) - "module import `env::something` not defined") - -(component - (import "foo" (instance - (export "a-module" (core module - (import "env" "something" (func)) - )) - )) -) - -;; extra imports still ok -(component - (import "foo" (instance - (export "a-module" (core module - (import "env" "something" (func)) - (import "env" "other" (global i32)) - )) - )) -) - -(component $foo - (core module (export "a-module") - (func (export "f")) - ) -) - -;; dropping exports is ok -(component - (import "foo" (instance - (export "a-module" (core module)) - )) -) - -(component - (import "foo" (instance - (export "a-module" (core module - (export "f" (func)) - )) - )) -) - -(assert_unlinkable - (component - (import "foo" (instance - (export "a-module" (core module - (export "f" (func (param i32))) - )) - )) - ) - "expected type `(func (param i32))`, found type `(func)`") - -(assert_unlinkable - (component - (import "foo" (instance - (export "a-module" (core module - (export "f" (global i32)) - )) - )) - ) - "expected global found func") - -(component $foo - (core module (export "m") - (func (export "f")) - (table (export "t") 1 funcref) - (memory (export "m") 1) - (global (export "g") i32 i32.const 0) - ) -) - -;; wrong class of item -(assert_unlinkable - (component - (import "foo" (instance - (export "m" (core module (export "f" (global i32)))) - )) - ) - "expected global found func") -(assert_unlinkable - (component - (import "foo" (instance - (export "m" (core module (export "t" (func)))) - )) - ) - "expected func found table") -(assert_unlinkable - (component - (import "foo" (instance - (export "m" (core module (export "m" (func)))) - )) - ) - "expected func found memory") -(assert_unlinkable - (component - (import "foo" (instance - (export "m" (core module (export "g" (func)))) - )) - ) - "expected func found global") - -;; wrong item type -(assert_unlinkable - (component - (import "foo" (instance - (export "m" (core module (export "f" (func (param i32))))) - )) - ) - "export `f` has the wrong type") -(assert_unlinkable - (component - (import "foo" (instance - (export "m" (core module (export "t" (table 1 externref)))) - )) - ) - "export `t` has the wrong type") -(assert_unlinkable - (component - (import "foo" (instance - (export "m" (core module (export "t" (table 2 funcref)))) - )) - ) - "export `t` has the wrong type") -(assert_unlinkable - (component - (import "foo" (instance - (export "m" (core module (export "m" (memory 2)))) - )) - ) - "export `m` has the wrong type") -(assert_unlinkable - (component - (import "foo" (instance - (export "m" (core module (export "g" (global f32)))) - )) - ) - "export `g` has the wrong type") -(assert_unlinkable - (component - (import "foo" (instance - (export "m" (core module (export "g" (global (mut i32))))) - )) - ) - "export `g` has the wrong type") - -;; subtyping ok -(component - (import "foo" (instance - (export "m" (core module - (export "t" (table 0 funcref)) - (export "m" (memory 0)) - )) - )) -) - -(component $foo - (core module (export "f") (func (import "" ""))) - (core module (export "t") (table (import "" "") 1 funcref)) - (core module (export "m") (memory (import "" "") 1)) - (core module (export "g") (global (import "" "") i32)) -) - -;; wrong class of item -(assert_unlinkable - (component - (import "foo" (instance - (export "f" (core module (import "" "" (global i32)))) - )) - ) - "expected func found global") -(assert_unlinkable - (component - (import "foo" (instance - (export "t" (core module (import "" "" (func)))) - )) - ) - "expected table found func") -(assert_unlinkable - (component - (import "foo" (instance - (export "m" (core module (import "" "" (func)))) - )) - ) - "expected memory found func") -(assert_unlinkable - (component - (import "foo" (instance - (export "g" (core module (import "" "" (func)))) - )) - ) - "expected global found func") - -;; wrong item type -(assert_unlinkable - (component - (import "foo" (instance - (export "f" (core module (import "" "" (func (param i32))))) - )) - ) - "module import `::` has the wrong type") -(assert_unlinkable - (component - (import "foo" (instance - (export "t" (core module (import "" "" (table 1 externref)))) - )) - ) - "module import `::` has the wrong type") -(assert_unlinkable - (component - (import "foo" (instance - (export "t" (core module (import "" "" (table 0 funcref)))) - )) - ) - "module import `::` has the wrong type") -(assert_unlinkable - (component - (import "foo" (instance - (export "m" (core module (import "" "" (memory 0)))) - )) - ) - "module import `::` has the wrong type") -(assert_unlinkable - (component - (import "foo" (instance - (export "g" (core module (import "" "" (global f32)))) - )) - ) - "module import `::` has the wrong type") -(assert_unlinkable - (component - (import "foo" (instance - (export "g" (core module (import "" "" (global (mut i32))))) - )) - ) - "module import `::` has the wrong type") - -;; subtyping ok, but in the opposite direction of imports -(component - (import "foo" (instance - (export "t" (core module (import "" "" (table 2 funcref)))) - (export "m" (core module (import "" "" (memory 2)))) - )) -) - -;; An instance can reexport a module, define a module, and everything can be -;; used by something else -(component $src - (core module (export "m") - (global (export "g") i32 i32.const 2) - ) -) - -(component $reexport - (core module $m1 - (global (export "g") i32 i32.const 1) - ) - (import "src" (instance $src - (export "m" (core module (export "g" (global i32)))) - )) - - (core module $m3 - (global (export "g") i32 i32.const 3) - ) - - (export "m1" (core module $m1)) - (export "m2" (core module $src "m")) - (export "m3" (core module $m3)) -) - -(component - (core type $modulety (module (export "g" (global i32)))) - (import "reexport" (instance $reexport - (export "m1" (core module (type $modulety))) - (export "m2" (core module (type $modulety))) - (export "m3" (core module (type $modulety))) - )) - - (core module $assert_ok - (import "m1" "g" (global $m1 i32)) - (import "m2" "g" (global $m2 i32)) - (import "m3" "g" (global $m3 i32)) - - (func $assert_ok - block - global.get $m1 - i32.const 1 - i32.eq - br_if 0 - unreachable - end - block - global.get $m2 - i32.const 2 - i32.eq - br_if 0 - unreachable - end - block - global.get $m3 - i32.const 3 - i32.eq - br_if 0 - unreachable - end - ) - - (start $assert_ok) - ) - - (core instance $m1 (instantiate (module $reexport "m1"))) - (core instance $m2 (instantiate (module $reexport "m2"))) - (core instance $m3 (instantiate (module $reexport "m3"))) - - (core instance (instantiate $assert_ok - (with "m1" (instance $m1)) - (with "m2" (instance $m2)) - (with "m3" (instance $m3)) - )) -) - -;; order of imports and exports can be shuffled between definition site and -;; use-site -(component $provider - (core module (export "m") - (import "" "1" (global $i1 i32)) - (import "" "2" (global $i2 i32)) - (import "" "3" (global $i3 i32)) - (import "" "4" (global $i4 i32)) - - (global $g1 i32 i32.const 100) - (global $g2 i32 i32.const 101) - (global $g3 i32 i32.const 102) - (global $g4 i32 i32.const 103) - - (func $assert_imports - (block - global.get $i1 - i32.const 1 - i32.eq - br_if 0 - unreachable) - (block - global.get $i2 - i32.const 2 - i32.eq - br_if 0 - unreachable) - (block - global.get $i3 - i32.const 3 - i32.eq - br_if 0 - unreachable) - (block - global.get $i4 - i32.const 4 - i32.eq - br_if 0 - unreachable) - ) - - (start $assert_imports) - - (export "g1" (global $g1)) - (export "g2" (global $g2)) - (export "g3" (global $g3)) - (export "g4" (global $g4)) - ) -) - -(component - (import "provider" (instance $provider - (export "m" (core module - (import "" "4" (global i32)) - (import "" "3" (global i32)) - (import "" "2" (global i32)) - (import "" "1" (global i32)) - - (export "g4" (global i32)) - (export "g3" (global i32)) - (export "g2" (global i32)) - (export "g1" (global i32)) - )) - )) - - (core module $imports - (global (export "1") i32 (i32.const 1)) - (global (export "3") i32 (i32.const 3)) - (global (export "2") i32 (i32.const 2)) - (global (export "4") i32 (i32.const 4)) - ) - (core instance $imports (instantiate $imports)) - (core instance $m (instantiate (module $provider "m") - (with "" (instance $imports)) - )) - - (core module $import_globals - (import "" "g4" (global $g4 i32)) - (import "" "g3" (global $g3 i32)) - (import "" "g2" (global $g2 i32)) - (import "" "g1" (global $g1 i32)) - - (func $assert_imports - (block - global.get $g1 - i32.const 100 - i32.eq - br_if 0 - unreachable) - (block - global.get $g2 - i32.const 101 - i32.eq - br_if 0 - unreachable) - (block - global.get $g3 - i32.const 102 - i32.eq - br_if 0 - unreachable) - (block - global.get $g4 - i32.const 103 - i32.eq - br_if 0 - unreachable) - ) - - (start $assert_imports) - ) - - (core instance (instantiate $import_globals (with "" (instance $m)))) -) diff --git a/test/wasmtime/nested.wast b/test/wasmtime/nested.wast deleted file mode 100644 index 8cb4c381..00000000 --- a/test/wasmtime/nested.wast +++ /dev/null @@ -1,451 +0,0 @@ -;; simple nested component -(component - (component) -) - -;; simple nested component with a nested module -(component - (component - (core module) - ) -) - -;; simple instantiation of a nested component -(component - (component $c) - (instance (instantiate $c)) - (instance (instantiate $c - (with "x" (component $c)) - )) -) - -;; instantiate a module during a nested component, and also instantiate it -;; as an export of the nested component -(component - (component $c - (core module $m) - (core instance (instantiate $m)) - (export "m" (core module $m)) - ) - (instance $i (instantiate $c)) - (core instance $i (instantiate (module $i "m"))) -) - -;; instantiate an inner exported module with two different modules and -;; verify imports match -(component - (component $c - (core module $m - (import "" "g" (global $g i32)) - (import "" "f" (func $f (result i32))) - - (func $start - call $f - global.get $g - i32.ne - if unreachable end) - - (start $start) - ) - - (core module $m2 - (global (export "g") i32 i32.const 1) - (func (export "f") (result i32) i32.const 1) - ) - (core instance $i2 (instantiate $m2)) - (core instance (instantiate $m (with "" (instance $i2)))) - - (export "m" (core module $m)) - ) - (instance $i (instantiate $c)) - (core module $m2 - (global (export "g") i32 i32.const 5) - (func (export "f") (result i32) i32.const 5) - ) - (core instance $i2 (instantiate $m2)) - (core instance (instantiate (module $i "m") (with "" (instance $i2)))) -) - -;; instantiate an inner component with a module import -(component - (component $c - (import "m" (core module $m - (export "g" (global i32)) - )) - - (core instance $i (instantiate $m)) - - (core module $verify - (import "" "g" (global $g i32)) - - (func $start - global.get $g - i32.const 2 - i32.ne - if unreachable end - ) - - (start $start) - ) - (core instance (instantiate $verify (with "" (instance $i)))) - ) - - (core module $m - (global (export "g") i32 (i32.const 2)) - ) - (instance (instantiate $c (with "m" (core module $m)))) -) - -;; instantiate an inner component with a module import that itself has imports -(component - (component $c - (import "m" (core module $m - (import "" "g" (global i32)) - )) - (core module $m2 - (global (export "g") i32 i32.const 2100) - ) - (core instance $m2 (instantiate $m2)) - (core instance (instantiate $m (with "" (instance $m2)))) - ) - - (core module $verify - (import "" "g" (global $g i32)) - - (func $start - global.get $g - i32.const 2100 - i32.ne - if unreachable end - ) - - (start $start) - ) - (instance (instantiate $c (with "m" (core module $verify)))) -) - -;; instantiate an inner component with an export from the outer component -(component $c - (core module (export "m") - (import "" "g1" (global $g1 i32)) - (import "" "g2" (global $g2 i32)) - - (func $start - global.get $g1 - i32.const 10000 - i32.ne - if unreachable end - - global.get $g2 - i32.const 20000 - i32.ne - if unreachable end - ) - - (start $start) - ) -) - -(component - (import "c" (instance $i - (export "m" (core module - (import "" "g2" (global i32)) - (import "" "g1" (global i32)) - )) - )) - - (component $c - (import "m" (core module $verify - (import "" "g2" (global i32)) - (import "" "g1" (global i32)) - )) - - (core module $m - (global (export "g1") i32 i32.const 10000) - (global (export "g2") i32 i32.const 20000) - ) - (core instance $m (instantiate $m)) - (core instance (instantiate $verify (with "" (instance $m)))) - ) - - (instance (instantiate $c (with "m" (core module $i "m")))) -) - -;; instantiate a reexported module -(component - (core module $m - (global (export "g") i32 i32.const 7) - ) - (component $c - (import "i" (instance $i - (export "m" (core module - (import "" "" (func)) - (export "g" (global i32)) - )) - )) - - (export "m" (core module $i "m")) - ) - - (instance $c (instantiate $c (with "i" (instance (export "m" (core module $m)))))) - (core module $dummy - (func (export "")) - ) - (core instance $dummy (instantiate $dummy)) - - (core instance $m (instantiate (module $c "m") (with "" (instance $dummy)))) - - (core module $verify - (import "" "g" (global i32)) - (func $start - global.get 0 - i32.const 7 - i32.ne - if unreachable end - ) - - (start $start) - ) - (core instance (instantiate $verify (with "" (instance $m)))) -) - -;; module must be found through a few layers of imports -(component $c - (core module (export "m") - (global (export "g") i32 i32.const 101) - ) -) - -(component - (import "c" (instance $i - (export "m" (core module - (export "g" (global i32)) - )) - )) - (component $c1 - (import "c" (instance $i - (export "m" (core module - (export "g" (global i32)) - )) - )) - (core module $verify - (import "" "g" (global i32)) - (func $start - global.get 0 - i32.const 101 - i32.ne - if unreachable end - ) - - (start $start) - ) - (core instance $m (instantiate (module $i "m"))) - (core instance (instantiate $verify (with "" (instance $m)))) - ) - (instance (instantiate $c1 (with "c" (instance $i)))) -) - -;; instantiate outer alias to self -(component $C - (core module $m) - (alias outer $C $m (core module $other_m)) - (core instance (instantiate $other_m)) -) - -(component $C - (component $m) - (alias outer $C $m (component $other_m)) - (instance (instantiate $other_m)) -) - - -;; closing over an outer alias which is actually an argument to some -;; instantiation -(component - (component $c - (import "c" (core module $c - (export "a" (global i32)) - )) - - (component (export "c2") - (export "m" (core module $c)) - ) - ) - - (core module $m1 (global (export "a") i32 i32.const 1)) - (core module $m2 (global (export "a") i32 i32.const 2)) - - (instance $c1 (instantiate $c (with "c" (core module $m1)))) - (instance $c2 (instantiate $c (with "c" (core module $m2)))) - - (instance $m1_container (instantiate (component $c1 "c2"))) - (instance $m2_container (instantiate (component $c2 "c2"))) - - (core instance $core1 (instantiate (module $m1_container "m"))) - (core instance $core2 (instantiate (module $m2_container "m"))) - - (core module $verify - (import "core1" "a" (global $a i32)) - (import "core2" "a" (global $b i32)) - - (func $start - global.get $a - i32.const 1 - i32.ne - if unreachable end - - global.get $b - i32.const 2 - i32.ne - if unreachable end - ) - - (start $start) - ) - (core instance (instantiate $verify - (with "core1" (instance $core1)) - (with "core2" (instance $core2)) - )) -) - -;; simple importing of a component -(component - (component $C) - (component $other - (import "x" (component $c)) - (instance (instantiate $c)) - ) - (instance (instantiate $other (with "x" (component $C)))) -) - -;; deep nesting -(component $C - (core module $m - (global (export "g") i32 (i32.const 1)) - ) - (component $c - (core module (export "m") - (global (export "g") i32 (i32.const 2)) - ) - ) - - (component $c1 - (component $c2 (export "a") - (component $c3 (export "a") - (alias outer $C $m (core module $my_module)) - (alias outer $C $c (component $my_component)) - - (export "m" (core module $my_module)) - (export "c" (component $my_component)) - ) - ) - ) - - (instance $i1 (instantiate $c1)) - (instance $i2 (instantiate (component $i1 "a"))) - (instance $i3 (instantiate (component $i2 "a"))) - - (core instance $m1 (instantiate (module $i3 "m"))) - (instance $c (instantiate (component $i3 "c"))) - (core instance $m2 (instantiate (module $c "m"))) - - (core module $verify - (import "m1" "g" (global $m1 i32)) - (import "m2" "g" (global $m2 i32)) - - (func $start - global.get $m1 - i32.const 1 - i32.ne - if unreachable end - - global.get $m2 - i32.const 2 - i32.ne - if unreachable end - ) - (start $start) - ) - (core instance (instantiate $verify (with "m1" (instance $m1)) (with "m2" (instance $m2)))) -) - -;; Try threading through component instantiation arguments as various forms of -;; instances. -(component - (component $c - (core module $m (export "m")) - (component $c (export "c") - (core module (export "m")) - ) - (instance $i (instantiate $c)) - (instance $i2 - (export "m" (core module $m)) - (export "c" (component $c)) - (export "i" (instance $i)) - ) - (export "i" (instance $i)) - (export "i2" (instance $i2)) - ) - (instance $i (instantiate $c)) - - (component $another - (import "host" (instance - (export "m" (core module)) - (export "c" (component)) - (export "i" (instance)) - )) - ) - (instance (instantiate $another (with "host" (instance $i)))) - (instance (instantiate $another (with "host" (instance $i "i2")))) - - (instance $reexport - (export "c" (component $i "c")) - (export "m" (core module $i "m")) - (export "i" (instance $i "i")) - ) - (instance (instantiate $another (with "host" (instance $reexport)))) -) - -;; thread host functions around -(component - (import "host-return-two" (func $import (result u32))) - - ;; thread the host function through an instance - (component $c - (import "a" (func $f (result u32))) - (export "f" (func $f)) - ) - (instance $c (instantiate $c (with "a" (func $import)))) - (alias export $c "f" (func $import2)) - - ;; thread the host function into a nested component - (component $c2 - (import "host" (instance $i (export "return-two" (func (result u32))))) - - (core module $m - (import "host" "return-two" (func $host (result i32))) - (func $start - call $host - i32.const 2 - i32.ne - if unreachable end - ) - (start $start) - ) - - (core func $return_two - (canon lower (func $i "return-two")) - ) - (core instance (instantiate $m - (with "host" (instance - (export "return-two" (func $return_two)) - )) - )) - ) - - (instance (instantiate $c2 - (with "host" (instance - (export "return-two" (func $import2)) - )) - )) -) diff --git a/test/wasmtime/resources.wast b/test/wasmtime/resources.wast deleted file mode 100644 index 5f58a0a5..00000000 --- a/test/wasmtime/resources.wast +++ /dev/null @@ -1,1091 +0,0 @@ -;; bare bones "intrinsics work" -(component - (type $r (resource (rep i32))) - (core func $rep (canon resource.rep $r)) - (core func $new (canon resource.new $r)) - (core func $drop (canon resource.drop $r)) - - (core module $m - (import "" "rep" (func $rep (param i32) (result i32))) - (import "" "new" (func $new (param i32) (result i32))) - (import "" "drop" (func $drop (param i32))) - - (func $start - (local $r i32) - (local.set $r (call $new (i32.const 100))) - - (if (i32.ne (local.get $r) (i32.const 1)) (then (unreachable))) - (if (i32.ne (call $rep (local.get $r)) (i32.const 100)) (then (unreachable))) - - (call $drop (local.get $r)) - ) - - (start $start) - ) - (core instance (instantiate $m - (with "" (instance - (export "rep" (func $rep)) - (export "new" (func $new)) - (export "drop" (func $drop)) - )) - )) -) - -;; cannot call `resource.drop` on a nonexistent resource -(component - (type $r (resource (rep i32))) - (core func $drop (canon resource.drop $r)) - - (core module $m - (import "" "drop" (func $drop (param i32))) - - (func (export "r") - (call $drop (i32.const 0)) - ) - ) - (core instance $i (instantiate $m - (with "" (instance - (export "drop" (func $drop)) - )) - )) - - (func (export "r") (canon lift (core func $i "r"))) -) -(assert_trap (invoke "r") "unknown handle index 0") - -;; cannot call `resource.rep` on a nonexistent resource -(component - (type $r (resource (rep i32))) - (core func $rep (canon resource.rep $r)) - - (core module $m - (import "" "rep" (func $rep (param i32) (result i32))) - - (func (export "r") - (drop (call $rep (i32.const 0))) - ) - ) - (core instance $i (instantiate $m - (with "" (instance - (export "rep" (func $rep)) - )) - )) - - (func (export "r") (canon lift (core func $i "r"))) -) -(assert_trap (invoke "r") "unknown handle index 0") - -;; index reuse behavior of handles -(component - (type $r (resource (rep i32))) - (core func $rep (canon resource.rep $r)) - (core func $new (canon resource.new $r)) - (core func $drop (canon resource.drop $r)) - - (core module $m - (import "" "rep" (func $rep (param i32) (result i32))) - (import "" "new" (func $new (param i32) (result i32))) - (import "" "drop" (func $drop (param i32))) - - (func $start - (local $r1 i32) - (local $r2 i32) - (local $r3 i32) - (local $r4 i32) - - ;; resources assigned sequentially - (local.set $r1 (call $new (i32.const 100))) - (if (i32.ne (local.get $r1) (i32.const 1)) (then (unreachable))) - - (local.set $r2 (call $new (i32.const 200))) - (if (i32.ne (local.get $r2) (i32.const 2)) (then (unreachable))) - - (local.set $r3 (call $new (i32.const 300))) - (if (i32.ne (local.get $r3) (i32.const 3)) (then (unreachable))) - - ;; representations all look good - (if (i32.ne (call $rep (local.get $r1)) (i32.const 100)) (then (unreachable))) - (if (i32.ne (call $rep (local.get $r2)) (i32.const 200)) (then (unreachable))) - (if (i32.ne (call $rep (local.get $r3)) (i32.const 300)) (then (unreachable))) - - ;; reallocate r2 - (call $drop (local.get $r2)) - (local.set $r2 (call $new (i32.const 400))) - - ;; should have reused index 3 - (if (i32.ne (local.get $r2) (i32.const 2)) (then (unreachable))) - - ;; representations all look good - (if (i32.ne (call $rep (local.get $r1)) (i32.const 100)) (then (unreachable))) - (if (i32.ne (call $rep (local.get $r2)) (i32.const 400)) (then (unreachable))) - (if (i32.ne (call $rep (local.get $r3)) (i32.const 300)) (then (unreachable))) - - ;; deallocate, then reallocate - (call $drop (local.get $r1)) - (call $drop (local.get $r2)) - (call $drop (local.get $r3)) - - (local.set $r1 (call $new (i32.const 500))) - (local.set $r2 (call $new (i32.const 600))) - (local.set $r3 (call $new (i32.const 700))) - - ;; representations all look good - (if (i32.ne (call $rep (local.get $r1)) (i32.const 500)) (then (unreachable))) - (if (i32.ne (call $rep (local.get $r2)) (i32.const 600)) (then (unreachable))) - (if (i32.ne (call $rep (local.get $r3)) (i32.const 700)) (then (unreachable))) - - ;; indices should be lifo - (if (i32.ne (local.get $r1) (i32.const 3)) (then (unreachable))) - (if (i32.ne (local.get $r2) (i32.const 2)) (then (unreachable))) - (if (i32.ne (local.get $r3) (i32.const 1)) (then (unreachable))) - - ;; bump one more time - (local.set $r4 (call $new (i32.const 800))) - (if (i32.ne (local.get $r4) (i32.const 4)) (then (unreachable))) - - ;; deallocate everything - (call $drop (local.get $r1)) - (call $drop (local.get $r2)) - (call $drop (local.get $r3)) - (call $drop (local.get $r4)) - ) - - (start $start) - ) - (core instance (instantiate $m - (with "" (instance - (export "rep" (func $rep)) - (export "new" (func $new)) - (export "drop" (func $drop)) - )) - )) -) - -(assert_unlinkable - (component - (import "host" (instance - (export "missing" (type (sub resource))) - )) - ) - "was not found") -(assert_unlinkable - (component - (import "host" (instance - (export "return-three" (type (sub resource))) - )) - ) - "expected resource found func") - -;; all resources can be uniquely imported -(component - (import "host" (instance - (export "resource1" (type (sub resource))) - (export "resource2" (type (sub resource))) - (export "resource1-again" (type (sub resource))) - )) -) - -;; equality constraints also work -(component - (import "host" (instance - (export "resource1" (type $r1 (sub resource))) - (export "resource2" (type (sub resource))) - (export "resource1-again" (type (eq $r1))) - )) -) - -;; equality constraints are checked if resources are supplied -(assert_unlinkable - (component - (import "host" (instance - (export "resource1" (type (sub resource))) - (export "resource2" (type $r1 (sub resource))) - (export "resource1-again" (type (eq $r1))) - )) - ) - "mismatched resource types") - -;; equality constraints mean that types don't need to be supplied -(component - (import "host" (instance - (export "resource1" (type $r1 (sub resource))) - (export "resource2" (type (sub resource))) - (export "this-name-is-not-provided-in-the-wast-harness" (type (eq $r1))) - )) -) - -;; simple properties of handles -(component - (import "host" (instance $host - (export "resource1" (type $r (sub resource))) - (export "[constructor]resource1" (func (param "r" u32) (result (own $r)))) - (export "[static]resource1.assert" (func (param "r" (own $r)) (param "rep" u32))) - )) - (alias export $host "resource1" (type $r)) - (alias export $host "[constructor]resource1" (func $ctor)) - (alias export $host "[static]resource1.assert" (func $assert)) - - (core func $drop (canon resource.drop $r)) - (core func $ctor (canon lower (func $ctor))) - (core func $assert (canon lower (func $assert))) - - (core module $m - (import "" "drop" (func $drop (param i32))) - (import "" "ctor" (func $ctor (param i32) (result i32))) - (import "" "assert" (func $assert (param i32 i32))) - - (func $start - (local $r1 i32) - (local $r2 i32) - (local.set $r1 (call $ctor (i32.const 100))) - (local.set $r2 (call $ctor (i32.const 200))) - - ;; assert r1/r2 are sequential - (if (i32.ne (local.get $r1) (i32.const 1)) (then (unreachable))) - (if (i32.ne (local.get $r2) (i32.const 2)) (then (unreachable))) - - ;; reallocate r1 and it should be reassigned the same index - (call $drop (local.get $r1)) - (local.set $r1 (call $ctor (i32.const 300))) - (if (i32.ne (local.get $r1) (i32.const 1)) (then (unreachable))) - - ;; internal values should match - (call $assert (local.get $r1) (i32.const 300)) - (call $assert (local.get $r2) (i32.const 200)) - ) - - (start $start) - ) - (core instance (instantiate $m - (with "" (instance - (export "drop" (func $drop)) - (export "ctor" (func $ctor)) - (export "assert" (func $assert)) - )) - )) -) - -;; Using an index that has never been valid is a trap -(component - (import "host" (instance $host - (export "resource1" (type $r (sub resource))) - (export "[static]resource1.assert" (func (param "r" (own $r)) (param "rep" u32))) - )) - (alias export $host "resource1" (type $r)) - (alias export $host "[static]resource1.assert" (func $assert)) - (core func $assert (canon lower (func $assert))) - - (core module $m - (import "" "assert" (func $assert (param i32 i32))) - - (func (export "f") - (call $assert (i32.const 0) (i32.const 0)) - ) - ) - (core instance $i (instantiate $m - (with "" (instance - (export "assert" (func $assert)) - )) - )) - - (func (export "f") (canon lift (core func $i "f"))) -) - -(assert_trap (invoke "f") "unknown handle index") - -;; Using an index which was previously valid but no longer valid is also a trap. -(component - (import "host" (instance $host - (export "resource1" (type $r (sub resource))) - (export "[constructor]resource1" (func (param "r" u32) (result (own $r)))) - (export "[static]resource1.assert" (func (param "r" (own $r)) (param "rep" u32))) - )) - (alias export $host "[constructor]resource1" (func $ctor)) - (alias export $host "[static]resource1.assert" (func $assert)) - - (core func $assert (canon lower (func $assert))) - (core func $ctor (canon lower (func $ctor))) - - (core module $m - (import "" "assert" (func $assert (param i32 i32))) - (import "" "ctor" (func $ctor (param i32) (result i32))) - - (global $handle (mut i32) i32.const 0) - - (func (export "f") - (global.set $handle (call $ctor (i32.const 100))) - (call $assert (global.get $handle) (i32.const 100)) - ) - - (func (export "f2") - (call $assert (global.get $handle) (i32.const 100)) - ) - ) - (core instance $i (instantiate $m - (with "" (instance - (export "assert" (func $assert)) - (export "ctor" (func $ctor)) - )) - )) - - (func (export "f") (canon lift (core func $i "f"))) - (func (export "f2") (canon lift (core func $i "f2"))) -) - -(assert_return (invoke "f")) -(assert_trap (invoke "f2") "unknown handle index") - -;; Also invalid to pass a previously valid handle to the drop intrinsic -(component - (import "host" (instance $host - (export "resource1" (type $r (sub resource))) - (export "[constructor]resource1" (func (param "r" u32) (result (own $r)))) - )) - (alias export $host "resource1" (type $r)) - (alias export $host "[constructor]resource1" (func $ctor)) - - (core func $drop (canon resource.drop $r)) - (core func $ctor (canon lower (func $ctor))) - - (core module $m - (import "" "drop" (func $drop (param i32))) - (import "" "ctor" (func $ctor (param i32) (result i32))) - - (global $handle (mut i32) i32.const 0) - - (func (export "f") - (global.set $handle (call $ctor (i32.const 100))) - (call $drop (global.get $handle)) - ) - - (func (export "f2") - (call $drop (global.get $handle)) - ) - ) - (core instance $i (instantiate $m - (with "" (instance - (export "ctor" (func $ctor)) - (export "drop" (func $drop)) - )) - )) - - (func (export "f") (canon lift (core func $i "f"))) - (func (export "f2") (canon lift (core func $i "f2"))) -) - -(assert_return (invoke "f")) -(assert_trap (invoke "f2") "unknown handle index") - -;; If an inner component instantiates a resource then an outer component -;; should not implicitly have access to that resource. -(component - (import "host" (instance $host - (export "resource1" (type $r (sub resource))) - (export "[constructor]resource1" (func (param "r" u32) (result (own $r)))) - )) - - ;; an inner component which upon instantiation will invoke the constructor, - ;; assert that it's zero, and then forget about it. - (component $inner - (import "host" (instance $host - (export "resource1" (type $r (sub resource))) - (export "[constructor]resource1" (func (param "r" u32) (result (own $r)))) - )) - (alias export $host "[constructor]resource1" (func $ctor)) - - (core func $ctor (canon lower (func $ctor))) - - (core module $m - (import "" "ctor" (func $ctor (param i32) (result i32))) - - (func $start - (if (i32.ne (call $ctor (i32.const 100)) (i32.const 0)) (then (unreachable))) - ) - ) - (core instance $i (instantiate $m - (with "" (instance (export "ctor" (func $ctor)))) - )) - ) - (instance $i (instantiate $inner (with "host" (instance $host)))) - - ;; the rest of this component which is a single function that invokes `drop` - ;; for index 0. The index 0 should be valid within the above component, but - ;; it is not valid within this component - (alias export $host "resource1" (type $r)) - (core func $drop (canon resource.drop $r)) - - (core module $m - (import "" "drop" (func $drop (param i32))) - - (func (export "f") - (call $drop (i32.const 0)) - ) - ) - (core instance $i (instantiate $m - (with "" (instance - (export "drop" (func $drop)) - )) - )) - - (func (export "f") (canon lift (core func $i "f"))) -) - -(assert_trap (invoke "f") "unknown handle index") - -;; Same as the above test, but for resources defined within a component -(component - (component $inner - (type $r (resource (rep i32))) - - (core func $ctor (canon resource.new $r)) - - (core module $m - (import "" "ctor" (func $ctor (param i32) (result i32))) - - (func $start - (if (i32.ne (call $ctor (i32.const 100)) (i32.const 1)) (then (unreachable))) - ) - (start $start) - ) - (core instance $i (instantiate $m - (with "" (instance (export "ctor" (func $ctor)))) - )) - (export "r" (type $r)) - ) - (instance $i (instantiate $inner)) - - ;; the rest of this component which is a single function that invokes `drop` - ;; for index 1. The index 1 should be valid within the above component, but - ;; it is not valid within this component - (alias export $i "r" (type $r)) - (core func $drop (canon resource.drop $r)) - - (core module $m - (import "" "drop" (func $drop (param i32))) - - (func (export "f") - (call $drop (i32.const 1)) - ) - ) - (core instance $i (instantiate $m - (with "" (instance - (export "drop" (func $drop)) - )) - )) - - (func (export "f") (canon lift (core func $i "f"))) -) - -(assert_trap (invoke "f") "unknown handle index 1") - -;; Each instantiation of a component generates a unique resource type, so -;; allocating in one component and deallocating in another should fail. -(component - (component $inner - (type $r (resource (rep i32))) - - (core func $ctor (canon resource.new $r)) - (core func $drop (canon resource.drop $r)) - - (core module $m - (import "" "ctor" (func $ctor (param i32) (result i32))) - (import "" "drop" (func $drop (param i32))) - - (func (export "alloc") - (if (i32.ne (call $ctor (i32.const 100)) (i32.const 1)) (then (unreachable))) - ) - (func (export "dealloc") - (call $drop (i32.const 1)) - ) - ) - (core instance $i (instantiate $m - (with "" (instance - (export "ctor" (func $ctor)) - (export "drop" (func $drop)) - )) - )) - (func (export "alloc") (canon lift (core func $i "alloc"))) - (func (export "dealloc") (canon lift (core func $i "dealloc"))) - ) - (instance $i1 (instantiate $inner)) - (instance $i2 (instantiate $inner)) - - (alias export $i1 "alloc" (func $alloc_in_1)) - (alias export $i1 "dealloc" (func $dealloc_in_1)) - (alias export $i2 "alloc" (func $alloc_in_2)) - (alias export $i2 "dealloc" (func $dealloc_in_2)) - - (export "alloc-in1" (func $alloc_in_1)) - (export "dealloc-in1" (func $dealloc_in_1)) - (export "alloc-in2" (func $alloc_in_2)) - (export "dealloc-in2" (func $dealloc_in_2)) -) - -(assert_return (invoke "alloc-in1")) -(assert_return (invoke "dealloc-in1")) -(assert_return (invoke "alloc-in1")) -(assert_return (invoke "alloc-in2")) -(assert_return (invoke "dealloc-in2")) -(assert_trap (invoke "dealloc-in2") "unknown handle index") - -;; Same as above, but the same host resource type is imported into a -;; component that is instantiated twice. Each component instance should -;; receive different tables tracking resources so a resource allocated in one -;; should not be visible in the other. -(component - (import "host" (instance $host - (export "resource1" (type $r (sub resource))) - (export "[constructor]resource1" (func (param "r" u32) (result (own $r)))) - )) - (alias export $host "resource1" (type $r)) - (alias export $host "[constructor]resource1" (func $ctor)) - - (component $inner - (import "r" (type $r (sub resource))) - (import "[constructor]r" (func $ctor (param "r" u32) (result (own $r)))) - - (core func $ctor (canon lower (func $ctor))) - (core func $drop (canon resource.drop $r)) - - (core module $m - (import "" "ctor" (func $ctor (param i32) (result i32))) - (import "" "drop" (func $drop (param i32))) - - (func (export "alloc") - (if (i32.ne (call $ctor (i32.const 100)) (i32.const 1)) (then (unreachable))) - ) - (func (export "dealloc") - (call $drop (i32.const 1)) - ) - ) - (core instance $i (instantiate $m - (with "" (instance - (export "ctor" (func $ctor)) - (export "drop" (func $drop)) - )) - )) - (func (export "alloc") (canon lift (core func $i "alloc"))) - (func (export "dealloc") (canon lift (core func $i "dealloc"))) - ) - (instance $i1 (instantiate $inner - (with "r" (type $r)) - (with "[constructor]r" (func $ctor)) - )) - (instance $i2 (instantiate $inner - (with "r" (type $r)) - (with "[constructor]r" (func $ctor)) - )) - - (alias export $i1 "alloc" (func $alloc_in_1)) - (alias export $i1 "dealloc" (func $dealloc_in_1)) - (alias export $i2 "alloc" (func $alloc_in_2)) - (alias export $i2 "dealloc" (func $dealloc_in_2)) - - (export "alloc-in1" (func $alloc_in_1)) - (export "dealloc-in1" (func $dealloc_in_1)) - (export "alloc-in2" (func $alloc_in_2)) - (export "dealloc-in2" (func $dealloc_in_2)) -) - -(assert_return (invoke "alloc-in1")) -(assert_return (invoke "dealloc-in1")) -(assert_return (invoke "alloc-in1")) -(assert_return (invoke "alloc-in2")) -(assert_return (invoke "dealloc-in2")) -(assert_trap (invoke "dealloc-in2") "unknown handle index") - -;; Multiple copies of intrinsics all work -(component - (type $r (resource (rep i32))) - - (core func $new1 (canon resource.new $r)) - (core func $new2 (canon resource.new $r)) - (core func $drop1 (canon resource.drop $r)) - (core func $drop2 (canon resource.drop $r)) - - (core module $m - (import "" "new1" (func $new1 (param i32) (result i32))) - (import "" "new2" (func $new2 (param i32) (result i32))) - (import "" "drop1" (func $drop1 (param i32))) - (import "" "drop2" (func $drop2 (param i32))) - - (func $start - ;; 2x2 matrix of pairing new/drop - (call $drop1 (call $new1 (i32.const 101))) - (call $drop2 (call $new1 (i32.const 102))) - (call $drop1 (call $new2 (i32.const 103))) - (call $drop2 (call $new2 (i32.const 104))) - - ;; should be referencing the same namespace - (if (i32.ne (call $new1 (i32.const 105)) (i32.const 1)) (then (unreachable))) - (if (i32.ne (call $new2 (i32.const 105)) (i32.const 2)) (then (unreachable))) - - ;; use different drops out of order - (call $drop2 (i32.const 1)) - (call $drop1 (i32.const 2)) - ) - - (start $start) - ) - - (core instance (instantiate $m - (with "" (instance - (export "new1" (func $new1)) - (export "new2" (func $new2)) - (export "drop1" (func $drop1)) - (export "drop2" (func $drop2)) - )) - )) -) - -;; u32::MAX isn't special in some weird way, it's just probably always invalid -;; because that's a lot of handles. -(component - (type $r (resource (rep i32))) - - (core func $drop (canon resource.drop $r)) - - (core module $m - (import "" "drop" (func $drop (param i32))) - - (func (export "f") - (call $drop (i32.const 0xffffffff)) - ) - ) - - (core instance $i (instantiate $m - (with "" (instance - (export "drop" (func $drop)) - )) - )) - (func (export "f") (canon lift (core func $i "f"))) -) -(assert_trap (invoke "f") "unknown handle index") - -;; Test behavior of running a destructor for local resources -(component - (core module $m1 - (global $drops (mut i32) i32.const 0) - (global $last_drop (mut i32) i32.const -1) - - (func (export "dtor") (param i32) - (global.set $drops (i32.add (global.get $drops) (i32.const 1))) - (global.set $last_drop (local.get 0)) - ) - (func (export "drops") (result i32) global.get $drops) - (func (export "last-drop") (result i32) global.get $last_drop) - ) - (core instance $i1 (instantiate $m1)) - - (type $r1 (resource (rep i32))) - (type $r2 (resource (rep i32) (dtor (core func $i1 "dtor")))) - - (core func $drop1 (canon resource.drop $r1)) - (core func $drop2 (canon resource.drop $r2)) - (core func $new1 (canon resource.new $r1)) - (core func $new2 (canon resource.new $r2)) - - (core module $m2 - (import "" "drop1" (func $drop1 (param i32))) - (import "" "drop2" (func $drop2 (param i32))) - (import "" "new1" (func $new1 (param i32) (result i32))) - (import "" "new2" (func $new2 (param i32) (result i32))) - (import "i1" "drops" (func $drops (result i32))) - (import "i1" "last-drop" (func $last-drop (result i32))) - - (func $start - (local $r1 i32) - (local $r2 i32) - - (local.set $r1 (call $new1 (i32.const 100))) - (local.set $r2 (call $new2 (i32.const 200))) - - ;; indexes start at 2 and while they have distinct types they should be - ;; within the same table. - (if (i32.ne (local.get $r1) (i32.const 1)) (then (unreachable))) - (if (i32.ne (local.get $r2) (i32.const 2)) (then (unreachable))) - - ;; nothing should be dropped yet - (if (i32.ne (call $drops) (i32.const 0)) (then (unreachable))) - (if (i32.ne (call $last-drop) (i32.const -1)) (then (unreachable))) - - ;; dropping a resource without a destructor is ok, but shouldn't tamper - ;; with anything. - (call $drop1 (local.get $r1)) - (if (i32.ne (call $drops) (i32.const 0)) (then (unreachable))) - (if (i32.ne (call $last-drop) (i32.const -1)) (then (unreachable))) - - ;; drop r2 which should record a drop and additionally record the private - ;; representation value which was dropped - (call $drop2 (local.get $r2)) - (if (i32.ne (call $drops) (i32.const 1)) (then (unreachable))) - (if (i32.ne (call $last-drop) (i32.const 200)) (then (unreachable))) - - ;; do it all over again - (local.set $r2 (call $new2 (i32.const 300))) - (call $drop2 (local.get $r2)) - (if (i32.ne (call $drops) (i32.const 2)) (then (unreachable))) - (if (i32.ne (call $last-drop) (i32.const 300)) (then (unreachable))) - ) - - (start $start) - ) - - (core instance $i2 (instantiate $m2 - (with "" (instance - (export "drop1" (func $drop1)) - (export "drop2" (func $drop2)) - (export "new1" (func $new1)) - (export "new2" (func $new2)) - )) - (with "i1" (instance $i1)) - )) -) - -;; Test dropping a host resource -(component - (import "host" (instance $host - (export "resource1" (type $r (sub resource))) - (export "[constructor]resource1" (func (param "r" u32) (result (own $r)))) - (export "[static]resource1.last-drop" (func (result u32))) - (export "[static]resource1.drops" (func (result u32))) - )) - - (alias export $host "resource1" (type $r)) - (alias export $host "[constructor]resource1" (func $ctor)) - (alias export $host "[static]resource1.last-drop" (func $last-drop)) - (alias export $host "[static]resource1.drops" (func $drops)) - - (core func $drop (canon resource.drop $r)) - (core func $ctor (canon lower (func $ctor))) - (core func $last-drop (canon lower (func $last-drop))) - (core func $drops (canon lower (func $drops))) - - (core module $m - (import "" "drop" (func $drop (param i32))) - (import "" "ctor" (func $ctor (param i32) (result i32))) - (import "" "last-drop" (func $last-drop (result i32))) - (import "" "drops" (func $raw-drops (result i32))) - - (global $init-drop-cnt (mut i32) i32.const 0) - - (func $drops (result i32) - (i32.sub (call $raw-drops) (global.get $init-drop-cnt)) - ) - - (func $start - (local $r1 i32) - (global.set $init-drop-cnt (call $raw-drops)) - - (local.set $r1 (call $ctor (i32.const 100))) - - ;; should be no drops yet - (if (i32.ne (call $drops) (i32.const 0)) (then (unreachable))) - - ;; should count a drop - (call $drop (local.get $r1)) - (if (i32.ne (call $drops) (i32.const 1)) (then (unreachable))) - (if (i32.ne (call $last-drop) (i32.const 100)) (then (unreachable))) - - ;; do it again to be sure - (local.set $r1 (call $ctor (i32.const 200))) - (call $drop (local.get $r1)) - (if (i32.ne (call $drops) (i32.const 2)) (then (unreachable))) - (if (i32.ne (call $last-drop) (i32.const 200)) (then (unreachable))) - ) - - (start $start) - ) - (core instance (instantiate $m - (with "" (instance - (export "drop" (func $drop)) - (export "ctor" (func $ctor)) - (export "last-drop" (func $last-drop)) - (export "drops" (func $drops)) - )) - )) -) - -;; Test some bare-bones basics of borrowed resources -(component - (import "host" (instance $host - (export "resource1" (type $r (sub resource))) - (export "[constructor]resource1" (func (param "r" u32) (result (own $r)))) - (export "[method]resource1.simple" (func (param "self" (borrow $r)) (param "rep" u32))) - (export "[method]resource1.take-borrow" (func (param "self" (borrow $r)) (param "b" (borrow $r)))) - (export "[method]resource1.take-own" (func (param "self" (borrow $r)) (param "b" (own $r)))) - )) - - (alias export $host "resource1" (type $r)) - (alias export $host "[constructor]resource1" (func $ctor)) - (alias export $host "[method]resource1.simple" (func $simple)) - (alias export $host "[method]resource1.take-borrow" (func $take-borrow)) - (alias export $host "[method]resource1.take-own" (func $take-own)) - - (core func $drop (canon resource.drop $r)) - (core func $ctor (canon lower (func $ctor))) - (core func $simple (canon lower (func $simple))) - (core func $take-own (canon lower (func $take-own))) - (core func $take-borrow (canon lower (func $take-borrow))) - - (core module $m - (import "" "drop" (func $drop (param i32))) - (import "" "ctor" (func $ctor (param i32) (result i32))) - (import "" "simple" (func $simple (param i32 i32))) - (import "" "take-own" (func $take-own (param i32 i32))) - (import "" "take-borrow" (func $take-borrow (param i32 i32))) - - - (func $start - (local $r1 i32) - (local $r2 i32) - (local.set $r1 (call $ctor (i32.const 100))) - (local.set $r2 (call $ctor (i32.const 200))) - - (call $simple (local.get $r1) (i32.const 100)) - (call $simple (local.get $r1) (i32.const 100)) - (call $simple (local.get $r2) (i32.const 200)) - (call $simple (local.get $r1) (i32.const 100)) - (call $simple (local.get $r2) (i32.const 200)) - (call $simple (local.get $r2) (i32.const 200)) - - (call $drop (local.get $r1)) - (call $drop (local.get $r2)) - - - (local.set $r1 (call $ctor (i32.const 200))) - (local.set $r2 (call $ctor (i32.const 300))) - (call $take-borrow (local.get $r1) (local.get $r2)) - (call $take-borrow (local.get $r2) (local.get $r1)) - (call $take-borrow (local.get $r1) (local.get $r1)) - (call $take-borrow (local.get $r2) (local.get $r2)) - - (call $take-own (local.get $r1) (call $ctor (i32.const 400))) - (call $take-own (local.get $r2) (call $ctor (i32.const 500))) - (call $take-own (local.get $r2) (local.get $r1)) - (call $drop (local.get $r2)) - - ;; table should be empty at this point, so a fresh allocation should get - ;; index 2 - (if (i32.ne (call $ctor (i32.const 600)) (i32.const 1)) (then (unreachable))) - ) - - (start $start) - ) - (core instance (instantiate $m - (with "" (instance - (export "drop" (func $drop)) - (export "ctor" (func $ctor)) - (export "simple" (func $simple)) - (export "take-own" (func $take-own)) - (export "take-borrow" (func $take-borrow)) - )) - )) -) - -;; Cannot pass out an owned resource when it's borrowed by the same call -(component - (import "host" (instance $host - (export "resource1" (type $r (sub resource))) - (export "[constructor]resource1" (func (param "r" u32) (result (own $r)))) - (export "[method]resource1.take-own" (func (param "self" (borrow $r)) (param "b" (own $r)))) - )) - - (alias export $host "resource1" (type $r)) - (alias export $host "[constructor]resource1" (func $ctor)) - (alias export $host "[method]resource1.take-own" (func $take-own)) - - (core func $drop (canon resource.drop $r)) - (core func $ctor (canon lower (func $ctor))) - (core func $take-own (canon lower (func $take-own))) - - (core module $m - (import "" "drop" (func $drop (param i32))) - (import "" "ctor" (func $ctor (param i32) (result i32))) - (import "" "take-own" (func $take-own (param i32 i32))) - - - (func (export "f") - (local $r i32) - (local.set $r (call $ctor (i32.const 100))) - (call $take-own (local.get $r) (local.get $r)) - ) - ) - (core instance $i (instantiate $m - (with "" (instance - (export "drop" (func $drop)) - (export "ctor" (func $ctor)) - (export "take-own" (func $take-own)) - )) - )) - - (func (export "f") (canon lift (core func $i "f"))) -) - -(assert_trap (invoke "f") "cannot remove owned resource while borrowed") - -;; Borrows must actually exist -(component - (import "host" (instance $host - (export "resource1" (type $r (sub resource))) - (export "[method]resource1.simple" (func (param "self" (borrow $r)) (param "b" u32))) - )) - - (alias export $host "resource1" (type $r)) - (alias export $host "[method]resource1.simple" (func $simple)) - - (core func $drop (canon resource.drop $r)) - (core func $simple (canon lower (func $simple))) - - (core module $m - (import "" "drop" (func $drop (param i32))) - (import "" "simple" (func $simple (param i32 i32))) - - - (func (export "f") - (call $simple (i32.const 0) (i32.const 0)) - ) - ) - (core instance $i (instantiate $m - (with "" (instance - (export "drop" (func $drop)) - (export "simple" (func $simple)) - )) - )) - - (func (export "f") (canon lift (core func $i "f"))) -) - -(assert_trap (invoke "f") "unknown handle index 0") - -(component - (component $A - (type $t' (resource (rep i32))) - (export $t "t" (type $t')) - - (core func $ctor (canon resource.new $t)) - (core func $dtor (canon resource.drop $t)) - (core func $rep (canon resource.rep $t)) - - (core module $m - (import "" "dtor" (func $dtor (param i32))) - (import "" "rep" (func $rep (param i32) (result i32))) - - (func (export "[method]t.assert") (param i32 i32) - (if (i32.ne (local.get 0) (local.get 1)) (then (unreachable))) - ) - (func (export "[static]t.assert-own") (param i32 i32) - (if (i32.ne (call $rep (local.get 0)) (local.get 1)) (then (unreachable))) - (call $dtor (local.get 0)) - ) - ) - (core instance $i (instantiate $m - (with "" (instance - (export "dtor" (func $dtor)) - (export "rep" (func $rep)) - )) - )) - (func (export "[constructor]t") (param "x" u32) (result (own $t)) - (canon lift (core func $ctor))) - (func (export "[method]t.assert") (param "self" (borrow $t)) (param "x" u32) - (canon lift (core func $i "[method]t.assert"))) - (func (export "[static]t.assert-own") (param "self" (own $t)) (param "x" u32) - (canon lift (core func $i "[static]t.assert-own"))) - ) - (instance $a (instantiate $A)) - - (component $B - (import "a" (instance $i - (export "t" (type $t (sub resource))) - (export "[constructor]t" (func (param "x" u32) (result (own $t)))) - (export "[method]t.assert" (func (param "self" (borrow $t)) (param "x" u32))) - (export "[static]t.assert-own" (func (param "self" (own $t)) (param "x" u32))) - )) - - (alias export $i "t" (type $t)) - (alias export $i "[constructor]t" (func $ctor)) - (alias export $i "[method]t.assert" (func $assert-borrow)) - (alias export $i "[static]t.assert-own" (func $assert-own)) - - (core func $ctor (canon lower (func $ctor))) - (core func $dtor (canon resource.drop $t)) - (core func $assert-own (canon lower (func $assert-own))) - (core func $assert-borrow (canon lower (func $assert-borrow))) - - (core module $m - (import "" "ctor" (func $ctor (param i32) (result i32))) - (import "" "dtor" (func $dtor (param i32))) - (import "" "assert-own" (func $assert-own (param i32 i32))) - (import "" "assert-borrow" (func $assert-borrow (param i32 i32))) - - (func (export "f") - (local $r1 i32) - (local $r2 i32) - - (local.set $r1 (call $ctor (i32.const 100))) - (local.set $r2 (call $ctor (i32.const 200))) - - (if (i32.ne (local.get $r1) (i32.const 1)) (then (unreachable))) - (if (i32.ne (local.get $r2) (i32.const 2)) (then (unreachable))) - - (call $assert-borrow (local.get $r2) (i32.const 200)) - (call $assert-borrow (local.get $r1) (i32.const 100)) - - (call $assert-own (local.get $r2) (i32.const 200)) - (call $dtor (local.get $r1)) - ) - ) - (core instance $i (instantiate $m - (with "" (instance - (export "ctor" (func $ctor)) - (export "dtor" (func $dtor)) - (export "assert-own" (func $assert-own)) - (export "assert-borrow" (func $assert-borrow)) - )) - )) - (func (export "f") (canon lift (core func $i "f"))) - ) - (instance $b (instantiate $B (with "a" (instance $a)))) - (export "f" (func $b "f")) -) - -(assert_return (invoke "f")) - -;; Test destructor behavior when using the wrong resource type -(component definition $C - (type $r1 (resource (rep i32))) - (type $r2 (resource (rep i32))) - - (core func $drop1 (canon resource.drop $r1)) - (core func $drop2 (canon resource.drop $r2)) - (core func $new1 (canon resource.new $r1)) - (core func $new2 (canon resource.new $r2)) - - (core module $m2 - (import "" "drop1" (func $drop1 (param i32))) - (import "" "drop2" (func $drop2 (param i32))) - (import "" "new1" (func $new1 (param i32) (result i32))) - (import "" "new2" (func $new2 (param i32) (result i32))) - - (func (export "drop-r1-as-r2") (call $drop2 (call $new1 (i32.const 100)))) - (func (export "return-r1-as-r2") (result i32) (call $new1 (i32.const 100))) - ) - - (core instance $i2 (instantiate $m2 - (with "" (instance - (export "drop1" (func $drop1)) - (export "drop2" (func $drop2)) - (export "new1" (func $new1)) - (export "new2" (func $new2)) - )) - )) - - (export $r2' "r2" (type $r2)) - (func (export "drop-r1-as-r2") (canon lift (core func $i2 "drop-r1-as-r2"))) - (func (export "return-r1-as-r2") (result (own $r2')) (canon lift (core func $i2 "return-r1-as-r2"))) -) - -(component instance $C1 $C) -(assert_trap (invoke "drop-r1-as-r2") "handle index 1 used with the wrong type, expected guest-defined resource but found a different guest-defined resource") -(component instance $C1 $C) -(assert_trap (invoke "return-r1-as-r2") "handle index 1 used with the wrong type, expected guest-defined resource but found a different guest-defined resource") diff --git a/test/wasmtime/restrictions.wast b/test/wasmtime/restrictions.wast deleted file mode 100644 index 9bd53e7e..00000000 --- a/test/wasmtime/restrictions.wast +++ /dev/null @@ -1,22 +0,0 @@ -(assert_invalid - (component (import "x" (component))) - "root-level component imports are not supported") - -(assert_invalid - (component (component (export "x"))) - "exporting a component from the root component is not supported") - -(assert_invalid - (component - (import "f" (func $f)) - (export "f" (func $f)) - ) - "component export `f` is a reexport of an imported function which is not implemented") - -(assert_invalid - (component - (import "x" (component - (export "x" (type (sub resource))) - )) - ) - "root-level component imports are not supported") diff --git a/test/wasmtime/simple.wast b/test/wasmtime/simple.wast deleted file mode 100644 index 7bf2ab1e..00000000 --- a/test/wasmtime/simple.wast +++ /dev/null @@ -1,42 +0,0 @@ -(component) - -(component - (core module) -) - -(component - (core module) - (core module) - (core module) -) - -(component - (core module - (func (export "a") (result i32) i32.const 0) - (func (export "b") (result i64) i64.const 0) - ) - (core module - (func (export "c") (result f32) f32.const 0) - (func (export "d") (result f64) f64.const 0) - ) -) - -(assert_invalid - (component - (import "a" (component)) - ) - "root-level component imports are not supported") - -(assert_invalid - (component - (component (export "a")) - ) - "exporting a component from the root component is not supported") - -(component - (core module $m (func (export ""))) - (core instance $m (instantiate $m)) - (func (export "a") (canon lift (core func $m ""))) -) - -(assert_return (invoke "a")) diff --git a/test/wasmtime/strings.wast b/test/wasmtime/strings.wast deleted file mode 100644 index bc0de08b..00000000 --- a/test/wasmtime/strings.wast +++ /dev/null @@ -1,110 +0,0 @@ -;;! multi_memory = true - -;; unaligned utf16 string -(assert_trap - (component - (component $c - (core module $m - (func (export "") (param i32 i32)) - (func (export "realloc") (param i32 i32 i32 i32) (result i32) i32.const 0) - (memory (export "memory") 1) - ) - (core instance $m (instantiate $m)) - (func (export "a") (param "a" string) - (canon lift (core func $m "") (realloc (core func $m "realloc")) (memory (core memory $m "memory"))) - ) - ) - - (component $c2 - (import "a" (func $f (param "a" string))) - (core module $libc - (memory (export "memory") 1) - ) - (core instance $libc (instantiate $libc)) - (core func $f (canon lower (func $f) string-encoding=utf16 (memory (core memory $libc "memory")))) - (core module $m - (import "" "" (func $f (param i32 i32))) - - (func $start (call $f (i32.const 1) (i32.const 0))) - (start $start) - ) - (core instance (instantiate $m (with "" (instance (export "" (func $f)))))) - ) - - (instance $c (instantiate $c)) - (instance $c2 (instantiate $c2 (with "a" (func $c "a")))) - ) - "unaligned pointer") - -;; unaligned latin1+utf16 string, even with the latin1 encoding -(assert_trap - (component - (component $c - (core module $m - (func (export "") (param i32 i32)) - (func (export "realloc") (param i32 i32 i32 i32) (result i32) i32.const 0) - (memory (export "memory") 1) - ) - (core instance $m (instantiate $m)) - (func (export "a") (param "a" string) - (canon lift (core func $m "") (realloc (core func $m "realloc")) (memory (core memory $m "memory"))) - ) - ) - - (component $c2 - (import "a" (func $f (param "a" string))) - (core module $libc - (memory (export "memory") 1) - ) - (core instance $libc (instantiate $libc)) - (core func $f (canon lower (func $f) string-encoding=latin1+utf16 (memory (core memory $libc "memory")))) - (core module $m - (import "" "" (func $f (param i32 i32))) - - (func $start (call $f (i32.const 1) (i32.const 0))) - (start $start) - ) - (core instance (instantiate $m (with "" (instance (export "" (func $f)))))) - ) - - (instance $c (instantiate $c)) - (instance $c2 (instantiate $c2 (with "a" (func $c "a")))) - ) - "unaligned pointer") - -;; out of bounds utf8->utf8 string -(assert_trap - (component - (component $c - (core module $m - (func (export "") (param i32 i32)) - (func (export "realloc") (param i32 i32 i32 i32) (result i32) i32.const 0) - (memory (export "memory") 1) - ) - (core instance $m (instantiate $m)) - (func (export "a") (param "a" string) - (canon lift (core func $m "") (realloc (core func $m "realloc")) (memory (core memory $m "memory")) - string-encoding=utf8) - ) - ) - - (component $c2 - (import "a" (func $f (param "a" string))) - (core module $libc - (memory (export "memory") 1) - ) - (core instance $libc (instantiate $libc)) - (core func $f (canon lower (func $f) string-encoding=utf8 (memory (core memory $libc "memory")))) - (core module $m - (import "" "" (func $f (param i32 i32))) - - (func $start (call $f (i32.const 0x8000_0000) (i32.const 1))) - (start $start) - ) - (core instance (instantiate $m (with "" (instance (export "" (func $f)))))) - ) - - (instance $c (instantiate $c)) - (instance $c2 (instantiate $c2 (with "a" (func $c "a")))) - ) - "string content out-of-bounds") diff --git a/test/wasmtime/tags.wast b/test/wasmtime/tags.wast deleted file mode 100644 index cac1fdec..00000000 --- a/test/wasmtime/tags.wast +++ /dev/null @@ -1,14 +0,0 @@ -;;! exceptions = true - -(component - (core module $a (tag (export "t"))) - (core module $b (import "a" "t" (tag))) - - (core instance $a (instantiate $a)) - (core instance (instantiate $b (with "a" (instance $a)))) - (core instance (instantiate $b - (with "a" (instance - (export "t" (tag $a "t")) - )) - )) -) diff --git a/test/wasmtime/types.wast b/test/wasmtime/types.wast deleted file mode 100644 index 9596ebe6..00000000 --- a/test/wasmtime/types.wast +++ /dev/null @@ -1,355 +0,0 @@ -(component - (type string) - (type (func (param "a" string))) - (type $r (record (field "x" (result)) (field "y" string))) - (type $u (variant (case "r" $r) (case "s" string))) - (type $e (result $u (error u32))) - (type (result $u)) - (type (result (error $u))) - (type (result)) - - (type (func (param "a" $e) (result (option $r)))) - - (type (variant - (case "a" string) - (case "b" u32) - (case "c" float32) - (case "d" float64) - )) - - (type $errno (enum "a" "b" "e")) - (type (list $errno)) - (type $oflags (flags "read" "write" "exclusive")) - (type (tuple $oflags $errno $r)) - - ;; primitives in functions - (type (func - (param "a" bool) - (param "b" u8) - (param "c" s8) - (param "d" u16) - (param "e" s16) - (param "f" u32) - (param "g" s32) - (param "h" u64) - (param "i" s64) - (param "j" char) - (param "k" string) - )) - - ;; primitives in types - (type bool) - (type u8) - (type s8) - (type u16) - (type s16) - (type u32) - (type s32) - (type u64) - (type s64) - (type char) - (type string) -) - -(component - (type $empty (func)) - (type (func (param "a" string) (result u32))) - (type (component)) - (core type (module)) - (core type (func)) - (type (instance)) - - (type (component - (import "x" (func (type $empty))) - (import "y" (func)) - (import "z" (component)) - - (type $t (instance)) - - (export "a" (core module)) - (export "b" (instance (type $t))) - )) - - (type (instance - (export "x" (func (type $empty))) - (export "y" (func)) - (export "z" (component)) - - (type $t (instance)) - - (export "a" (core module)) - (export "b" (instance (type $t))) - )) - - (core type (module - (import "" "" (func (param i32))) - (import "" "1" (func (result i32))) - (export "1" (global i32)) - (export "2" (memory 1)) - (export "3" (table 1 funcref)) - )) -) - -;; outer core aliases work -(component $C - (core type $f (func)) - (core type $m (module)) - - (component $C2 - (alias outer $C $f (core type $my_f)) - (import "a" (core module (type $m))) - (import "x" (core module - (alias outer $C2 $my_f (type $my_f)) - (import "" "1" (func (type $my_f))) - )) - ) -) - -;; type exports work -(component $C - (component $C2 - (type string) - (export "x" (type 0)) - ) - (instance (instantiate 0)) - (alias export 0 "x" (type)) - (export "x" (type 0)) -) - -(component - (core module $m (func (export "") (param i32) (result i32) local.get 0)) - (core instance $m (instantiate $m)) - (func (export "i-to-b") (param "a" u32) (result bool) (canon lift (core func $m ""))) - (func (export "i-to-u8") (param "a" u32) (result u8) (canon lift (core func $m ""))) - (func (export "i-to-s8") (param "a" u32) (result s8) (canon lift (core func $m ""))) - (func (export "i-to-u16") (param "a" u32) (result u16) (canon lift (core func $m ""))) - (func (export "i-to-s16") (param "a" u32) (result s16) (canon lift (core func $m ""))) -) -(assert_return (invoke "i-to-b" (u32.const 0)) (bool.const false)) -(assert_return (invoke "i-to-b" (u32.const 1)) (bool.const true)) -(assert_return (invoke "i-to-b" (u32.const 2)) (bool.const true)) -(assert_return (invoke "i-to-u8" (u32.const 0x00)) (u8.const 0)) -(assert_return (invoke "i-to-u8" (u32.const 0x01)) (u8.const 1)) -(assert_return (invoke "i-to-u8" (u32.const 0xf01)) (u8.const 1)) -(assert_return (invoke "i-to-u8" (u32.const 0xf00)) (u8.const 0)) -(assert_return (invoke "i-to-s8" (u32.const 0xffffffff)) (s8.const -1)) -(assert_return (invoke "i-to-s8" (u32.const 127)) (s8.const 127)) -(assert_return (invoke "i-to-u16" (u32.const 0)) (u16.const 0)) -(assert_return (invoke "i-to-u16" (u32.const 1)) (u16.const 1)) -(assert_return (invoke "i-to-u16" (u32.const 0xffffffff)) (u16.const 0xffff)) -(assert_return (invoke "i-to-s16" (u32.const 0)) (s16.const 0)) -(assert_return (invoke "i-to-s16" (u32.const 1)) (s16.const 1)) -(assert_return (invoke "i-to-s16" (u32.const 0xffffffff)) (s16.const -1)) - -(assert_invalid - (component - (type $t1 string) - (type $t2 (list $t1)) - (type $t3 (list $t2)) - (type $t4 (list $t3)) - (type $t5 (list $t4)) - (type $t6 (list $t5)) - (type $t7 (list $t6)) - (type $t8 (list $t7)) - (type $t9 (list $t8)) - (type $t10 (list $t9)) - (type $t11 (list $t10)) - (type $t12 (list $t11)) - (type $t13 (list $t12)) - (type $t14 (list $t13)) - (type $t15 (list $t14)) - (type $t16 (list $t15)) - (type $t17 (list $t16)) - (type $t18 (list $t17)) - (type $t19 (list $t18)) - (type $t20 (list $t19)) - (type $t21 (list $t20)) - (type $t22 (list $t21)) - (type $t23 (list $t22)) - (type $t24 (list $t23)) - (type $t25 (list $t24)) - (type $t26 (list $t25)) - (type $t27 (list $t26)) - (type $t28 (list $t27)) - (type $t29 (list $t28)) - (type $t30 (list $t29)) - (type $t31 (list $t30)) - (type $t32 (list $t31)) - (type $t33 (list $t32)) - (type $t34 (list $t33)) - (type $t35 (list $t34)) - (type $t36 (list $t35)) - (type $t37 (list $t36)) - (type $t38 (list $t37)) - (type $t39 (list $t38)) - (type $t40 (list $t39)) - (type $t41 (list $t40)) - (type $t42 (list $t41)) - (type $t43 (list $t42)) - (type $t44 (list $t43)) - (type $t45 (list $t44)) - (type $t46 (list $t45)) - (type $t47 (list $t46)) - (type $t48 (list $t47)) - (type $t49 (list $t48)) - (type $t50 (list $t49)) - (type $t51 (list $t50)) - (type $t52 (list $t51)) - (type $t53 (list $t52)) - (type $t54 (list $t53)) - (type $t55 (list $t54)) - (type $t56 (list $t55)) - (type $t57 (list $t56)) - (type $t58 (list $t57)) - (type $t59 (list $t58)) - (type $t60 (list $t59)) - (type $t61 (list $t60)) - (type $t62 (list $t61)) - (type $t63 (list $t62)) - (type $t64 (list $t63)) - (type $t65 (list $t64)) - (type $t66 (list $t65)) - (type $t67 (list $t66)) - (type $t68 (list $t67)) - (type $t69 (list $t68)) - (type $t70 (list $t69)) - (type $t71 (list $t70)) - (type $t72 (list $t71)) - (type $t73 (list $t72)) - (type $t74 (list $t73)) - (type $t75 (list $t74)) - (type $t76 (list $t75)) - (type $t77 (list $t76)) - (type $t78 (list $t77)) - (type $t79 (list $t78)) - (type $t80 (list $t79)) - (type $t81 (list $t80)) - (type $t82 (list $t81)) - (type $t83 (list $t82)) - (type $t84 (list $t83)) - (type $t85 (list $t84)) - (type $t86 (list $t85)) - (type $t87 (list $t86)) - (type $t88 (list $t87)) - (type $t89 (list $t88)) - (type $t90 (list $t89)) - (type $t91 (list $t90)) - (type $t92 (list $t91)) - (type $t93 (list $t92)) - (type $t94 (list $t93)) - (type $t95 (list $t94)) - (type $t96 (list $t95)) - (type $t97 (list $t96)) - (type $t98 (list $t97)) - (type $t99 (list $t98)) - (type $t100 (list $t99)) - (type $t101 (list $t100)) - (export "t" (type $t101)) - ) - "type nesting is too deep") - -(component - (type (instance - (export "x" (instance $x - (type $t u32) - (export "y" (type (eq $t))) - )) - (alias export $x "y" (type $t)) - (export "my-y" (type (eq $t))) - )) - - (type (component - (import "x" (instance $x - (type $t u32) - (export "y" (type (eq $t))) - )) - (alias export $x "y" (type $t)) - (export "my-y" (type (eq $t))) - )) -) - -(component - (type $t u32) - (export $t2 "t" (type $t)) - (type $r (record (field "x" $t2))) - (export "r" (type $r)) -) - -(component - (component - (import "x" (instance $i - (type $i u32) - (export "i" (type (eq $i))) - )) - (alias export $i "i" (type $i)) - (export "i" (type $i)) - ) -) - -(component - (type $u u32) - (instance $i - (export "i" (type $u)) - ) - (alias export $i "i" (type $i)) - (export "i" (type $i)) -) - -(component - (component $c - (type $t u32) - (export "t" (type $t)) - ) - (instance $c (instantiate $c)) - (export "i" (type $c "t")) -) - -(component - (component $c - (import "x" (component $c - (type $t u32) - (export "t" (type (eq $t))) - )) - (instance $c (instantiate $c)) - (export "i" (type $c "t")) - ) - - (component $x - (type $t u32) - (export "t" (type $t)) - ) - - (instance $c (instantiate $c (with "x" (component $x)))) -) - -(component - (type $t1 u64) - (import "a" (type $t2 (eq $t1))) - (import "b" (type $t3 (eq $t2))) -) - -(component - (import "a" (instance - (type $t1 u64) - (export "a" (type $t2 (eq $t1))) - (export "b" (type (eq $t2))) - )) -) - -(component - (type (export "x") (component - (type $t' (instance - (export "r" (type (sub resource))) - )) - (export "t" (instance $t (type $t'))) - )) -) - -(component - (type (export "x") (instance - (type $t' (instance - (export "r" (type (sub resource))) - )) - (export "t" (instance $t (type $t'))) - )) -)