Skip to content

Commit

Permalink
Support the new name mangling scheme for components
Browse files Browse the repository at this point in the history
This commit adds support for WebAssembly/component-model#378 to
`wit-component`. Notably a new set of alternative names are registered
and recognized during the module-to-component translation process.
Support for the previous set of names are all preserved and will
continue to be supported for some time. The new names are, for now,
recognized in parallel to the old names.

This involved some refactoring to the validation part of `wit-component`
and further encapsulation of various names to one small location instead
of a shared location for everywhere else to use as well.
  • Loading branch information
alexcrichton committed Sep 28, 2024
1 parent 9094e79 commit 22eaa40
Show file tree
Hide file tree
Showing 12 changed files with 1,053 additions and 259 deletions.
2 changes: 1 addition & 1 deletion crates/wit-component/src/dummy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub fn dummy_module(resolve: &Resolve, world: WorldId) -> Vec<u8> {
WorldItem::Interface { id: export, .. } => {
let name = resolve.name_world_key(name);
for (_, func) in resolve.interfaces[*export].functions.iter() {
let name = func.core_export_name(Some(&name));
let name = func.legacy_core_export_name(Some(&name));
push_func(&mut wat, &name, resolve, func);
}

Expand Down
5 changes: 3 additions & 2 deletions crates/wit-component/src/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
//! component model.
use crate::metadata::{self, Bindgen, ModuleMetadata};
use crate::validation::{Export, ExportMap, Import, ImportInstance, ImportMap, RESOURCE_DROP};
use crate::validation::{Export, ExportMap, Import, ImportInstance, ImportMap};
use crate::StringEncoding;
use anyhow::{anyhow, bail, Context, Result};
use indexmap::{IndexMap, IndexSet};
Expand Down Expand Up @@ -647,6 +647,7 @@ impl<'a> EncodingState<'a> {
}

let world = &resolve.worlds[self.info.encoder.metadata.world];

for export_name in exports {
let export_string = resolve.name_world_key(export_name);
match &world.exports[export_name] {
Expand Down Expand Up @@ -1457,7 +1458,7 @@ impl<'a> EncodingState<'a> {
Import::ImportedResourceDrop(key, iface, id) => {
let ty = &resolve.types[*id];
let name = ty.name.as_ref().unwrap();
name_tmp = format!("{RESOURCE_DROP}{name}");
name_tmp = format!("{name}_drop");
(key, &name_tmp, iface.map(|_| resolve.name_world_key(key)))
}
Import::WorldFunc(key, name) => (key, name, None),
Expand Down
4 changes: 2 additions & 2 deletions crates/wit-component/src/encoding/world.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::{Adapter, ComponentEncoder, LibraryInfo, RequiredOptions};
use crate::validation::{
validate_adapter_module, validate_module, Import, ImportMap, ValidatedModule, RESOURCE_DROP,
validate_adapter_module, validate_module, Import, ImportMap, ValidatedModule,
};
use anyhow::{Context, Result};
use indexmap::{IndexMap, IndexSet};
Expand Down Expand Up @@ -461,7 +461,7 @@ impl ImportedInterface {
let name = ty.name.as_deref().expect("resources must be named");

if required.resource_drops.contains(&id) {
let name = format!("{RESOURCE_DROP}{name}");
let name = format!("{name}_drop");
let prev = self.lowerings.insert(name, Lowering::ResourceDrop(id));
assert!(prev.is_none());
}
Expand Down
Loading

0 comments on commit 22eaa40

Please sign in to comment.