Skip to content

[test] Add more tests for cont.new#147

Open
tlively wants to merge 1 commit into
mainfrom
cont-new-tests
Open

[test] Add more tests for cont.new#147
tlively wants to merge 1 commit into
mainfrom
cont-new-tests

Conversation

@tlively
Copy link
Copy Markdown
Member

@tlively tlively commented May 4, 2026

Also add support for ref.cont return patterns in assertions.

Comment thread interpreter/script/run.ml Outdated
let run_action act : Value.t list =
match act.it with
| Invoke (x_opt, name, vs) ->
| (Invoke (x_opt, name, vs): Wasm.Script.action') ->
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.

The complaint about the module recursion must be because this refers back to module Wasm. Just drop the prefix.

Comment thread interpreter/runtime/cont.ml Outdated
Comment on lines +6 to +7
type 'ctxt t = 'ctxt cont
and 'ctxt cont = int32 * 'ctxt (* TODO: represent type properly *)
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.

Nit: these don't need to be recursive, just put cont first.


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.

Why remove this check?

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.

This was causing allocation of globals with defined continuation types to fail because type_of_value rerurns the top cont type for continuation values.

Comment thread interpreter/exec/eval.mli Outdated
Comment on lines +18 to +45
type 'a stack = 'a list

type frame =
{
inst : module_inst;
locals : value option ref list;
}

type code = value stack * admin_instr list

and admin_instr = admin_instr' phrase
and admin_instr' =
| Plain of instr'
| Refer of ref_
| Invoke of func_inst
| Breaking of int32 * value stack
| Returning of value stack
| ReturningInvoke of value stack * func_inst
| Throwing of Tag.t * value stack
| Trapping of string
| Label of int * instr list * code
| Frame of int * frame * code
| Handler of int * catch list * code
| Prompt of handle_table * code
| Suspending of tag_inst * value stack * (int32 * ref_) option * ctxt

and ctxt = code -> code
and handle_table = (tag_inst * idx) list * tag_inst list
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.

Is there a reason you want to expose all this? If you need type ctxt in the interface to define cont below, it suffices to export it abstractly (justtype ctxt), and then all the other types don't need to be here.

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.

No reason, this is just copied out of the .ml file and I didn't know it could be shortened. Will give it a shot.

@tlively tlively changed the title [WIP][test] Add more tests for cont.new [test] Add more tests for cont.new May 11, 2026
Also add support for `ref.cont` return patterns in assertions.
@tlively tlively marked this pull request as ready for review May 11, 2026 16:51
@tlively
Copy link
Copy Markdown
Member Author

tlively commented May 11, 2026

@rossberg I've significantly simplified the changes here. PTAL!

@tlively tlively requested a review from fgmccabe May 11, 2026 17:11
Copy link
Copy Markdown
Member

@rossberg rossberg left a comment

Choose a reason for hiding this comment

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

Looks mostly good, but you'll also need to extend the is_js_reftype predicate in script/js.ml, otherwise it will assume that it can im/export conts to/from JS instead of creating wrapper modules (for assertions over cont refs).

Comment thread interpreter/exec/eval.mli
Comment on lines +14 to +17
type ctxt
type handle_table

type cont = int32 * ctxt (* TODO: represent type properly *)
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.

Since these types aren't used externally, I believe we can simplify even further:

Suggested change
type ctxt
type handle_table
type cont = int32 * ctxt (* TODO: represent type properly *)
type cont

@tlively
Copy link
Copy Markdown
Member Author

tlively commented May 11, 2026

Looks mostly good, but you'll also need to extend the is_js_reftype predicate in script/js.ml, otherwise it will assume that it can im/export conts to/from JS instead of creating wrapper modules (for assertions over cont refs).

What's the simplest way to run the JS tests that would expose this bug?

@rossberg
Copy link
Copy Markdown
Member

What's the simplest way to run the JS tests that would expose this bug?

See the commented-out CI interpreter workflow (presuming Node already has it, otherwise try the same with d8):

cd interpreter && opam exec make JS=node ci   # test with V8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants