| 1 |
;; RUN: wast --assert default --snapshot tests/snapshots % -f shared-everything-threads |
| 2 |
|
| 3 |
;; Styled after ../component-model/resources.wast |
| 4 |
|
| 5 |
(component |
| 6 |
(core type $start (shared (func (param $context i32)))) |
| 7 |
(core func $spawn_ref (canon thread.spawn_ref $start)) |
| 8 |
|
| 9 |
(core module $libc (table (export "start-table") shared 1 (ref null (shared func)))) |
| 10 |
(core instance $libc (instantiate $libc)) |
| 11 |
(core func $spawn_indirect (canon thread.spawn_indirect $start (table $libc "start-table"))) |
| 12 |
|
| 13 |
(core func $parallelism (canon thread.available_parallelism)) |
| 14 |
) |
| 15 |
|
| 16 |
(component |
| 17 |
(core type $start (shared (func (param $context i32)))) |
| 18 |
(core func $spawn_ref (canon thread.spawn_ref $start)) |
| 19 |
|
| 20 |
(core module $libc (table (export "start-table") shared 1 (ref null (shared func)))) |
| 21 |
(core instance $libc (instantiate $libc)) |
| 22 |
(core func $spawn_indirect (canon thread.spawn_indirect $start (table $libc "start-table"))) |
| 23 |
|
| 24 |
(core func $parallelism (canon thread.available_parallelism)) |
| 25 |
|
| 26 |
(core module $m |
| 27 |
(type $spawned_func_ty (shared (func (param $context i32)))) |
| 28 |
(type $spawn_ref_ty (shared (func (param (ref null $spawned_func_ty)) (param i32) (result i32)))) |
| 29 |
(type $spawn_indirect_ty (shared (func (param i32) (param i32) (result i32)))) |
| 30 |
(type $parallelism_ty (shared (func (result i32)))) |
| 31 |
(import "" "spawn_ref" (func (type $spawn_ref_ty))) |
| 32 |
(import "" "spawn_indirect" (func (type $spawn_indirect_ty))) |
| 33 |
(import "" "parallelism" (func (type $parallelism_ty))) |
| 34 |
) |
| 35 |
|
| 36 |
(core instance (instantiate $m |
| 37 |
(with "" (instance |
| 38 |
(export "spawn_ref" (func $spawn_ref)) |
| 39 |
(export "spawn_indirect" (func $spawn_indirect)) |
| 40 |
(export "parallelism" (func $parallelism)) |
| 41 |
)) |
| 42 |
)) |
| 43 |
) |
| 44 |
|
| 45 |
(assert_invalid |
| 46 |
(component |
| 47 |
(core type $start (func)) |
| 48 |
(core func $spawn_ref (canon thread.spawn_ref $start)) |
| 49 |
) |
| 50 |
"spawn type must be shared" |
| 51 |
) |
| 52 |
|
| 53 |
(assert_invalid |
| 54 |
(component |
| 55 |
(core type $start (shared (func (param i32)))) |
| 56 |
;; Refer to a non-existent table type (i.e., 0); validation |
| 57 |
;; for `thread.spawn_indirect` happens first. |
| 58 |
(core func $spawn_indirect (canon thread.spawn_indirect $start (table 0))) |
| 59 |
) |
| 60 |
"unknown table 0: table index out of bounds" |
| 61 |
) |
| 62 |
|
| 63 |
(assert_invalid |
| 64 |
(component |
| 65 |
(core type $start (shared (func))) |
| 66 |
(core func $spawn_ref (canon thread.spawn_ref $start)) |
| 67 |
) |
| 68 |
"spawn function must take a single `i32` argument (currently)" |
| 69 |
) |
| 70 |
|
| 71 |
(assert_invalid |
| 72 |
(component |
| 73 |
(core type $start (shared (func))) |
| 74 |
(core module $libc (table (export "start-table") shared 1 (ref null (shared func)))) |
| 75 |
(core instance $libc (instantiate $libc)) |
| 76 |
(core func $spawn_indirect (canon thread.spawn_indirect $start (table $libc "start-table"))) |
| 77 |
) |
| 78 |
"spawn function must take a single `i32` argument (currently)" |
| 79 |
) |
| 80 |
|
| 81 |
(assert_invalid |
| 82 |
(component |
| 83 |
(core type $start (shared (func (param i32)))) |
| 84 |
(core module $libc (table (export "start-table") 1 (ref null (shared func)))) |
| 85 |
(core instance $libc (instantiate $libc)) |
| 86 |
(core func $spawn_indirect (canon thread.spawn_indirect $start (table $libc "start-table"))) |
| 87 |
) |
| 88 |
"mismatch in the shared flag for tables" |
| 89 |
) |