Skip to content

Commit d918f9c

Browse files
authored
[Stack Switching] wasm-ctor-eval: stop on serializing continuations to globals (#8585)
Continuations cannot be serialized.
1 parent 1527ce0 commit d918f9c

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

src/tools/wasm-ctor-eval.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,13 @@ class EvallingModuleRunner : public ModuleRunnerBase<EvallingModuleRunner> {
213213
return ModuleRunnerBase<EvallingModuleRunner>::visitGlobalGet(curr);
214214
}
215215

216+
Flow visitGlobalSet(GlobalSet* curr) {
217+
if (curr->value->type.isContinuation()) {
218+
throw FailToEvalException("cannot serialize continuations to globals");
219+
}
220+
return ModuleRunnerBase<EvallingModuleRunner>::visitGlobalSet(curr);
221+
}
222+
216223
Flow visitTableGet(TableGet* curr) {
217224
// We support tableLoad, below, so that call_indirect works (it calls it
218225
// internally), but we want to disable table.get for now.

test/lit/ctor-eval/cont-noserial.wast

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,3 +351,76 @@
351351
(func $export (export "export")
352352
)
353353
)
354+
355+
;; Now the problem happens when we write a continuation to a global, which we
356+
;; cannot do. Nothing can be optimized here.
357+
(module
358+
;; CHECK: (type $func (func))
359+
;; NOKEEP: (type $func (func))
360+
(type $func (func))
361+
;; CHECK: (type $cont (cont $func))
362+
;; NOKEEP: (type $cont (cont $func))
363+
(type $cont (cont $func))
364+
365+
;; CHECK: (type $2 (func (result (ref null $cont))))
366+
367+
;; CHECK: (global $global (mut (ref null $cont)) (ref.null nocont))
368+
;; NOKEEP: (type $2 (func (result (ref null $cont))))
369+
370+
;; NOKEEP: (global $global (mut (ref null $cont)) (ref.null nocont))
371+
(global $global (mut (ref null $cont)) (ref.null $cont))
372+
373+
;; CHECK: (elem declare func $func)
374+
375+
;; CHECK: (export "read" (func $read))
376+
377+
;; CHECK: (export "test" (func $test))
378+
;; NOKEEP: (elem declare func $func)
379+
380+
;; NOKEEP: (export "read" (func $read))
381+
382+
;; NOKEEP: (export "test" (func $test))
383+
(export "test" (func $test))
384+
385+
;; CHECK: (func $func (type $func)
386+
;; CHECK-NEXT: (nop)
387+
;; CHECK-NEXT: )
388+
;; NOKEEP: (func $func (type $func)
389+
;; NOKEEP-NEXT: (nop)
390+
;; NOKEEP-NEXT: )
391+
(func $func
392+
)
393+
394+
;; CHECK: (func $test (type $func)
395+
;; CHECK-NEXT: (global.set $global
396+
;; CHECK-NEXT: (cont.new $cont
397+
;; CHECK-NEXT: (ref.func $func)
398+
;; CHECK-NEXT: )
399+
;; CHECK-NEXT: )
400+
;; CHECK-NEXT: )
401+
;; NOKEEP: (func $test (type $func)
402+
;; NOKEEP-NEXT: (global.set $global
403+
;; NOKEEP-NEXT: (cont.new $cont
404+
;; NOKEEP-NEXT: (ref.func $func)
405+
;; NOKEEP-NEXT: )
406+
;; NOKEEP-NEXT: )
407+
;; NOKEEP-NEXT: )
408+
(func $test
409+
(global.set $global
410+
(cont.new $cont
411+
(ref.func $func)
412+
)
413+
)
414+
)
415+
416+
;; CHECK: (func $read (type $2) (result (ref null $cont))
417+
;; CHECK-NEXT: (global.get $global)
418+
;; CHECK-NEXT: )
419+
;; NOKEEP: (func $read (type $2) (result (ref null $cont))
420+
;; NOKEEP-NEXT: (global.get $global)
421+
;; NOKEEP-NEXT: )
422+
(func $read (export "read") (result (ref null $cont))
423+
(global.get $global)
424+
)
425+
)
426+

0 commit comments

Comments
 (0)