Skip to content

Fix wasm worker: poll for synthesize and handle wasmoocaml events#2322

Merged
JasonGross merged 1 commit into
mit-plv:masterfrom
JasonGross:fiat-crypto-fix-wasm
May 5, 2026
Merged

Fix wasm worker: poll for synthesize and handle wasmoocaml events#2322
JasonGross merged 1 commit into
mit-plv:masterfrom
JasonGross:fiat-crypto-fix-wasm

Conversation

@JasonGross
Copy link
Copy Markdown
Collaborator

Summary

  • Replace the fixed 1s setTimeout in fiat-html/wasm_fiat_crypto_worker.js with a 50ms poll for self.synthesize. The current wasm_of_ocaml launcher loads/instantiates the (~13.8 MB) wasm asynchronously and only then runs the OCaml entry that does Js.export "synthesize" ..., so on the deployed site the timeout regularly elapsed before initialization finished, producing ReferenceError: synthesize is not defined.
  • Subscribe to the wasmoocaml:loaded / wasmoocaml:error events introduced in Wasm: dispatch lifecycle events when async instantiation completes ocaml-wasm/wasm_of_ocaml#143: install the handler immediately on success, surface load failures back to the page (instead of polling forever), and log a note on the loaded path that the polling fallback can be removed once the deployed wasm_of_ocaml ships these events.

Test plan

The wasm_of_ocaml launcher loads and instantiates the wasm module
asynchronously, then runs the OCaml entry point that calls
`Js.export "synthesize" ...`. The previous fixed 1s setTimeout in
the worker raced against this and produced
`ReferenceError: synthesize is not defined` on the deployed site
(the wasm blob is now ~13.8 MB and routinely takes longer to load
than 1s).

Replace the timeout with a 50ms poll for `self.synthesize`, and
also subscribe to the `wasmoocaml:loaded` / `wasmoocaml:error`
events introduced in
ocaml-wasm/wasm_of_ocaml#143 so we install
the handler immediately on success and surface load failures back
to the page instead of looping forever. The loaded handler logs a
note that the polling fallback can be removed once the deployed
wasm_of_ocaml ships these events.
@JasonGross JasonGross enabled auto-merge (squash) May 5, 2026 19:23
@JasonGross JasonGross disabled auto-merge May 5, 2026 19:25
@JasonGross JasonGross merged commit cc2e56b into mit-plv:master May 5, 2026
17 checks passed
@JasonGross JasonGross deleted the fiat-crypto-fix-wasm branch May 5, 2026 19:26
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.

1 participant