Skip to content

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

Draft
tlively wants to merge 1 commit intomainfrom
cont-new-tests
Draft

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

Conversation

@tlively
Copy link
Copy Markdown
Member

@tlively tlively commented May 4, 2026

This is a WIP because the interpreter does not quite handle ref.cont patterns in assert_return commands yet. I've bumbled my way through fixing this, but the current error is this:

Error: Module Run in directory _build/default depends on Wasm.
This doesn't make sense to me.

Wasm is the main module of the library and is the only module exposed outside
of the library. Consequently, it should be the one depending on all the other
modules in the library.
-> required by _build/default/.wasm.objs/wasm__Run.impl.all-deps
-> required by _build/default/.wasm.objs/native/wasm__Run.cmx
-> required by _build/default/wasm.cmxa
-> required by _build/default/wasm.exe
make: *** [Makefile:41: wasm] Error 1 

I thought I'd stop here and ask @rossberg for some advice :)

Comment thread interpreter/script/run.ml
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 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
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.

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