alexcrichton opened PR #13483 from alexcrichton:refactor-module-registry to bytecodealliance:main:
Prior to this commit the methods of
ModuleRegistryimplicitly relied on the in-memory layout of compiled modules/components, specifically that defined functions for modules were the only interesting functions and they're all clumped in groups. This reliance is surfaced in themodule_and_code_by_pcmethod which was called for various operations such as when throwing an exception or looking at the stack for GC roots. In these scenarios, however, there's no need for aModuleto be used and instead a blandCodeMemorycan be used instead.This commit refactors the internals to no longer look at the
finished_functionsof a module and also avoid aBTreeMapwithin theModuleRegistry. By doing so all methods are now fully agnostic to the internal layout of the code image of a module or component, which in turn empowers refactoring/moving various items around as needed. This is needed for an upcoming change I'm making, for example. Internally most users have moved over tostore_code_by_pcsince the call sites didn't need a module but instead "just some metadata". The main holdout is the logic to generate a trap frame from a stack walk. This is enabled by refactoring the previousBTreeMapto instead hold aCompiledFunctionsTable, used to translate a pc to aFuncKey, and then a mapping ofStaticModuleIndextoRegisteredModuleId. This adds up to the ability to be able to go from an arbitrary pc to a module for a defined wasm function.<!--
Please make sure you include the following information:
If this work has been discussed elsewhere, please include a link to that
conversation. If it was discussed in an issue, just mention "issue #...".Explain why this change is needed. If the details are in an issue already,
this can be brief.Our development process is documented in the Wasmtime book:
https://docs.wasmtime.dev/contributing-development-process.htmlPlease ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->
alexcrichton requested pchickey for a review on PR #13483.
alexcrichton requested wasmtime-core-reviewers for a review on PR #13483.
:thumbs_up: pchickey submitted PR review.
alexcrichton added PR #13483 Refactor ModuleRegistry to not rely on image layout to the merge queue.
:check: alexcrichton merged PR #13483.
alexcrichton removed PR #13483 Refactor ModuleRegistry to not rely on image layout from the merge queue.
Last updated: Jun 01 2026 at 09:49 UTC