wasm-encoder: add ComponentBuilder::instantiate_exports - #2655
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`.
f66f04b to
5c4e5a8
Compare
|
Thanks for the PR, and looks like a rustfmt is needed to get CI passing. Also please make sure to review our AI tool usage policy, for a change like this a small new function doesn't need such a large PR description |
|
Sorry about that. Damn things are a little too enthusiastic to post a PR before I can review it. I really wish they'd add something that would queue so it couldn't send them out before review. "Let me just go ahead and submit that PR.....beep bop-boop!" nooooo!!! :) |
FYI, just to make the point more explicit: automated posting of code that has not been reviewed by a human is even more against our policies than the lengthy LLM-generated description is. (In this case it's a trivial function, but the process is important here.) I say this because your wording seems to imply somehow that this is not in your control ("I wish they'd add..."). I'd recommend either removing your bot's GitHub token or setting a hard blocker on creating PRs to Bytecode Alliance repos in whatever permissions system you have until you can work out why this slipped through. If we otherwise have an account that is posting AI-authored content, unreviewed by humans, with a human admitting they don't have full control of it, then this would have to go to the TSC for further action. Thanks! |
|
I appreciate that. I was just highlighting that it's far too easy to have happen and making a joke out of it |
|
On that note I think WebAssembly should be used more often for AI agent sanboxing. It could possibly have prevented the recent OpenAI/HF incident. |
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.