Skip to content

Make WIT decoded from components match them - #2851

Open
sansmoraxz wants to merge 9 commits into
bytecodealliance:mainfrom
sansmoraxz:wit-decode/bail-2-roundtrip
Open

sansmoraxz wants to merge 9 commits into
bytecodealliance:mainfrom
sansmoraxz:wit-decode/bail-2-roundtrip

Conversation

@sansmoraxz

Copy link
Copy Markdown
Contributor

This is hopefully the last set of backports


Some components decoded fine, but component wit then printed WIT that doesn't parse, or that failed when encoded again. Now each of these either decodes to valid WIT or returns an error saying what WIT can't express.

Now accepted:

  • World functions that use an imported interface's type directly.
  • Types that reuse an anonymous type, like type t = own<r> after list<own<r>>.

Now an error:

  • Worlds whose exports would see an interface twice.
  • Interfaces referring to a type they don't define or use.
  • Worlds importing an interface but not the interfaces it uses.
  • Package docs WIT can't write, or with invalid @since versions.

Also fixed: the printer now escapes keyword feature names (%func).

A world's `use` of an interface's type is encoded as a type import, but
a component's functions can also refer to an imported instance's type
directly. Decoding such a function gave the world no `use` for the type,
and its WIT, such as `import f: func(x: t);`, didn't parse.

The decoded world now gets the `use`s its functions need. It's an error
if another item in the world already has the type's name.
A world exporting `a:b/i` and an interface that uses `a:b/i` through the
imported `a:b/j` would give that interface both the imported and the
exported `a:b/i`, which WIT rejects. Decoding accepted such a component
and printed WIT that doesn't parse.

Decoded worlds now go through the same export check as worlds parsed
from WIT.
Decoding injected a package-docs section's docs and feature names as
they were, so a feature name like `]x` or docs with a control code
printed as WIT that doesn't parse.
Decoding injected a package-docs section's `@since` versions as they
were, so one newer than the package's version, or in a package without
a version, printed as WIT that doesn't parse.
`@unstable(feature = %func)` printed as `@unstable(feature = func)`,
which doesn't parse.
Decoding failed on an interface whose `type t = own<r>` reused the
anonymous `own<r>` of an earlier `list<own<r>>`, taking it for a `use`
of an anonymous type. In a world the same encoding decoded as
`type t = r`, an alias of the resource rather than a handle to it.

Such a type is now defined as the anonymous type it reuses. In an
interface, only when every named type it reaches belongs to that
interface; anything else still has no WIT form and still errors.
Decoding merges every use of an interface into one, so an export of
`a:x/k` with a function taking `a:x/l`'s `t`, which it neither defines
nor `use`s, gave interface `k` that function. `component wit` printed WIT
that doesn't parse, and encoding it failed later on.

Named interfaces can now only refer to their own types and to types they
`use` under those types' names. Unnamed interfaces are left alone, since
they still encode and `wasm-compose` makes them.
Decoding merges a world's import and export of one interface, so an
export that `use`s `a:x/l` gave the imported `a:x/k` a dependency on
`a:x/l`, which the world only exports. WIT would import `a:x/l` for `k`,
but the decoded world didn't, and encoding it failed later on.
@sansmoraxz
sansmoraxz requested a review from a team as a code owner November 25, 2026 08:37
@sansmoraxz
sansmoraxz requested review from dicej and removed request for a team November 25, 2026 08:37

This branch has not been deployed

No deployments
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.

1 participant