wasm-encoder: add ComponentBuilder::instantiate_exports - #2655
Open
zacharywhitley wants to merge 1 commit into
Open
wasm-encoder: add ComponentBuilder::instantiate_exports#2655zacharywhitley wants to merge 1 commit into
zacharywhitley wants to merge 1 commit into
Conversation
The core-level analogue `core_instantiate_exports` already exists on `ComponentBuilder` and mirrors the `Instance::FromExports` variant of the core instance section. The component-level side had no equivalent: `ComponentInstanceSection::export_items` is public but only reachable through the manual section-append path, not the builder facade. Add `instantiate_exports` next to `instantiate` so callers rebuilding a component structurally from a parsed one can round-trip `ComponentInstance::FromExports` the same way core-level `Instance::FromExports` already round-trips. The signature follows the section-level `ComponentInstanceSection:: export_items` — `N: Into<ComponentExternName<'a>>` in the name slot, preserving the rich name form (`implements` / `version_suffix` / `external_id`) an item can carry. `&'a str` satisfies the bound via the existing `From<&'a str> for ComponentExternName<'a>`, so callers that only need a plain name write the same call as with `core_instantiate_exports`.
zacharywhitley
force-pushed
the
feat/component-instantiate-exports
branch
from
September 12, 2026 12:29
f66f04b to
5c4e5a8
Compare
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.
The core-level analogue
core_instantiate_exportsalready exists onComponentBuilderand mirrors theInstance::FromExportsvariant ofthe core instance section. The component-level side had no equivalent:
ComponentInstanceSection::export_itemsis public but only reachablethrough the manual section-append path, not the builder facade.
This adds
instantiate_exportsnext toinstantiateso callersrebuilding a component structurally from a parsed one can round-trip
ComponentInstance::FromExportsthe same way core-levelInstance::FromExportsalready round-trips.Signature
Mirrors
core_instantiate_exports— same(&'a str, K, u32)triples,just with
ComponentExportKindin the kind slot instead ofExportKind:Motivation
A component optimizer that reads a component with
wasmparserandre-emits it via
ComponentBuilderneeds to round-trip everyComponentInstancevariant.Instantiatewas already covered byComponentBuilder::instantiate;FromExportswas the missing case.The public alternative was dropping down to
ComponentInstanceSection::export_itemsand manually appending thesection, bypassing the builder's index-space bookkeeping — which
defeats the point of using the builder.
Alternatives
component_instances()accessor:wider surface area than needed and doesn't match the pattern
established by
core_instantiate_exports.duplicating the builder's index-space accounting.
The chosen shape sticks to the precedent already set for the core
side.