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

Reimplement wac-parser on wac-graph. #82

Merged
merged 15 commits into from
Apr 15, 2024

Conversation

peterhuene
Copy link
Member

@peterhuene peterhuene commented Apr 14, 2024

This PR is a complete reimplementation of wac-parser's resolution to be based on wac-graph.

It also contains an overhaul of the wac-graph API to facilitate its use from wac-parser:

  • Reimplements CompositionGraph on top of petgraph::StableDiGraph, which eliminates needing to keep track of nodes internally to CompositionGraph.
  • Packages now populate their type information into the graph's types collection rather than having their own collections.
  • Splits the Error enum into discrete error types for each graph operation; this allows the AST resolver to properly attach span information to errors.
  • Add type dependency edges for defined types, ensuring topological ordering.
  • Fix encoding of defined type aliases so that each encoded alias refers to the export index of the previously encoded type.
  • Added a debug formatter for CompositionGraph that outputs a DOT representation (used in resolution tests as well).
  • Graph encoding now includes an optional producers custom section.
  • Fixed toposort to be in ascending node index order for independent nodes.

The subtype checker implementation was reverted to the previous implementation, where invert and revert are called at specific points to change the type of check being performed; the newer implementation did not give the correct "expected, found" error messages for AST resolution.

wac resolve now outputs a DOT representation of the resolved composition graph instead of JSON.

A names custom section is now included in the output of an encoded WAC document.

Most of the deleted code comes from code that has already moved into wac-types and wac-graph.

Closes #79.
Fixes #78.
Fixes #76.
Closes #37.

This commit is a complete reimplementation of `wac-parser`'s resolution to be
based on `wac-graph`.

It also contains an overhaul of the `wac-graph` API to facilitate its use from
`wac-parser`:

* Reimplements `CompositionGraph` on top of `petgraph::StableDiGraph`, which
  eliminates needing to keep track of nodes internally to `CompositionGraph`.
* Packages now populate their type information into the graph's types
  collection rather than having their own collections.
* Splits the `Error` enum into discrete error types for each graph operation;
  this allows the AST resolver to properly attach span information to errors.
* Add type dependency edges for defined types, ensuring topological ordering.
* Fix encoding of defined type aliases so that each encoded alias refers to the
  export index of the previously encoded type.
* Added a debug formatter for `CompositionGraph` that outputs a DOT
  representation (used in resolution tests as well).
* Graph encoding now includes an optional producers custom section.
* Fixed toposort to be in ascending node index order for independent nodes.

The subtype checker implementation was reverted to the previous implementation,
where `invert` and `revert` are called at specific points to change the type of
check being performed; the newer implementation did not give the correct
"expected, found" error messages for AST resolution.

`wac resolve` now outputs a DOT representation of the resolved composition
graph instead of JSON.

Most of the deleted code comes from code that has already moved into
`wac-types` and `wac-graph`.

Closes bytecodealliance#79.
Fixes bytecodealliance#78.
Fixes bytecodealliance#76.
@peterhuene
Copy link
Member Author

peterhuene commented Apr 14, 2024

When this and a fix for #81 lands, I plan on adding a publish script to CI and creating a 0.1.0 tag to publish to crates.io.

@peterhuene peterhuene linked an issue Apr 14, 2024 that may be closed by this pull request
Copy link
Collaborator

@rylev rylev left a comment

Choose a reason for hiding this comment

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

I'm seeing a stack overflow when running this against my own project. It seems that for some reason, a particular interface that we're merging into the types collection has an export (a resource) that depends on the interface itself - specifically the resource alias owner is the interface being merged. This causes an infinite loop since we've not yet registered this interface as being remapped.

crates/wac-graph/src/graph.rs Outdated Show resolved Hide resolved
crates/wac-graph/src/graph.rs Outdated Show resolved Hide resolved
crates/wac-graph/src/graph.rs Outdated Show resolved Hide resolved
crates/wac-graph/src/graph.rs Outdated Show resolved Hide resolved
crates/wac-graph/src/graph.rs Outdated Show resolved Hide resolved
crates/wac-graph/src/graph.rs Outdated Show resolved Hide resolved
crates/wac-graph/src/graph.rs Outdated Show resolved Hide resolved
crates/wac-graph/src/graph.rs Outdated Show resolved Hide resolved
crates/wac-graph/src/graph.rs Outdated Show resolved Hide resolved
src/commands/encode.rs Outdated Show resolved Hide resolved
peterhuene and others added 11 commits April 15, 2024 09:38
This commit fixes an existing bug exposed by the refactoring (likely due to the
changes in the order in which nodes are processed for implicit arguments).

Previously, an interface might contain a type alias for another resource it
owns; this lead to the alias information of the resource being self-referential
for the interface containing the aliased resource.

It would then lead to infinite recursion in an attempt to remap such an
interface when populating implicit instantiation arguments.

The fix is to clear the self-referencing information while converting an
interface during package parsing.
@peterhuene peterhuene merged commit 75f2f37 into bytecodealliance:main Apr 15, 2024
7 checks passed
@peterhuene peterhuene deleted the update-parser branch April 15, 2024 20:14
peterhuene added a commit to peterhuene/wac that referenced this pull request Apr 16, 2024
The `NodeInfo` struct should have been removed with the changes in bytecodealliance#82 as it is
no longer needed.
@peterhuene peterhuene mentioned this pull request Apr 16, 2024
peterhuene added a commit that referenced this pull request Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants