wasm-encoder: add ComponentBuilder::start() - #2657
Merged
alexcrichton merged 1 commit intoSep 14, 2026
Merged
Conversation
Second wasmos-required helper on the same fork branch as `instantiate_exports`. Emits a component start section, invoking `function_index` at instantiation time with `args` (each an index into the component value index space) and producing `results` new values. Returns the index of the first produced value so callers can register the newly-populated value-index slots for downstream consumers (canonical option refs, exports, etc.). Subsequent produced values occupy `first+1`, `first+2`, …, `first+results-1`. Component start is a singleton section (spec allows at most one per component); this helper does not enforce that, matching the underlying `ComponentStartSection` encoder's posture. Flushes any prior aggregating section before emitting so section ordering stays coherent. Unblocks wasmos-component-opt's `SectionItem::ComponentStart` writer arm, which previously `bail!`'d pending this method. See `docs/upstream-needs.md` in that crate for the full context.
zacharywhitley
requested review from
pchickey
and removed request for
a team
September 14, 2026 13:06
alexcrichton
approved these changes
Sep 14, 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.
Summary
Adds a public
ComponentBuilder::start()helper for emitting component start sections. Currently every other section shape has a builder helper (import,export,alias,lift_func,lower_func,core_module,core_module_raw,component_raw,instantiate,instantiate_exportsper #2655,raw_custom_section, …), but component start is missing — callers have to fall back to the lower-levelComponent::section(&ComponentStartSection { … })interface and manually maintain their own value-index counter.Returns the index of the first produced value in the component value index space; subsequent produced values occupy contiguous indices from
first+1up tofirst+results-1.Motivation
Downstream tooling (specifically
wasmos-component-opt, a component-level optimizer) needs to round-trip components that carry start sections. The reader / IR / DCE walker are all in place; only the encoding step was gated on this API. Thecomponent_start_section_roundtripsintegration test in that crate exercises the full path (parse → optimize → re-encode → validate).Design notes
section_accessorsmacro that handlescomponent_instances,types,imports, etc. The helperflush()es any prior section first so section ordering stays coherent.ComponentStartSectionencoder's posture; the caller carries the responsibility.instantiate_exports(wasm-encoder: add ComponentBuilder::instantiate_exports #2655): au32naming the first new index-space entry produced. Callers can iteratefirst..first+resultsif they need each slot separately.Test plan
cargo build -p wasm-encoderclean.cargo test -p wasm-encoder— 36 tests, all pass.component_start_section_roundtripstest (parse a component with a start section → run the -O2 pipeline → re-encode viab.start(...)→ validate).