chore: upgrade wirm from 2.1.0 to 4.0.4#10049
Open
venkkatesh-sekar wants to merge 1 commit intomasterfrom
Open
chore: upgrade wirm from 2.1.0 to 4.0.4#10049venkkatesh-sekar wants to merge 1 commit intomasterfrom
venkkatesh-sekar wants to merge 1 commit intomasterfrom
Conversation
Adapt to wirm 4.0.4 API changes: `Module::parse` and `Instructions::new` gained extra arguments, several methods (`unwrap_local_mut`, `get_ops_mut`, `params`, `encode`, `replace_import_in_module`) now return `Result`, and `wasmparser::TypeRef` gained a `FuncExact` variant which we reject in the import validation alongside other unsupported import kinds.
basvandijk
approved these changes
Apr 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adapt to wirm 4.0.4 API breaks. Mostly mechanical, but two API changes (
Module::parseandInstructions::new) gained extra parameters that need deliberate values, and several methods now returnResultwhere they used to be infallible.API changes and chosen values
Module::parse(wasm, enable_multi_memory)→Module::parse(wasm, enable_multi_memory, with_offsets)All callsites pass
falsefor the newwith_offsetsparameter.with_offsetscontrols whether wirm records each operator's static PC offset within the function body during parsing. We don't need it: instrumentation walks instructions structurally (by index inbody.instructions), never by source byte offset. Saving offsets would only add memory overhead for data we never read.Instructions::new(Vec<Operator>)→Instructions::new(Vec<(Operator, usize)>, locals_start, save_offsets)All callsites pass
save_offsets = falseandlocals_start = 0, and map each operator to(op, 0).save_offsetscontrols whether wirm stores per-operator PC offsets on the resultingInstructions. We're constructing fresh synthetic instruction sequences (helper functions, replacement bodies, instrumented bodies), not parsing existing bytes — there is no real PC to record, and downstream code never reads these offsets. Withsave_offsets = false, the per-operatorusizeandlocals_startare both unused (wirm only consults them inside theif save_offsetsbranch to computeoffset - locals_start). We pass0in both spots as an unambiguous "unused" sentinel.wasmparser::TypeRef::FuncExact(_)(new variant)Added a match arm in
validate_import_sectionthat rejects it with the sameInvalidImportSectionerror used forTagimports. We don't support exact-typed function imports — IC0 imports use ordinaryFunc, and acceptingFuncExactwould require type-equality plumbing we don't need.Methods that now return
ResultThe wirm 4.0.4 versions of
unwrap_local_mut,get_ops_mut,params,encode, andreplace_import_in_moduleall returntypes::Result<_>instead of panicking / returning the bare value. Where the surrounding context guarantees the call can't actually fail, we use.expect(...)with a message documenting why it can't fail. Specifically:inject_metering(instrumentation.rs:1324)get_ops_mut()Instructionshas instrumentationflagsset. Flags are only set by wirm's iterator-based injection API (before/after/alternate), which we never call — we manipulatebody.instructionsdirectly.inject_try_grow_wasm_memory(instrumentation.rs:1425)get_ops_mut()replace_system_api_functions(instrumentation.rs:1500)replace_import_in_module(id)idisn't aTypeRef::Func. Theidcomes fromcalculate_api_indexes, which filters withmatches!(imp.ty, TypeRef::Func(_))before producing indexes.instrument(instrumentation.rs:1593)unwrap_local_mut().filter(|f| f.is_local())already guarantees this.instrument(instrumentation.rs:1614)unwrap_local_mut()instrument(instrumentation.rs:1621)params()FuncType. The lookup usesfunc_body.ty_id, and per the wasm spec a function's type index must reference a function type — enforced by the wasm validator that already ran.module.encode()is the one fallible call we genuinely propagate (viaWasmInstrumentationError::WasmSerializeError), since serialization can in principle fail on malformed instrumented output.Test plan
bazel test— 33 directly-affected targets pass (//rs/embedders:*,//rs/execution_environment:execution_environment_misc_integration_tests/*,//rs/test_utilities/execution_environment:*)cargo clippyclean onic-embeddersandembedders_bench