Skip to content
Open
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
1 change: 0 additions & 1 deletion interpreter/runtime/global.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ exception NotMutable

let alloc (GlobalT (_mut, t) as ty) v =
assert Free.((val_type t).types = Set.empty);
if not (Match.match_val_type [] (type_of_value v) t) then raise Type;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a similar check in Table.store, which you'll also need to remove. (Would also be good to have tests for putting conts in tables.)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. I'll do that in a separate PR if that's ok.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean the test? Sure, that's fine by me. I'd do the change here, though, to leave it in consistent state.

{ty; content = v}

let type_of glob =
Expand Down
2 changes: 1 addition & 1 deletion interpreter/valid/valid.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1147,7 +1147,7 @@ let is_const (c : context) (e : instr) =
| Const _ | VecConst _
| Binary (Value.I32 I32Op.(Add | Sub | Mul))
| Binary (Value.I64 I64Op.(Add | Sub | Mul))
| RefNull _ | RefFunc _
| RefNull _ | RefFunc _ | ContNew _
| RefI31 | StructNew _ | ArrayNew _ | ArrayNewFixed _ -> true
| GlobalGet x -> let GlobalT (mut, _t) = global c x in mut = Cons
| _ -> false
Expand Down
6 changes: 5 additions & 1 deletion proposals/stack-switching/Explainer.md
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,8 @@ function.
```

It takes a reference to a function of type `[t1*] -> [t2*]` whose body
may perform non-local control flow.
may perform non-local control flow. `cont.new` is a constant
expression, so it can be used in places like global initializers.

### Invoking continuations

Expand Down Expand Up @@ -1035,6 +1036,9 @@ where `rt` is the respective target type of the cast instruction, and the `casta
- `rt castable`
- iff not (rt <: (ref null cont))


Finally, `cont.new` is added to the set of constant expressions.

### Execution

The same control tag may be used simultaneously by `throw`, `suspend`,
Expand Down
39 changes: 18 additions & 21 deletions test/core/stack-switching/cont.new.wast
Original file line number Diff line number Diff line change
Expand Up @@ -322,24 +322,21 @@
"type mismatch"
)

;; TODO: Make cont.new constant
;; https://github.com/WebAssembly/stack-switching/issues/145

;; ;; Constant expression in global definition.
;; (module
;; (type $f (func))
;; (type $k (cont $f))
;; (global $k (export "k") (ref $k) (cont.new $k (ref.func $f)))
;; (func $f (type $f))
;; )
;; (assert_return (get "k") (ref.cont))

;; ;; Constant expression in element segment definition.
;; (module
;; (type $f (func))
;; (type $k (cont $f))
;; (table $t (ref null $k) (elem (cont.new $k (ref.func $f))))
;; (func $f (type $f))
;; (func (export "get") (result (ref null $k)) (table.get $t (i32.const 0)))
;; )
;; (assert_return (invoke "get") (ref.cont))
;; Constant expression in global definition.
(module
(type $f (func))
(type $k (cont $f))
(global $k (export "k") (ref $k) (cont.new $k (ref.func $f)))
(func $f (type $f))
)
(assert_return (get "k") (ref.cont))

;; Constant expression in element segment definition.
(module
(type $f (func))
(type $k (cont $f))
(table $t (ref null $k) (elem (cont.new $k (ref.func $f))))
(func $f (type $f))
(func (export "get") (result (ref null $k)) (table.get $t (i32.const 0)))
)
(assert_return (invoke "get") (ref.cont))