Skip to content

Upstream initial test suite from wasm-tools #85

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
;; Styled after ../component-model/resources.wast

(component
(core type $start (shared (func (param $context i32))))
(core func $spawn (canon thread.spawn $start))
(core func $concurrency (canon thread.hw_concurrency))
)

(component
(core type $start (shared (func (param $context i32))))
(core func $spawn (canon thread.spawn $start))
(core func $concurrency (canon thread.hw_concurrency))

(core module $m
(type $st (shared (func (param $context i32))))
(import "" "spawn" (func (param (ref null $st)) (param i32) (result i32)))
(import "" "concurrency" (func (result i32)))
)

(core instance (instantiate $m
(with "" (instance
(export "spawn" (func $spawn))
(export "concurrency" (func $concurrency))
))
))
)

(assert_invalid
(component
(core type $start (func))
(core func $spawn (canon thread.spawn $start))
)
"spawn type must be shared"
)

(assert_invalid
(component
(core type $start (shared (func)))
(core func $spawn (canon thread.spawn $start))
)
"spawn function must take a single `i32` argument (currently)"
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
;; Check that shared functions are valid WAT.
(module
(type $f (shared (func)))
(func (import "spectest" "shared-func") (type $f))
(func (type $f))
)

;; Check that unshared functions cannot be called from shared functions.
(assert_invalid
(module
(type $shared (shared (func)))
(type $unshared (func))
(func (type $shared)
call $unshared)
(func $unshared (type $unshared))
)
"shared functions cannot access unshared functions")

;; Check that unshared globals cannot be accessed from shared functions.
(assert_invalid
(module
(global $unshared_global i32 (i32.const 0))
(type $shared_func (shared (func)))
(func (type $shared_func)
global.get $unshared_global
drop)
)
"shared functions cannot access unshared globals")

;; Check that unshared tables cannot be accessed from shared functions.
(assert_invalid
(module
(table $unshared_table 1 anyref)
(type $shared_func (shared (func)))
(func (type $shared_func)
i32.const 0
table.get $unshared_table
drop)
)
"shared functions cannot access unshared tables")

;; Check that unshared arrays cannot be accessed from shared functions.
(assert_invalid
(module
(type $unshared_array (array anyref))
(type $shared_func (shared (func)))
(func (type $shared_func)
(array.new $unshared_array (ref.null any) (i32.const 0))
(array.get $unshared_array (i32.const 0))
drop)
)
"shared functions cannot access unshared arrays")

;; Check that unshared structs cannot be accessed from shared functions.
(assert_invalid
(module
(type $unshared_struct (struct (field i32)))
(type $shared_func (shared (func)))
(func (type $shared_func)
(struct.new $unshared_struct (i32.const 0))
(struct.get $unshared_struct 0)
drop)
)
"shared functions cannot access unshared structs")
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
(module
(func
unreachable
ref.null (shared eq)
ref.eq
drop

ref.null eq
ref.eq
drop
)
(func
unreachable
any.convert_extern
ref.cast (ref i31)
drop
)
(func
unreachable
any.convert_extern
ref.cast (ref (shared i31))
drop
)
(func
unreachable
ref.eq
drop
)
(func
(local $a (ref null (shared eq)))
unreachable
local.get $a
ref.eq
drop
)
(func
(local $a (ref null eq))
unreachable
local.get $a
ref.eq
drop
)
(func
(local $a (ref null eq))
unreachable
ref.cast (ref eq)
local.get $a
ref.eq
drop
)
(func
(local $a (ref null (shared eq)))
unreachable
ref.cast (ref (shared eq))
local.get $a
ref.eq
drop
)
(func
(local $a (ref null (shared eq)))
unreachable
any.convert_extern
extern.convert_any
any.convert_extern
ref.cast (ref (shared eq))
local.get $a
ref.eq
drop
)
(func
(local $a (ref null eq))
unreachable
any.convert_extern
extern.convert_any
any.convert_extern
ref.cast (ref eq)
local.get $a
ref.eq
drop
)
(func
unreachable
any.convert_extern
ref.cast (ref (shared array))
array.len
drop
)
)

(assert_invalid
(module
(func
unreachable
any.convert_extern
ref.null eq
ref.eq
drop
)
)
"expected subtype of eq, found any")

(assert_invalid
(module
(func
unreachable
extern.convert_any
ref.cast (ref (shared i31))
drop
)
)
"expected (shared anyref), found (ref (shared extern))")

(assert_invalid
(module
(func
unreachable
any.convert_extern
ref.cast (ref extern)
drop
)
)
"expected externref, found (ref any)")
(assert_invalid
(module
(func
unreachable
any.convert_extern
array.len
drop
)
)
"expected subtype of array, found any")
(assert_invalid
(module
(func
unreachable
ref.as_non_null
i32.eq
drop
)
)
"expected i32, found heap type")
(assert_invalid
(module
(func
block $l
unreachable
br_on_cast $l (ref any) (ref any)
end
)
)
"br_on_cast to label with empty types")
Loading