Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the encoding of wit definitions #1252

Merged
merged 20 commits into from
Oct 18, 2023

Conversation

elliottt
Copy link
Member

@elliottt elliottt commented Oct 13, 2023

Address WebAssembly/component-model#248 by implementing support for the new encoding proposal. Additionally, this PR maintains backwards compatibility with decoding the previous encoding, by detecting when the newer encoding was used.

The rollout of the v2 encoding scheme will follow roughly the same plan as for semicolons in wit: there's a new environment variable introduced that controls the encoding scheme, WIT_COMPONENT_ENCODING_V2 that can be used to control when we encode in the new format, with the default behavior being what's done on main. After tooling has caught up to expecting the new format we can switch the default behavior to be the new format, and then completely remove support for v1 after we're confident nothing depends on it anymore.

@elliottt elliottt marked this pull request as ready for review October 17, 2023 18:51
Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All looks reasonable to me! There's some changes in tests though where *.wit.print shouldn't change but some type definitions are being duplicated through use

@elliottt
Copy link
Member Author

@alexcrichton I've switched the fuzzer over to using the V2 format, and also modified it to never produce an empty package.

@alexcrichton alexcrichton merged commit b57d64c into bytecodealliance:main Oct 18, 2023
15 checks passed
alexcrichton added a commit to alexcrichton/wasmtime that referenced this pull request Oct 19, 2023
This is primarily to pull in bytecodealliance/wasm-tools#1252 to get
decoding of the new format into a Wasmtime release ASAP.
alexcrichton added a commit to bytecodealliance/wasmtime that referenced this pull request Oct 19, 2023
This is primarily to pull in bytecodealliance/wasm-tools#1252 to get
decoding of the new format into a Wasmtime release ASAP.
alexcrichton added a commit to alexcrichton/wasm-tools that referenced this pull request Oct 30, 2023
Currently there's a few encoding changes in-flight in wasm-tools. Two
relevant ones here are:

* How WIT packages are encoded (`WIT_COMPONENT_ENCODING_V2`, bytecodealliance#1252)
* How type information is embedded in core wasm files
  (`WIT_COMPONENT_NEW_ENCODE`, bytecodealliance#1260)

Currently these don't end up playing well together. If the new WIT
package encoding is used then it breaks when combined with the new
metadata encoding. This commit seeks to rectify this situation.
Currently this wasn't previously tested on CI due to this particular
combination of flags not being on in the tests.

The fixes here largely amount to refactoring to delete some duplicated
code. Previously the v1/v2 split introduced an `encode_world` that was
defined in both modules, but the output was different for both modules
and only one would work when fed to decoding. This commit removes this
split and leaves only one canonical `encode_world` function since it
should be the same for both as well.

This then additionally updates `WIT_COMPONENT_NEW_ENCODE=1` to preserve
a lookalike format of a WIT package. Furthermore `decode_world` is
updated to expect this structure as well. The intention is that the
encoded metadata is as-if there was a single world in a WIT package.

These refactorings fix the prior buggy behavior between the two new
encodings. Note that this was only exposed through
`WIT_COMPONENT_NEW_ENCODE=1` which was only very recently added.
Previous builds using only `WIT_COMPONENT_ENCODING_V2=1` should continue
to work fine and produce the same output as before.
alexcrichton added a commit that referenced this pull request Oct 31, 2023
Currently there's a few encoding changes in-flight in wasm-tools. Two
relevant ones here are:

* How WIT packages are encoded (`WIT_COMPONENT_ENCODING_V2`, #1252)
* How type information is embedded in core wasm files
  (`WIT_COMPONENT_NEW_ENCODE`, #1260)

Currently these don't end up playing well together. If the new WIT
package encoding is used then it breaks when combined with the new
metadata encoding. This commit seeks to rectify this situation.
Currently this wasn't previously tested on CI due to this particular
combination of flags not being on in the tests.

The fixes here largely amount to refactoring to delete some duplicated
code. Previously the v1/v2 split introduced an `encode_world` that was
defined in both modules, but the output was different for both modules
and only one would work when fed to decoding. This commit removes this
split and leaves only one canonical `encode_world` function since it
should be the same for both as well.

This then additionally updates `WIT_COMPONENT_NEW_ENCODE=1` to preserve
a lookalike format of a WIT package. Furthermore `decode_world` is
updated to expect this structure as well. The intention is that the
encoded metadata is as-if there was a single world in a WIT package.

These refactorings fix the prior buggy behavior between the two new
encodings. Note that this was only exposed through
`WIT_COMPONENT_NEW_ENCODE=1` which was only very recently added.
Previous builds using only `WIT_COMPONENT_ENCODING_V2=1` should continue
to work fine and produce the same output as before.
alexcrichton added a commit to alexcrichton/wasm-tools that referenced this pull request Nov 1, 2023
This commit enables the new encoding for WIT packages in WebAssembly
components described in WebAssembly/component-model#248 and originally
implemented in bytecodealliance#1252. Support for the new encoding has been in a
wasm-tools for a bit and it's also released with Wasmtime 14. This
switch means that infrastructure will start being exposed to it by
default now. Support for the old encoding remains to assist with interop
as well. In a release or two support for creating the old encoding will
be removed.
pchickey pushed a commit that referenced this pull request Nov 1, 2023
This commit enables the new encoding for WIT packages in WebAssembly
components described in WebAssembly/component-model#248 and originally
implemented in #1252. Support for the new encoding has been in a
wasm-tools for a bit and it's also released with Wasmtime 14. This
switch means that infrastructure will start being exposed to it by
default now. Support for the old encoding remains to assist with interop
as well. In a release or two support for creating the old encoding will
be removed.
alexcrichton added a commit to alexcrichton/wasm-tools that referenced this pull request Sep 11, 2024
This commit removes support for the "v1" encoding of WIT packages into
WebAssembly. This was originally migrated to v2 in bytecodealliance#1252 and v2 was
enabled by default in bytecodealliance#1274. This finishes the transition by removing
support for creating the old encoding.
github-merge-queue bot pushed a commit that referenced this pull request Sep 12, 2024
* Remove v1 encoding support for WIT documents/worlds

This commit removes support for the "v1" encoding of WIT packages into
WebAssembly. This was originally migrated to v2 in #1252 and v2 was
enabled by default in #1274. This finishes the transition by removing
support for creating the old encoding.

* Fix fuzzer build

* Update outdated comments
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