bytecodealliance/wac

Dependencies of explicitly imported interfaces are not merged with implicitly imported interfaces

Closed this issue · 1 comments

If I have an explicit import node that is itself importing some dependent package foo and then I am also implicitly importing foo due to some usage elsewhere, the graph encoding will not aggregate and merge those two usages leading to the implicitly imported version always being used. If there are some pieces of the interface in the version from the explicit import that are not present in the implicitly imported version, then encoding will be wrong.

This is because import nodes use the type collection on the CompositionGraph which has not had its interfaces aggregated:

self.import(&mut state, name, &self.0.types, node.item_kind)

Ensuring that the implicit import is remapped is fairly straight forwarded. We can simply return the type aggregator back from the populate_implicit_args method and use that when calling self.import for the explicitly imported item. The issue is that by that time, it's already too late. The encoder has already imported the dependency when encoding implicit imports. When we go to import the dependency of the explicit import, the cache will already say that that dependency has been imported and can be ignored. We need to merge implicit and explicit imports earlier on.

Here's a test that reproduces the issue:

main...rylev:wac:merging-import-dependencies