fix: guard ProfilerInstant against wasm32 Instant::now() panic#181
fix: guard ProfilerInstant against wasm32 Instant::now() panic#181eliothedeman wants to merge 1 commit intofacebook:mainfrom
Conversation
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.
|
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. ProcessIn 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 If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
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 viaCallEnter/CallExitheap markers, making the Starlark evaluator unusable on WASM.This applies the same
#[cfg(any(test, target_arch = "wasm32"))]guard pattern already used ineval.rs(line 68) andmodules.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 remainingInstant::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"))]