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

Implement component encoding. #11

Merged
merged 1 commit into from
Nov 25, 2023
Merged

Implement component encoding. #11

merged 1 commit into from
Nov 25, 2023

Conversation

peterhuene
Copy link
Member

@peterhuene peterhuene commented Nov 21, 2023

This giant PR implements encoding of resolved WAC documents, effectively enabling component composition.

Changes to the grammar:

  • resource methods no longer accept references to function types (WIT compat).

Changes to the AST:

  • The AST printer moved into the ast module.
  • Fixed or not printing correctly for printing lookahead failures.
  • Fixed segment spans in a package path not being calculated correctly.
  • Types now store their span; used in new resolution diagnostics.

Changes to resolution:

  • The majority of the resolution logic has been refactored out into an ast submodule.
  • A check was added to ensure function result types do not contain a borrow.
  • There is now a package arena so that instantiations (and implicit imports) can keep track of the originating package for better diagnostic messages.
  • The value type enum was refactored such that borrows and owns of resources don't need allocations in the types arena (unless aliased with type foo = borrow<x>).
  • The Item struct and ItemSource enum were merged into a single Item enum.
  • Support for aliasing resources was added (e.g. type r2 = r;).
  • The Resource type no longer stores a collection of related methods as this greatly complicated merging of implicit imports; now resource methods are exported/imported directly in the exports/imports of an interface/world.
  • Consequently, merging of implicitly imported instances is now correctly implemented.
  • Subtype checking relating to resources has been improved so that the ResourceMap is no longer required.
  • Scope rules now better align with WIT; an interface or world may no longer reference top-level types.
  • Decoding binary packages now properly resolves resources and "used" types in interface and world definitions.
  • The type cache for binary decoding was removed as it was both overly complex and didn't work properly with resources.

Implementation of encoding:

  • Encoding of WIT subset of the grammar should match that of the existing WIT tooling; may be round-tripped with wasm-tools component wit.
  • Encoding of imports, instantiations, and exports should enable the output of actual WebAssembly compositions.

CLI changes:

  • The parse command has been split into three different commands:

    • The parse command that outputs a JSON formatted AST.
    • The resolve command that outputs a JSON formatted resolved document.
    • The encode command that outputs with text or binary WebAssembly.

This giant commit implements encoding of resolved WAC documents, effectively
enabling component composition.

Changes to the grammar:

* resource methods no longer accept references to function types (WIT compat).

Changes to the AST:

* The AST printer moved into the `ast` module.
* Fixed `or` not printing correctly for printing lookahead failures.
* Fixed segment spans in a package path not being calculated correctly.
* Types now store their span; used in new resolution diagnostics.

Changes to resolution:

* The majority of the resolution logic has been refactored out into an `ast`
  submodule.
* A check was added to ensure function result types do not contain a borrow.
* There is now a package arena so that instantiations (and implicit imports)
  can keep track of the originating package for better diagnostic messages.
* The value type enum was refactored such that borrows and owns of resources
  don't need allocations in the types arena (unless aliased with `type foo =
  borrow<x>`).
* The `Item` struct and `ItemSource` enum were merged into a single `Item`
  enum.
* Support for aliasing resources was added (e.g. `type r2 = r;`).
* The `Resource` type no longer stores a collection of related methods as this
  *greatly* complicated merging of implicit imports; now resource methods are
  exported/imported directly in the exports/imports of an interface/world.
* Consequently, merging of implicitly imported instances is now correctly
  implemented.
* Subtype checking relating to resources has been improved so that the
  `ResourceMap` is no longer required.
* Scope rules now better align with WIT; an interface or world may no longer
  reference top-level types.
* Decoding binary packages now properly resolves resources and "used" types in
  interface and world definitions.

Implementation of encoding:

* Encoding of WIT subset of the grammar should match that of the existing WIT
  tooling; may be round-tripped with `wasm-tools component wit`.
* Encoding of imports, instantiations, and exports should enable the output of
  actual WebAssembly compositions.

CLI changes:

* The `parse` command has been split into three different commands:

  * The `parse` command that outputs a JSON formatted AST.
  * The `resolve` command that outputs a JSON formatted resolved document.
  * The `encode` command that outputs with text or binary WebAssembly.
@peterhuene
Copy link
Member Author

@fibonacci1729 absolutely no rush on this review; hopefully this is the last huge refactoring review I'll have for a while (🤞).

Copy link
Collaborator

@fibonacci1729 fibonacci1729 left a comment

Choose a reason for hiding this comment

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

Looks great!

@peterhuene peterhuene merged commit 85a7efa into main Nov 25, 2023
4 checks passed
@peterhuene peterhuene deleted the encoding branch November 25, 2023 07:01
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