Skip to content

Commit ff6cf2b

Browse files
committed
Reimplement wac-parser on wac-graph.
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 #79. Fixes #78. Fixes #76.
1 parent 1ad1447 commit ff6cf2b

89 files changed

Lines changed: 3678 additions & 9390 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ keywords = ["webassembly", "wasm", "components", "component-model"]
1919
repository = "https://github.com/bytecodealliance/wac"
2020

2121
[dependencies]
22+
wac-types = { workspace = true }
23+
wac-graph = { workspace = true }
2224
wac-resolver = { workspace = true, default-features = false }
2325
wac-parser = { workspace = true, default-features = false }
2426
anyhow = { workspace = true }
@@ -30,7 +32,6 @@ owo-colors = { workspace = true }
3032
serde = { workspace = true }
3133
serde_json = { workspace = true }
3234
wat = { workspace = true }
33-
wasmparser = { workspace = true }
3435
wasmprinter = { workspace = true }
3536
thiserror = { workspace = true }
3637
indexmap = { workspace = true }

crates/wac-graph/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ semver = { workspace = true }
2121
serde = { workspace = true, optional = true }
2222
wasm-encoder = { workspace = true }
2323
log = { workspace = true }
24+
wasm-metadata = { workspace = true }
2425

2526
[dev-dependencies]
2627
pretty_assertions = { workspace = true }

crates/wac-graph/src/encoding.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
use crate::{NodeId, PackageId};
1+
use crate::PackageId;
22
use indexmap::IndexMap;
3+
use petgraph::graph::NodeIndex;
34
use std::collections::HashMap;
45
use wac_types::{
56
CoreExtern, DefinedType, DefinedTypeId, Enum, Flags, FuncResult, FuncTypeId, InterfaceId,
@@ -116,11 +117,11 @@ pub struct State {
116117
/// The current encoding scope.
117118
pub current: Scope,
118119
/// A map of nodes in the graph to their encoded indexes.
119-
pub node_indexes: HashMap<NodeId, u32>,
120+
pub node_indexes: HashMap<NodeIndex, u32>,
120121
/// The map of package identifiers to encoded components (either imported or defined).
121122
pub packages: HashMap<PackageId, u32>,
122123
/// A map of instantiation nodes to a list of their encoded implicitly imported arguments.
123-
pub implicit_args: HashMap<NodeId, Vec<(String, ComponentExportKind, u32)>>,
124+
pub implicit_args: HashMap<NodeIndex, Vec<(String, ComponentExportKind, u32)>>,
124125
}
125126

126127
impl State {

0 commit comments

Comments
 (0)