Skip to content

OxCaml Stack Switching#376

Open
TheNumbat wants to merge 7 commits into
masterfrom
oxcaml-stack-switching-rebased
Open

OxCaml Stack Switching#376
TheNumbat wants to merge 7 commits into
masterfrom
oxcaml-stack-switching-rebased

Conversation

@TheNumbat

@TheNumbat TheNumbat commented Jun 15, 2026

Copy link
Copy Markdown
Member

Adds special handling for OCaml 5 effect primitives.

In OxCaml, if the ptwrite instruction is supported, the runtime will emit events that record the fiber ID upon perform and resume. Magic trace can use this ID to save and restore the fiber's callstack and exception handling state. We now also generate flow events connecting the perform and resume pair. Support for ptwrite events comes from #328.

If ptwrite events are not present, we still try to track state for the current fiber, which means programs that perform and resume with a stack discipline will work correctly. Otherwise, we still use the most recent state, so callstacks may be incorrect, but the trace still mostly works (e.g. the migrate test hits unknown return warnings, but still produces something coherent).

Adds several sample programs that exercise effects and exceptions. They all give the expected structure with ptwrite events and something coherent without.

There are currently a bunch of hardcoded offsets to detect the effect operations - I'll add these to the compiler output (alongside the exn handler info) and read them in another pr.

@TheNumbat TheNumbat mentioned this pull request Jun 15, 2026
@TheNumbat TheNumbat marked this pull request as ready for review June 15, 2026 19:46
@TheNumbat TheNumbat requested a review from Svetlitski June 17, 2026 18:42
@glittershark

Copy link
Copy Markdown
Member

@TheNumbat this will need to be updated for oxcaml/oxcaml#6440

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.

4 participants