Skip to content

Commit 17d4989

Browse files
authored
GUFA: Handle suspend with value (#8423)
Suspend can send a value to the Tag.
1 parent 4d479b4 commit 17d4989

File tree

2 files changed

+109
-0
lines changed

2 files changed

+109
-0
lines changed

src/ir/possible-contents.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,6 +1366,9 @@ struct InfoCollector
13661366
void visitSuspend(Suspend* curr) {
13671367
// TODO: optimize when possible
13681368
addRoot(curr);
1369+
1370+
// The given values are written to the tag, just the same as a throw.
1371+
handleThrow(curr);
13691372
}
13701373

13711374
template<typename T> void handleResume(T* curr) {

test/lit/passes/gufa-cont.wast

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,3 +281,109 @@
281281
)
282282
)
283283
)
284+
285+
(module
286+
;; CHECK: (type $func (func))
287+
;; OPEN_WORLD: (type $func (func))
288+
(type $func (func))
289+
290+
;; CHECK: (type $cont (cont $func))
291+
(type $cont (cont $func))
292+
293+
;; CHECK: (type $func-i32 (func (param i32)))
294+
;; OPEN_WORLD: (type $cont (cont $func))
295+
296+
;; OPEN_WORLD: (type $func-i32 (func (param i32)))
297+
(type $func-i32 (func (param i32)))
298+
299+
300+
301+
;; CHECK: (type $3 (func (result i32)))
302+
303+
;; CHECK: (type $4 (func (result i32 (ref $cont))))
304+
305+
;; CHECK: (elem declare func $cont)
306+
307+
;; CHECK: (tag $tag (type $func))
308+
;; OPEN_WORLD: (type $3 (func (result i32)))
309+
310+
;; OPEN_WORLD: (type $4 (func (result i32 (ref $cont))))
311+
312+
;; OPEN_WORLD: (elem declare func $cont)
313+
314+
;; OPEN_WORLD: (tag $tag (type $func))
315+
(tag $tag (type $func))
316+
317+
;; CHECK: (tag $tag-i32 (type $func-i32) (param i32))
318+
;; OPEN_WORLD: (tag $tag-i32 (type $func-i32) (param i32))
319+
(tag $tag-i32 (type $func-i32))
320+
321+
;; CHECK: (export "resume" (func $resume))
322+
323+
;; CHECK: (func $cont (type $func)
324+
;; CHECK-NEXT: (suspend $tag-i32
325+
;; CHECK-NEXT: (i32.const 1337)
326+
;; CHECK-NEXT: )
327+
;; CHECK-NEXT: )
328+
;; OPEN_WORLD: (export "resume" (func $resume))
329+
330+
;; OPEN_WORLD: (func $cont (type $func)
331+
;; OPEN_WORLD-NEXT: (suspend $tag-i32
332+
;; OPEN_WORLD-NEXT: (i32.const 1337)
333+
;; OPEN_WORLD-NEXT: )
334+
;; OPEN_WORLD-NEXT: )
335+
(func $cont
336+
;; Helper for below.
337+
(suspend $tag-i32
338+
(i32.const 1337)
339+
)
340+
)
341+
342+
;; CHECK: (func $resume (type $3) (result i32)
343+
;; CHECK-NEXT: (tuple.drop 2
344+
;; CHECK-NEXT: (block $block (type $4) (result i32 (ref $cont))
345+
;; CHECK-NEXT: (resume $cont (on $tag-i32 $block)
346+
;; CHECK-NEXT: (cont.new $cont
347+
;; CHECK-NEXT: (ref.func $cont)
348+
;; CHECK-NEXT: )
349+
;; CHECK-NEXT: )
350+
;; CHECK-NEXT: (return
351+
;; CHECK-NEXT: (i32.const 42)
352+
;; CHECK-NEXT: )
353+
;; CHECK-NEXT: )
354+
;; CHECK-NEXT: )
355+
;; CHECK-NEXT: (i32.const 1337)
356+
;; CHECK-NEXT: )
357+
;; OPEN_WORLD: (func $resume (type $3) (result i32)
358+
;; OPEN_WORLD-NEXT: (tuple.drop 2
359+
;; OPEN_WORLD-NEXT: (block $block (type $4) (result i32 (ref $cont))
360+
;; OPEN_WORLD-NEXT: (resume $cont (on $tag-i32 $block)
361+
;; OPEN_WORLD-NEXT: (cont.new $cont
362+
;; OPEN_WORLD-NEXT: (ref.func $cont)
363+
;; OPEN_WORLD-NEXT: )
364+
;; OPEN_WORLD-NEXT: )
365+
;; OPEN_WORLD-NEXT: (return
366+
;; OPEN_WORLD-NEXT: (i32.const 42)
367+
;; OPEN_WORLD-NEXT: )
368+
;; OPEN_WORLD-NEXT: )
369+
;; OPEN_WORLD-NEXT: )
370+
;; OPEN_WORLD-NEXT: (i32.const 1337)
371+
;; OPEN_WORLD-NEXT: )
372+
(func $resume (export "resume") (result i32)
373+
;; A continuation is created, it suspends, and we handle that. We can even
374+
;; infer the suspended value, 1337.
375+
(tuple.extract 2 0
376+
(block $block (result i32 (ref $cont))
377+
(resume $cont (on $tag-i32 $block)
378+
(cont.new $cont
379+
(ref.func $cont)
380+
)
381+
)
382+
(return
383+
(i32.const 42)
384+
)
385+
)
386+
)
387+
)
388+
)
389+

0 commit comments

Comments
 (0)