Skip to content

Alias use'd types during composition instead of re-encoding them locally#205

Merged
fibonacci1729 merged 2 commits into
bytecodealliance:mainfrom
salmans:fix-nested-use-type-alias
Jun 16, 2026
Merged

Alias use'd types during composition instead of re-encoding them locally#205
fibonacci1729 merged 2 commits into
bytecodealliance:mainfrom
salmans:fix-nested-use-type-alias

Conversation

@salmans

@salmans salmans commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Composing components fails validation with type not valid to be used as import whenever a use'd type is involved: the encoder re-encodes a type reachable only by id as a fresh local definition rather than referencing the imported instance's export it denotes. A world-level type import whose definition points at a local definition is not a valid import.

Two commits, one per encode path:

  1. use_aliases (type-bound path): records each emitted alias under the used type's ids so id-keyed lookups reuse it. Test: nested-use-type.
  2. value_type (aggregated-import path): the composed component's top-level imports carry no uses map, so this path needs the alias derived from the instances already imported into the scope; imports are encoded instances-first so the instance registers before referrers. Test: use-type-by-id-import.

wac plug on the equivalent two components fails identically before this change. implicit-resource-import is re-blessed (instances-first ordering drops one redundant alias; encoding is equivalent).

ps: The two alias paths could be unified once the aggregator preserves uses through aggregation.

@salmans salmans marked this pull request as draft June 13, 2026 04:05
@salmans salmans changed the title Fix nested use type alias Alias use'd types during composition instead of re-encoding them locally Jun 13, 2026
@salmans salmans force-pushed the fix-nested-use-type-alias branch 2 times, most recently from 512fb63 to b5d5381 Compare June 13, 2026 04:26
@salmans salmans marked this pull request as ready for review June 13, 2026 04:29
@salmans salmans force-pushed the fix-nested-use-type-alias branch 2 times, most recently from 0991467 to 8c14cd5 Compare June 13, 2026 04:40
salmans added 2 commits June 13, 2026 12:32
A type used from another interface, referenced only by id, was re-encoded
as a fresh local definition instead of the alias `use_aliases` emitted,
failing validation. Record the alias under the type's ids so id-keyed
lookups reuse it.
Top-level aggregated imports carry no `uses` map, so a type referenced by
id (e.g. an imported instance's export used in a record field) was
re-encoded as an invalid local definition. `value_type` now aliases it
from the imported instance, and imports are encoded instances-first.
@salmans salmans force-pushed the fix-nested-use-type-alias branch from 8c14cd5 to 1f06572 Compare June 13, 2026 16:33

@fibonacci1729 fibonacci1729 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for this! This looks good to me 👍

@fibonacci1729 fibonacci1729 merged commit 49e1e61 into bytecodealliance:main Jun 16, 2026
7 checks passed
@salmans

salmans commented Jun 16, 2026

Copy link
Copy Markdown
Contributor Author

Thank you so much @fibonacci1729 - is it possible to get a patch release for this change?

@fibonacci1729

Copy link
Copy Markdown
Collaborator

You got it -- i'll work on getting that out today.

@fibonacci1729

Copy link
Copy Markdown
Collaborator

@salmans v0.10.1 is released.

@salmans

salmans commented Jun 16, 2026

Copy link
Copy Markdown
Contributor Author

Thank you! @fibonacci1729

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