Skip to content
Merged
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
22 changes: 0 additions & 22 deletions crates/wac-parser/src/resolution/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1768,28 +1768,6 @@ impl<'a> AstResolver<'a> {
) -> ResolutionResult<ItemId> {
assert!(state.scopes.is_empty());

// If the item is an instance, we need to recurse on its dependencies
if let ItemKind::Instance(id) = kind {
let interface = &self.definitions.interfaces[id];
let deps = interface
.uses
.keys()
.map(|id| {
(
*id,
self.definitions.interfaces[*id]
.id
.as_ref()
.unwrap()
.clone(),
)
})
.collect::<Vec<_>>();
for (dep, name) in deps {
self.implicit_import(state, name, ItemKind::Instance(dep), package, span)?;
}
}

if let Some(import) = state.imports.get(&name) {
// Check if the implicit import would conflict with an explicit import
if import.package.is_none() {
Expand Down
9 changes: 8 additions & 1 deletion crates/wac-parser/src/resolution/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,13 @@ impl<'a> Encoder<'a> {
ItemKind::Type(ty) => ComponentTypeRef::Type(TypeBounds::Eq(encoder.ty(state, ty)?)),
ItemKind::Func(id) => ComponentTypeRef::Func(encoder.ty(state, Type::Func(id))?),
ItemKind::Instance(id) => {
// Check to see if the instance has already been imported
// This may occur when an interface uses another
if let Some(index) = state.current.instances.get(&id) {
log::debug!("skipping import of interface {id} as it was already imported with instance index {index}", id = id.index());
return Ok(*index);
}

ComponentTypeRef::Instance(encoder.ty(state, Type::Interface(id))?)
}
ItemKind::Component(id) => {
Expand Down Expand Up @@ -710,7 +717,7 @@ impl<'a> TypeEncoder<'a> {

log::debug!("encoding dependency on interface {id}", id = id.index());

let index = self.instance(state, id, true)?;
let index = self.instance(state, id, !state.scopes.is_empty())?;
let import_index = state.current.encodable.instance_count();

state
Expand Down