Skip to content

Consolidate generated modules in wit-component into one - #2600

Merged
alexcrichton merged 5 commits into
bytecodealliance:mainfrom
alexcrichton:consolidate-modules
Aug 13, 2026
Merged

Consolidate generated modules in wit-component into one#2600
alexcrichton merged 5 commits into
bytecodealliance:mainfrom
alexcrichton:consolidate-modules

Conversation

@alexcrichton

@alexcrichton alexcrichton commented Aug 12, 2026

Copy link
Copy Markdown
Member

To fully address some upcoming refactorings for wasip3 intrinsics this commit refactors the output of wit-component to ensure that all the little helper modules generated are glommed into one instead of lots of separate ones. The main purpose of this is to address the use case now addressed here where task intrinsics need to hook resource destructors which previously wasn't handled, nor was it easily possible.

This is mostly a lot of refactoring and attempting to move some complexity of encoding.rs to a separate file. The end result is that these modules are now all folded into one module:

  • The original fixup module which initializes the table of the shim module, for example. This is used when lowerings can't happen until after the main module is instantiated.
  • The shim module used to have a start function for the _initialize hook is now folded into the fixup module.
  • The __init module used by wasm-tools component link is now located in the main fixup module.
  • The task initialization hooks module is now part of the fixup module and now handles the use case of resource destructors as well.

This is all intended to be refactoring such that the next commit, adding more task lifetime hooks to get added, will be much easier to do.

Note: this is built on #2599

@alexcrichton
alexcrichton requested a review from a team as a code owner August 12, 2026 22:01
@alexcrichton
alexcrichton requested review from fitzgen and removed request for a team August 12, 2026 22:01
@alexcrichton
alexcrichton force-pushed the consolidate-modules branch 2 times, most recently from 20b09f7 to 827fbb2 Compare August 12, 2026 23:35
This commit moves some logic of generating a "fixup" module into a
separate file and starts to lay the foundation for merging various small
bits and pieces of modules into just one fixup module instead of
multiple. The goal of this work is to enable a future addition where the
task intrinsics are becoming more invasive and need to handle more
cases, and it seemed prudent to take this opportunity to go ahead and
optimize the various modules that wit-component generates.
No need for this to be separate any more.
This commit merges the `__init` module previously generated by
`wasm-tools component link` into the "fixup" module that's growing to
encompass all other smaller modules that are generated. This is done
with refactoring in a few places and additionally helps generate debug
names for items and deduplicate type information.
This adjust the location of task hook creation to primarily happen in
the main fixup module now. This avoids another "extra" module of sorts
and helps to minimize the number of core modules in components created
for wasip3. This additionally handles one more case than was previously
handled with this new refactoring -- resource destructors. Destructors
for resources happen on new tasks and need hooks around them and the
version that's filled in to the shim module now properly has hooks in
place.
@alexcrichton
alexcrichton requested review from dicej and removed request for fitzgen August 13, 2026 19:05
@alexcrichton

Copy link
Copy Markdown
Member Author

I'm going to switch this over to @dicej since I'd like to get your eyes in particular on the dynamic library changes here

Comment thread crates/wit-component/src/encoding/fixup.rs Outdated
@alexcrichton
alexcrichton enabled auto-merge August 13, 2026 21:19
@alexcrichton
alexcrichton added this pull request to the merge queue Aug 13, 2026
Merged via the queue into bytecodealliance:main with commit 8a8ef6d Aug 13, 2026
37 checks passed
@alexcrichton
alexcrichton deleted the consolidate-modules branch August 13, 2026 21:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants