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. 25
      crates/environ/src/component/translate.rs
  2. 29
      tests/misc_testsuite/component-model/aliasing.wast

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

@ -622,11 +622,34 @@ 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 {
// 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); self.types.push_component_typedef(ty);
} }
} }
} }
}
Payload::ComponentStartSection { start, range } => { Payload::ComponentStartSection { start, range } => {
self.validator.component_start_section(&start, &range)?; self.validator.component_start_section(&start, &range)?;

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