Skip to content

Commit 22eaa40

Browse files
committed
Support the new name mangling scheme for components
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.
1 parent 9094e79 commit 22eaa40

File tree

12 files changed

+1053
-259
lines changed

12 files changed

+1053
-259
lines changed

crates/wit-component/src/dummy.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub fn dummy_module(resolve: &Resolve, world: WorldId) -> Vec<u8> {
6767
WorldItem::Interface { id: export, .. } => {
6868
let name = resolve.name_world_key(name);
6969
for (_, func) in resolve.interfaces[*export].functions.iter() {
70-
let name = func.core_export_name(Some(&name));
70+
let name = func.legacy_core_export_name(Some(&name));
7171
push_func(&mut wat, &name, resolve, func);
7272
}
7373

crates/wit-component/src/encoding.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
//! component model.
7373
7474
use crate::metadata::{self, Bindgen, ModuleMetadata};
75-
use crate::validation::{Export, ExportMap, Import, ImportInstance, ImportMap, RESOURCE_DROP};
75+
use crate::validation::{Export, ExportMap, Import, ImportInstance, ImportMap};
7676
use crate::StringEncoding;
7777
use anyhow::{anyhow, bail, Context, Result};
7878
use indexmap::{IndexMap, IndexSet};
@@ -647,6 +647,7 @@ impl<'a> EncodingState<'a> {
647647
}
648648

649649
let world = &resolve.worlds[self.info.encoder.metadata.world];
650+
650651
for export_name in exports {
651652
let export_string = resolve.name_world_key(export_name);
652653
match &world.exports[export_name] {
@@ -1457,7 +1458,7 @@ impl<'a> EncodingState<'a> {
14571458
Import::ImportedResourceDrop(key, iface, id) => {
14581459
let ty = &resolve.types[*id];
14591460
let name = ty.name.as_ref().unwrap();
1460-
name_tmp = format!("{RESOURCE_DROP}{name}");
1461+
name_tmp = format!("{name}_drop");
14611462
(key, &name_tmp, iface.map(|_| resolve.name_world_key(key)))
14621463
}
14631464
Import::WorldFunc(key, name) => (key, name, None),

crates/wit-component/src/encoding/world.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::{Adapter, ComponentEncoder, LibraryInfo, RequiredOptions};
22
use crate::validation::{
3-
validate_adapter_module, validate_module, Import, ImportMap, ValidatedModule, RESOURCE_DROP,
3+
validate_adapter_module, validate_module, Import, ImportMap, ValidatedModule,
44
};
55
use anyhow::{Context, Result};
66
use indexmap::{IndexMap, IndexSet};
@@ -461,7 +461,7 @@ impl ImportedInterface {
461461
let name = ty.name.as_deref().expect("resources must be named");
462462

463463
if required.resource_drops.contains(&id) {
464-
let name = format!("{RESOURCE_DROP}{name}");
464+
let name = format!("{name}_drop");
465465
let prev = self.lowerings.insert(name, Lowering::ResourceDrop(id));
466466
assert!(prev.is_none());
467467
}

0 commit comments

Comments
 (0)