Skip to content

fix: guard ProfilerInstant against wasm32 Instant::now() panic#181

Closed
eliothedeman wants to merge 1 commit intofacebook:mainfrom
eliothedeman:fix/wasm32-instant-panic
Closed

fix: guard ProfilerInstant against wasm32 Instant::now() panic#181
eliothedeman wants to merge 1 commit intofacebook:mainfrom
eliothedeman:fix/wasm32-instant-panic

Conversation

@eliothedeman
Copy link
Copy Markdown

Summary

On wasm32-unknown-unknown, std::time::Instant::now() panics at runtime ("time not implemented on this platform"). ProfilerInstant::now() is called on every function enter/exit via CallEnter/CallExit heap markers, making the Starlark evaluator unusable on WASM.

This applies the same #[cfg(any(test, target_arch = "wasm32"))] guard pattern already used in eval.rs (line 68) and modules.rs (#154) — falling back to the existing monotonic thread-local counter. Profiling data won't reflect real wall-clock time on WASM, but the evaluator runs correctly.

Context

We're compiling starlark-rust to WASM for a browser-based interactive policy tutorial. The evaluator, module system, and stdlib all work perfectly on wasm32-unknown-unknown — this was the last remaining Instant::now() call site that needed guarding.

Changes

  • starlark/src/eval/runtime/profile/instant.rs: Replace #[cfg(not(test))] / #[cfg(test)] with #[cfg(not(any(test, target_arch = "wasm32")))] / #[cfg(any(test, target_arch = "wasm32"))]

On wasm32-unknown-unknown, std::time::Instant::now() panics at runtime
(time not implemented on this platform). ProfilerInstant is called on
every function enter/exit via CallEnter/CallExit heap markers, making
the evaluator unusable on WASM.

This applies the same cfg(any(test, target_arch = wasm32)) guard pattern
already used in eval.rs and modules.rs -- falling back to a monotonic
thread-local counter. Profiling data will not reflect real wall-clock
time on WASM, but the evaluator works correctly.
@meta-cla
Copy link
Copy Markdown

meta-cla Bot commented Mar 25, 2026

Hi @eliothedeman!

Thank you for your pull request.

We require contributors to sign our Contributor License Agreement, and yours needs attention.

You currently have a record in our system, but the CLA is no longer valid, and will need to be resubmitted.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Mar 25, 2026
@meta-cla
Copy link
Copy Markdown

meta-cla Bot commented Mar 25, 2026

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

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

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant