Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 64 additions & 28 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ wac-parser = { path = "crates/wac-parser", version = "0.10.0-dev", default-featu
wac-resolver = { path = "crates/wac-resolver", version = "0.10.0-dev", default-features = false }
wac-graph = { path = "crates/wac-graph", version = "0.10.0-dev" }
wac-types = { path = "crates/wac-types", version = "0.10.0-dev" }
wit-parser = "0.245.1"
wasmparser = "0.245.1"
wit-component = "0.245.1"
wasm-encoder = "0.245.1"
wasmprinter = "0.245.1"
wasm-metadata = "0.245.1"
wat = "1.245.1"
wit-parser = { git = "https://github.com/ricochet/wasm-tools", branch = "wasmparser-implements" }
wasmparser = { git = "https://github.com/ricochet/wasm-tools", branch = "wasmparser-implements" }
wit-component = { git = "https://github.com/ricochet/wasm-tools", branch = "wasmparser-implements" }
wasm-encoder = { git = "https://github.com/ricochet/wasm-tools", branch = "wasmparser-implements" }
wasmprinter = { git = "https://github.com/ricochet/wasm-tools", branch = "wasmparser-implements" }
wasm-metadata = { git = "https://github.com/ricochet/wasm-tools", branch = "wasmparser-implements" }
wat = { git = "https://github.com/ricochet/wasm-tools", branch = "wasmparser-implements" }
anyhow = "1.0.81"
clap = { version = "4.5.4", features = ["derive"] }
semver = { version = "1.0.22", features = ["serde"] }
Expand Down
6 changes: 5 additions & 1 deletion crates/wac-graph/src/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,11 @@ impl<'a> TypeEncoder<'a> {
.import_type(name, ComponentTypeRef::Instance(index));
if let Some(iid) = &self.0[id].id {
log::debug!("instance index {import_index} ({iid}) is available for aliasing");
state.current.instances.insert(iid.clone(), import_index);
state
.current
.instances
.entry(iid.clone())
.or_insert(import_index);
}
}
_ => panic!("expected only types, functions, and instance types"),
Expand Down
12 changes: 8 additions & 4 deletions crates/wac-graph/src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1690,11 +1690,15 @@ impl<'a> CompositionGraphEncoder<'a> {

fn import(&self, state: &mut State, name: &str, types: &Types, kind: ItemKind) -> u32 {
// Check to see if this is an import of an interface that's already been
// imported; this can happen based on importing of shared dependencies
// imported; this can happen based on importing of shared dependencies.
// Skip deduplication for implements names, as they can import the same
// interface multiple times under different labels.
if let ItemKind::Instance(id) = kind {
if let Some(id) = &types[id].id {
if let Some(index) = state.current.instances.get(id) {
return *index;
if !name.starts_with("[implements=<") {
if let Some(index) = state.current.instances.get(id) {
return *index;
}
}
}
}
Expand Down Expand Up @@ -1739,7 +1743,7 @@ impl<'a> CompositionGraphEncoder<'a> {
log::debug!(
"interface `{id}` is available for aliasing as instance index {index}"
);
state.current.instances.insert(id.clone(), index);
state.current.instances.entry(id.clone()).or_insert(index);
}
}
_ => {}
Expand Down
10 changes: 10 additions & 0 deletions crates/wac-graph/tests/graphs/implements-imports/consumer.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(component
(type (;0;)
(instance
(type (;0;) (func))
(export (;0;) "do-something" (func (type 0)))
)
)
(import "[implements=<test:test/iface>]primary" (instance (;0;) (type 0)))
(import "[implements=<test:test/iface>]backup" (instance (;1;) (type 0)))
)
28 changes: 28 additions & 0 deletions crates/wac-graph/tests/graphs/implements-imports/encoded.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
(component
(type (;0;)
(instance
(type (;0;) (func))
(export (;0;) "do-something" (func (type 0)))
)
)
(import "[implements=<test:test/iface>]primary" (instance (;0;) (type 0)))
(import "[implements=<test:test/iface>]backup" (instance (;1;) (type 0)))
(type (;1;)
(component
(type (;0;)
(instance
(type (;0;) (func))
(export (;0;) "do-something" (func (type 0)))
)
)
(import "[implements=<test:test/iface>]primary" (instance (;0;) (type 0)))
(import "[implements=<test:test/iface>]backup" (instance (;1;) (type 0)))
)
)
(import "unlocked-dep=<test:consumer>" (component (;0;) (type 1)))
(instance (;2;) (instantiate 0
(with "[implements=<test:test/iface>]primary" (instance 0))
(with "[implements=<test:test/iface>]backup" (instance 1))
)
)
)
14 changes: 14 additions & 0 deletions crates/wac-graph/tests/graphs/implements-imports/graph.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"packages": [
{
"name": "test:consumer",
"path": "consumer.wat"
}
],
"nodes": [
{
"type": "instantiation",
"package": 0
}
]
}
3 changes: 3 additions & 0 deletions crates/wac-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,8 @@ serde = { workspace = true, optional = true }
wasmparser = { workspace = true }
wasm-encoder = { workspace = true }

[dev-dependencies]
wat = { workspace = true }

[features]
serde = ["dep:serde"]
16 changes: 13 additions & 3 deletions crates/wac-types/src/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -567,9 +567,19 @@ impl<'a> TypeConverter<'a> {
wasm::ComponentEntityType::Func(id) => {
Ok(ItemKind::Func(self.component_func_type(id)?))
}
wasm::ComponentEntityType::Instance(id) => Ok(ItemKind::Instance(
self.component_instance_type(Some(name), id)?,
)),
wasm::ComponentEntityType::Instance(id) => {
let implements_iface =
ComponentName::new(name, 0)
.ok()
.and_then(|cn| match cn.kind() {
ComponentNameKind::Implements(i) => Some(i.interface().to_owned()),
_ => None,
});
let effective_name = implements_iface.as_deref().unwrap_or(name);
Ok(ItemKind::Instance(
self.component_instance_type(Some(effective_name), id)?,
))
}
wasm::ComponentEntityType::Component(id) => {
Ok(ItemKind::Component(self.component_type(Some(name), id)?))
}
Expand Down
Loading