Browse Source

Fix export translation for components. (#6108)

* Fix export translation for components.

Exports in the component model cause a new index to be added to the index space
of the item being exported.

This commit updates component translation so that translation of component
export sections properly updates internal lists representing those index
spaces.

* Code review feedback.
pull/6114/head
Peter Huene 2 years ago
committed by GitHub
parent
commit
73f42bf817
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 27
      crates/environ/src/component/translate.rs
  2. 29
      tests/misc_testsuite/component-model/aliasing.wast

27
crates/environ/src/component/translate.rs

@ -622,8 +622,31 @@ impl<'a, 'data> Translator<'a, 'data> {
self.result self.result
.initializers .initializers
.push(LocalInitializer::Export(item)); .push(LocalInitializer::Export(item));
if let ComponentItem::Type(ty) = item {
self.types.push_component_typedef(ty); // Exports create a new index, so push the item onto the
// appropriate list.
match item {
ComponentItem::Func(idx) => {
self.result
.component_funcs
.push(self.result.component_funcs[idx]);
}
ComponentItem::Module(_idx) => {
// We don't need to do anything here for modules as
// the type information isn't tracked in the initial
// translation pass.
}
ComponentItem::Component(idx) => {
self.result.components.push(self.result.components[idx]);
}
ComponentItem::ComponentInstance(idx) => {
self.result
.component_instances
.push(self.result.component_instances[idx]);
}
ComponentItem::Type(ty) => {
self.types.push_component_typedef(ty);
}
} }
} }
} }

29
tests/misc_testsuite/component-model/aliasing.wast

@ -0,0 +1,29 @@
(component
(component
(component
(component)
(instance (instantiate 0))
(export "a" (instance 0))
)
(instance (instantiate 0))
(export "a" (instance 0))
)
(instance (instantiate 0)) ;; instance 0
(alias export 0 "a" (instance)) ;; instance 1
(export "a" (instance 1)) ;; instance 2
(alias export 2 "a" (instance)) ;; instance 3
(export "inner-a" (instance 3)) ;; instance 4
)
(component
(component
(core module)
(export "a" (core module 0))
)
(instance (instantiate 0))
(alias export 0 "a" (core module)) ;; module 0
(export "a" (core module 0)) ;; module 1
(core instance (instantiate 1))
)
Loading…
Cancel
Save