Skip to content

Commit 9c6f7bd

Browse files
committed
Abstract handler heap type. Extend testsuite
1 parent 65efe82 commit 9c6f7bd

File tree

2 files changed

+75
-3
lines changed

2 files changed

+75
-3
lines changed

interpreter/valid/match.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ let abs_of_str_type _c = function
1414
| DefStructT _ | DefArrayT _ -> StructHT
1515
| DefFuncT _ -> FuncHT
1616
| DefContT _ -> ContHT
17-
| DefHandlerT _ -> failwith "TODO abstract heap type for handlers"
17+
| DefHandlerT _ -> HandlerHT
1818

1919
let rec top_of_str_type c st =
2020
top_of_heap_type c (abs_of_str_type c st)

test/core/stack-switching/cont.wast

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,7 +1119,7 @@
11191119
(local.set $i (i32.add (i32.const 1) (local.get $i)))
11201120
(br $next)))
11211121

1122-
(func $sumUp (export "sumUp") (param $n i32) (result i32)
1122+
(func (export "sumUp") (param $n i32) (result i32)
11231123
(local $i i32)
11241124
(local $j i32)
11251125
(local $k (ref $ct))
@@ -1137,6 +1137,78 @@
11371137
)
11381138
(return (local.get $i)))
11391139

1140-
(elem declare func $nats)
1140+
(func $nats-bad (type $ft)
1141+
(local $h (ref $ht))
1142+
(local $i i32)
1143+
(local.set $h (local.get 0))
1144+
(loop $next
1145+
(suspend_to $ht $yield
1146+
(local.get $i) (local.get $h))
1147+
(drop) ;; drop the handle
1148+
(local.set $i (i32.add (i32.const 1) (local.get $i)))
1149+
(br $next)))
1150+
1151+
(func (export "sumUp-bad") (param $n i32) (result i32)
1152+
(local $i i32)
1153+
(local $j i32)
1154+
(local $k (ref $ct))
1155+
(local.set $k (cont.new $ct (ref.func $nats-bad)))
1156+
(loop $next
1157+
(block $on_yield (result i32 (ref $ct))
1158+
(resume_with $ct (on $yield $on_yield) (local.get $k))
1159+
(return (local.get $i))
1160+
) ;; on_yield
1161+
(local.set $k)
1162+
(i32.add (local.get $i))
1163+
(local.set $i)
1164+
(local.set $j (i32.add (i32.const 1) (local.get $j)))
1165+
(br_if $next (i32.le_u (local.get $j) (local.get $n)))
1166+
)
1167+
(return (local.get $i)))
1168+
1169+
(elem declare func $nats $nats-bad)
11411170
)
11421171
(assert_return (invoke "sumUp" (i32.const 10)) (i32.const 55))
1172+
(assert_suspension (invoke "sumUp-bad" (i32.const 10)) "unhandled tag")
1173+
1174+
(module
1175+
(type $ht (handler))
1176+
(type $ft (func (param (ref $ht))))
1177+
(type $ct (cont $ft))
1178+
1179+
(type $ft2 (func))
1180+
(type $ct2 (cont $ft2))
1181+
1182+
(global $h1 (mut (ref null $ht)) (ref.null $ht))
1183+
(global $h2 (mut (ref null $ht)) (ref.null $ht))
1184+
1185+
(tag $yield)
1186+
1187+
(func $escape (type $ft)
1188+
(global.set $h2 (local.get 0))
1189+
(resume $ct2 (cont.new $ct2 (ref.func $do-suspend)))
1190+
(unreachable))
1191+
1192+
(func $do-suspend
1193+
(suspend_to $ht $yield (global.get $h1))
1194+
(unreachable))
1195+
1196+
(func $generate-name (type $ft)
1197+
(global.set $h1 (local.get 0))
1198+
(block $on_yield (result (ref $ct))
1199+
(resume_with $ct (on $yield $on_yield) (cont.new $ct (ref.func $escape)))
1200+
(unreachable)
1201+
) ;; on_yield [named]
1202+
(unreachable))
1203+
1204+
(func (export "use-escapee")
1205+
(block $on_yield (result (ref $ct))
1206+
(resume_with $ct (on $yield $on_yield) (cont.new $ct (ref.func $generate-name)))
1207+
(unreachable)
1208+
) ;; on_yield
1209+
(suspend_to $ht $yield (global.get $h2))
1210+
(unreachable))
1211+
1212+
(elem declare func $escape $do-suspend $generate-name)
1213+
)
1214+
(assert_suspension (invoke "use-escapee") "unhandled tag")

0 commit comments

Comments
 (0)