Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions crates/c-api/src/component/types/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub unsafe extern "C" fn wasmtime_component_type_import_get(
};
match ty.ty.get_import(&engine.engine, name) {
Some(item) => {
ret.write(item.into());
ret.write(item.ty.into());
true
}
None => false,
Expand All @@ -58,7 +58,7 @@ pub extern "C" fn wasmtime_component_type_import_nth(
let name: &str = name;
name_ret.write(name.as_ptr());
name_len_ret.write(name.len());
type_ret.write(item.into());
type_ret.write(item.ty.into());
true
}
None => false,
Expand Down Expand Up @@ -87,7 +87,7 @@ pub unsafe extern "C" fn wasmtime_component_type_export_get(
};
match ty.ty.get_export(&engine.engine, name) {
Some(item) => {
ret.write(item.into());
ret.write(item.ty.into());
true
}
None => false,
Expand All @@ -108,7 +108,7 @@ pub extern "C" fn wasmtime_component_type_export_nth(
let name: &str = name;
name_ret.write(name.as_ptr());
name_len_ret.write(name.len());
type_ret.write(item.into());
type_ret.write(item.ty.into());
true
}
None => false,
Expand Down
4 changes: 2 additions & 2 deletions crates/c-api/src/component/types/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub unsafe extern "C" fn wasmtime_component_instance_type_export_get(
};
match ty.ty.get_export(&engine.engine, name) {
Some(item) => {
ret.write(item.into());
ret.write(item.ty.into());
true
}
None => false,
Expand All @@ -54,7 +54,7 @@ pub extern "C" fn wasmtime_component_instance_type_export_nth(
let name: &str = name;
name_ret.write(name.as_ptr());
name_len_ret.write(name.len());
type_ret.write(item.into());
type_ret.write(item.ty.into());
true
}
None => false,
Expand Down
4 changes: 4 additions & 0 deletions crates/cli-flags/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,9 @@ wasmtime_option_group! {
/// Component model support for fixed-length lists: this corresponds
/// to the 🔧 emoji in the component model specification
pub component_model_fixed_length_lists: Option<bool>,
/// Component model support for `(implements ...)`, corresponds to the
/// 🏷️ emoji in the upstream spec.
pub component_model_implements: Option<bool>,
/// Whether or not any concurrency infrastructure in Wasmtime is
/// enabled or not.
pub concurrency_support: Option<bool>,
Expand Down Expand Up @@ -1223,6 +1226,7 @@ impl CommonOptions {
("component-model", component_model_error_context, wasm_component_model_error_context)
("component-model", component_model_map, wasm_component_model_map)
("component-model", component_model_fixed_length_lists, wasm_component_model_fixed_length_lists)
("component-model", component_model_implements, wasm_component_model_implements)
("threads", threads, wasm_threads)
("gc", gc, wasm_gc)
("gc", reference_types, wasm_reference_types)
Expand Down
14 changes: 7 additions & 7 deletions crates/environ/src/component/dfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ use wasmparser::component_types::ComponentCoreModuleTypeId;
#[derive(Default)]
pub struct ComponentDfg {
/// Same as `Component::import_types`
pub import_types: PrimaryMap<ImportIndex, (String, TypeDef)>,
pub import_types: PrimaryMap<ImportIndex, (String, ComponentExtern)>,

/// Same as `Component::imports`
pub imports: PrimaryMap<RuntimeImportIndex, (ImportIndex, Vec<String>)>,

/// Same as `Component::exports`
pub exports: IndexMap<String, Export>,
pub exports: IndexMap<String, (Export, ComponentExternData)>,

/// All trampolines and their type signature which will need to get
/// compiled by Cranelift.
Expand Down Expand Up @@ -254,7 +254,7 @@ pub enum Export {
},
Instance {
ty: TypeComponentInstanceIndex,
exports: IndexMap<String, Export>,
exports: IndexMap<String, (Export, ComponentExternData)>,
},
Type(TypeDef),
}
Expand Down Expand Up @@ -639,10 +639,10 @@ impl ComponentDfg {
// creating some lowered imports, perhaps some saved modules, etc.
let mut export_items = PrimaryMap::new();
let mut exports = NameMap::default();
for (name, export) in self.exports.iter() {
for (name, (export, data)) in self.exports.iter() {
let export =
linearize.export(export, &mut export_items, wasmtime_types, wasmparser_types)?;
exports.insert(name, &mut NameMapNoIntern, false, export)?;
exports.insert(name, &mut NameMapNoIntern, false, (export, data.clone()))?;
}

// With all those pieces done the results of the dataflow-based
Expand Down Expand Up @@ -802,10 +802,10 @@ impl LinearizeDfg<'_> {
ty: *ty,
exports: {
let mut map = NameMap::default();
for (name, export) in exports {
for (name, (export, data)) in exports {
let export =
self.export(export, items, wasmtime_types, wasmparser_types)?;
map.insert(name, &mut NameMapNoIntern, false, export)?;
map.insert(name, &mut NameMapNoIntern, false, (export, data.clone()))?;
}
map
},
Expand Down
6 changes: 3 additions & 3 deletions crates/environ/src/component/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub struct Component {
///
/// Note that each name is given an `ImportIndex` here for the next map to
/// refer back to.
pub import_types: PrimaryMap<ImportIndex, (String, TypeDef)>,
pub import_types: PrimaryMap<ImportIndex, (String, ComponentExtern)>,

/// A list of "flattened" imports that are used by this instance.
///
Expand Down Expand Up @@ -107,7 +107,7 @@ pub struct Component {
pub imports: PrimaryMap<RuntimeImportIndex, (ImportIndex, Vec<String>)>,

/// This component's own root exports from the component itself.
pub exports: NameMap<TryString, ExportIndex>,
pub exports: NameMap<TryString, (ExportIndex, ComponentExternData)>,

/// All exports of this component and exported instances of this component.
///
Expand Down Expand Up @@ -491,7 +491,7 @@ pub enum Export {
/// Instance type index, if such is assigned
ty: TypeComponentInstanceIndex,
/// Instance export map
exports: NameMap<TryString, ExportIndex>,
exports: NameMap<TryString, (ExportIndex, ComponentExternData)>,
},
/// An exported type from a component or instance, currently only
/// informational.
Expand Down
14 changes: 10 additions & 4 deletions crates/environ/src/component/translate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ struct Translation<'data> {

/// The list of exports from this component, as pairs of names and an
/// index into an index space of what's being exported.
exports: IndexMap<&'data str, ComponentItem>,
exports: IndexMap<&'data str, (ComponentItem, wasmparser::ComponentExternName<'data>)>,

/// Type information produced by `wasmparser` for this component.
///
Expand Down Expand Up @@ -355,7 +355,10 @@ enum LocalInitializer<'data> {
HashMap<&'data str, ComponentItem>,
ComponentInstanceTypeId,
),
ComponentSynthetic(HashMap<&'data str, ComponentItem>, ComponentInstanceTypeId),
ComponentSynthetic(
HashMap<&'data str, (ComponentItem, wasmparser::ComponentExternName<'data>)>,
ComponentInstanceTypeId,
),

// alias section
AliasExportFunc(ModuleInstanceIndex, &'data str),
Expand Down Expand Up @@ -1310,7 +1313,10 @@ impl<'a, 'data> Translator<'a, 'data> {
for export in s {
let export = export?;
let item = self.kind_to_item(export.kind, export.index)?;
let prev = self.result.exports.insert(export.name.name, item);
let prev = self
.result
.exports
.insert(export.name.name, (item, export.name));
assert!(prev.is_none());
self.result
.initializers
Expand Down Expand Up @@ -1452,7 +1458,7 @@ impl<'a, 'data> Translator<'a, 'data> {
let mut map = HashMap::with_capacity(exports.len());
for export in exports {
let idx = self.kind_to_item(export.kind, export.index)?;
map.insert(export.name.name, idx);
map.insert(export.name.name, (idx, export.name));
}

Ok(LocalInitializer::ComponentSynthetic(map, ty))
Expand Down
60 changes: 38 additions & 22 deletions crates/environ/src/component/translate/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,13 @@ pub(super) fn run(
if let TypeDef::Interface(_) = ty {
continue;
}
let index = inliner
.result
.import_types
.push((name.name.to_string(), ty));
let index = inliner.result.import_types.push((
name.name.to_string(),
ComponentExtern {
ty,
data: ComponentExternData::new(name),
},
));
let path = ImportPath::root(index);
args.insert(name.name, ComponentItemDef::from_import(path, ty)?);
}
Expand All @@ -134,8 +137,9 @@ pub(super) fn run(
assert!(frames.is_empty());

let mut export_map = Default::default();
for (name, def) in exports {
inliner.record_export(name, def, types, &mut export_map)?;
for (name, (def, data)) in exports {
let data = ComponentExternData::new(data);
inliner.record_export(name, def, data, types, &mut export_map)?;
}
inliner.result.exports = export_map;
inliner.result.num_future_tables = types.num_future_tables();
Expand Down Expand Up @@ -346,7 +350,7 @@ enum ComponentInstanceDef<'a> {
// FIXME: same as the issue on `ComponentClosure` where this is cloned a lot
// and may need `Rc`.
Items(
IndexMap<&'a str, ComponentItemDef<'a>>,
IndexMap<&'a str, (ComponentItemDef<'a>, wasmparser::ComponentExternName<'a>)>,
TypeComponentInstanceIndex,
),
}
Expand Down Expand Up @@ -376,7 +380,8 @@ impl<'a> Inliner<'a> {
&mut self,
types: &mut ComponentTypesBuilder,
frames: &mut Vec<(InlinerFrame<'a>, ResourcesBuilder)>,
) -> Result<IndexMap<&'a str, ComponentItemDef<'a>>> {
) -> Result<IndexMap<&'a str, (ComponentItemDef<'a>, wasmparser::ComponentExternName<'a>)>>
{
// This loop represents the execution of the instantiation of a
// component. This is an iterative process which is finished once all
// initializers are processed. Currently this is modeled as an infinite
Expand Down Expand Up @@ -407,7 +412,7 @@ impl<'a> Inliner<'a> {
.translation
.exports
.iter()
.map(|(name, item)| Ok((*name, frame.item(*item, types)?)))
.map(|(name, (item, data))| Ok((*name, (frame.item(*item, types)?, *data))))
.collect::<Result<_>>()?;
let instance_ty = frame.instance_ty;
let (_, snapshot) = frames.pop().unwrap();
Expand Down Expand Up @@ -1295,7 +1300,7 @@ impl<'a> Inliner<'a> {
ComponentSynthetic(map, ty) => {
let items = map
.iter()
.map(|(name, index)| Ok((*name, frame.item(*index, types)?)))
.map(|(name, (index, data))| Ok((*name, (frame.item(*index, types)?, *data))))
.collect::<Result<_>>()?;
let types_ref = frame.translation.types_ref();
let ty = types.convert_instance(types_ref, *ty)?;
Expand Down Expand Up @@ -1401,15 +1406,16 @@ impl<'a> Inliner<'a> {
// item is then pushed in the relevant index space.
ComponentInstanceDef::Import(path, ty) => {
let path = path.push(*name);
let def = ComponentItemDef::from_import(path, types[*ty].exports[*name])?;
let def =
ComponentItemDef::from_import(path, types[*ty].exports[*name].ty)?;
frame.push_item(def);
}

// Given a component instance which was either created
// through instantiation of a component or through a
// synthetic renaming of items we just schlep around the
// definitions of various items here.
ComponentInstanceDef::Items(map, _) => frame.push_item(map[*name].clone()),
ComponentInstanceDef::Items(map, _) => frame.push_item(map[*name].0.clone()),
}
}

Expand Down Expand Up @@ -1615,8 +1621,9 @@ impl<'a> Inliner<'a> {
&mut self,
name: &str,
def: ComponentItemDef<'a>,
data: ComponentExternData,
types: &'a ComponentTypesBuilder,
map: &mut IndexMap<String, dfg::Export>,
map: &mut IndexMap<String, (dfg::Export, ComponentExternData)>,
) -> Result<()> {
let export = match def {
// Exported modules are currently saved in a `PrimaryMap`, at
Expand Down Expand Up @@ -1676,8 +1683,8 @@ impl<'a> Inliner<'a> {
ComponentInstanceDef::Import(path, ty) => {
for (name, ty) in types[ty].exports.iter() {
let path = path.push(name);
let def = ComponentItemDef::from_import(path, *ty)?;
self.record_export(name, def, types, &mut exports)?;
let def = ComponentItemDef::from_import(path, ty.ty)?;
self.record_export(name, def, ty.data.clone(), types, &mut exports)?;
}
dfg::Export::Instance { ty, exports }
}
Expand All @@ -1686,8 +1693,9 @@ impl<'a> Inliner<'a> {
// translated recursively here to our `exports` map which is
// the bag of items we're exporting.
ComponentInstanceDef::Items(map, ty) => {
for (name, def) in map {
self.record_export(name, def, types, &mut exports)?;
for (name, (def, data)) in map {
let data = ComponentExternData::new(data);
self.record_export(name, def, data.clone(), types, &mut exports)?;
}
dfg::Export::Instance { ty, exports }
}
Expand All @@ -1703,7 +1711,7 @@ impl<'a> Inliner<'a> {
ComponentItemDef::Type(def) => dfg::Export::Type(def),
};

map.insert(name.to_string(), export);
map.insert(name.to_string(), (export, data));
Ok(())
}
}
Expand Down Expand Up @@ -1838,7 +1846,7 @@ impl<'a> InlinerFrame<'a> {
/// and which component instantiated it.
fn finish_instantiate(
&mut self,
exports: IndexMap<&'a str, ComponentItemDef<'a>>,
exports: IndexMap<&'a str, (ComponentItemDef<'a>, wasmparser::ComponentExternName<'a>)>,
ty: ComponentInstanceTypeId,
types: &mut ComponentTypesBuilder,
) -> Result<()> {
Expand All @@ -1852,7 +1860,7 @@ impl<'a> InlinerFrame<'a> {
&mut path,
&mut |path| match path {
[] => unreachable!(),
[name, rest @ ..] => exports[name].lookup_resource(rest, types),
[name, rest @ ..] => exports[name].0.lookup_resource(rest, types),
},
);
}
Expand Down Expand Up @@ -1916,7 +1924,7 @@ impl<'a> ComponentItemDef<'a> {
cur = match instance {
// If this instance is a "bag of things" then this is as easy as
// looking up the name in the bag of names.
ComponentInstanceDef::Items(names, _) => names[element].clone(),
ComponentInstanceDef::Items(names, _) => names[element].0.clone(),

// If, however, this instance is an imported instance then this
// is a further projection within the import with one more path
Expand All @@ -1925,7 +1933,7 @@ impl<'a> ComponentItemDef<'a> {
// in conjunction with a one-longer `path` to produce a new item
// definition.
ComponentInstanceDef::Import(path, ty) => {
ComponentItemDef::from_import(path.push(element), types[ty].exports[element])
ComponentItemDef::from_import(path.push(element), types[ty].exports[element].ty)
.unwrap()
}
ComponentInstanceDef::Intrinsics => {
Expand All @@ -1948,3 +1956,11 @@ enum InstanceModule {
Static(StaticModuleIndex),
Import(TypeModuleIndex),
}

impl ComponentExternData {
fn new(data: wasmparser::ComponentExternName<'_>) -> Self {
ComponentExternData {
implements: data.implements.map(|s| s.to_string()),
}
}
}
Loading
Loading