@ -637,10 +637,12 @@
;; simple variant translation
(component
(type $a (variant (case "x")))
(type $b (variant (case "y")))
(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)) (unreachable))
@ -651,6 +653,11 @@
(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)))
@ -670,15 +677,19 @@
))
)
(instance $c1 (instantiate $c1))
(instance $c2 (instantiate $c2 (with "r" (func $c1 "r"))))
(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
(type $a (variant (case "x")))
(component $c1
(type $a' (variant (case "x")))
(export $a "a" (type $a'))
(core module $m
(func (export "r") (param i32))
)
@ -686,6 +697,8 @@
(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)))
@ -702,16 +715,19 @@
))
)
(instance $c1 (instantiate $c1))
(instance $c2 (instantiate $c2 (with "r" (func $c1 "r"))))
(instance $c2 (instantiate $c2
(with "a" (type $c1 "a"))
(with "r" (func $c1 "r"))
))
)
"unreachable")
;; invalid variant discriminant in a result
(assert_trap
(component
(type $a (variant (case "x")))
(component $c1
(type $a' (variant (case "x")))
(export $a "a" (type $a'))
(core module $m
(func (export "r") (result i32) i32.const 1)
)
@ -719,6 +735,8 @@
(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)))
@ -732,7 +750,10 @@
))
)
(instance $c1 (instantiate $c1))
(instance $c2 (instantiate $c2 (with "r" (func $c1 "r"))))
(instance $c2 (instantiate $c2
(with "a" (type $c1 "a"))
(with "r" (func $c1 "r"))
))
)
"unreachable")
@ -803,19 +824,24 @@
;; translation of locals between different types
(component
(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)))
(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)))
(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))
@ -877,6 +903,22 @@
)
(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 $a "t-a" (type (eq $a')))
(export $b "t-b" (type (eq $b')))
(export $c "t-c" (type (eq $c')))
(export $d "t-d" (type (eq $d')))
(export $e "t-e" (type (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)))
@ -933,14 +975,17 @@
;; different size variants
(component
(type $a (variant
(case "a")
(case "b" float32)
(case "c" (tuple float32 u32))
(case "d" (tuple float32 (record) u64 u8))
))
(component $c1
(type $r' (record))
(export $r "t-r" (type $r'))
(type $a' (variant
(case "a")
(case "b" float32)
(case "c" (tuple float32 u32))
(case "d" (tuple float32 $r 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))
@ -984,6 +1029,15 @@
)
(component $c2
(import "a" (instance $i
(type $r' (record))
(export $r "t-r" (type (eq $r')))
(type $a' (variant
(case "a")
(case "b" float32)
(case "c" (tuple float32 u32))
(case "d" (tuple float32 $r u64 u8))
))
(export $a "t-a" (type (eq $a')))
(export "a" (func (param "x" u8) (param "a" $a)))
))
@ -1154,33 +1208,33 @@
;; test that flags get their upper bits all masked off
(component
(type $f0 (flags))
(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
(type $f0' (flags))
(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
(type $f17' (flags
"f1" "f2" "f3" "f4" "f5" "f6" "f7" "f8"
"g1" "g2" "g3" "g4" "g5" "g6" "g7" "g8"
"g9"
))
(type $f32 (flags
(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"
))
(type $f33 (flags
(type $f33' (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"
"i9"
))
(type $f64 (flags
(type $f64' (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"
@ -1190,7 +1244,7 @@
"l1" "l2" "l3" "l4" "l5" "l6" "l7" "l8"
"m1" "m2" "m3" "m4" "m5" "m6" "m7" "m8"
))
(type $f65 (flags
(type $f65' (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"
@ -1203,6 +1257,16 @@
))
(component $c1
(export $f0 "t-f0" (type $f0'))
(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'))
(export $f33 "t-f33" (type $f33'))
(export $f64 "t-f64" (type $f64'))
(export $f65 "t-f65" (type $f65'))
(core module $m
(func (export "f0"))
(func (export "f1") (param i32)
@ -1253,6 +1317,16 @@
(component $c2
(import "a" (instance $i
(export $f0 "t-f0" (type (eq $f0')))
(export $f1 "t-f1" (type (eq $f1')))
(export $f8 "t-f8" (type (eq $f8')))
(export $f9 "t-f9" (type (eq $f9')))
(export $f16 "t-f16" (type (eq $f16')))
(export $f17 "t-f17" (type (eq $f17')))
(export $f32 "t-f32" (type (eq $f32')))
(export $f33 "t-f33" (type (eq $f33')))
(export $f64 "t-f64" (type (eq $f64')))
(export $f65 "t-f65" (type (eq $f65')))
(export "f0" (func (param "a" $f0)))
(export "f1" (func (param "a" $f1)))
(export "f8" (func (param "a" $f8)))