Skip to content
Closed
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
41 changes: 14 additions & 27 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -769,3 +769,18 @@ fpr = "fpr"

[workspace.metadata.typos.files]
extend-exclude = [ "docs/js/mermaid*.js", "crates/wasi-nn/**/*.txt", "*.isle" ]

[patch.crates-io]
wasmparser = { git = 'https://github.com/bytecodealliance/wasm-tools' }
wat = { git = 'https://github.com/bytecodealliance/wasm-tools' }
wast = { git = 'https://github.com/bytecodealliance/wasm-tools' }
wasmprinter = { git = 'https://github.com/bytecodealliance/wasm-tools' }
wasm-encoder = { git = 'https://github.com/bytecodealliance/wasm-tools' }
wasm-smith = { git = 'https://github.com/bytecodealliance/wasm-tools' }
wasm-mutate = { git = 'https://github.com/bytecodealliance/wasm-tools' }
wit-parser = { git = 'https://github.com/bytecodealliance/wasm-tools' }
wit-component = { git = 'https://github.com/bytecodealliance/wasm-tools' }
wasm-wave = { git = 'https://github.com/bytecodealliance/wasm-tools' }
wasm-compose = { git = 'https://github.com/bytecodealliance/wasm-tools' }
wasm-metadata = { git = 'https://github.com/bytecodealliance/wasm-tools' }
json-from-wast = { git = 'https://github.com/bytecodealliance/wasm-tools' }
21 changes: 11 additions & 10 deletions crates/environ/src/component/translate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use wasmparser::component_types::{
ComponentFuncTypeId, ComponentInstanceTypeId, ComponentValType,
};
use wasmparser::types::Types;
use wasmparser::{Chunk, ComponentImportName, Encoding, Parser, Payload, Validator};
use wasmparser::{Chunk, ComponentExternName, Encoding, Parser, Payload, Validator};

mod adapt;
pub use self::adapt::*;
Expand Down Expand Up @@ -176,7 +176,7 @@ struct Translation<'data> {
// is straight from `wasmparser`'s passes.
enum LocalInitializer<'data> {
// imports
Import(ComponentImportName<'data>, ComponentEntityType),
Import(ComponentExternName<'data>, ComponentEntityType),

// An import of an intrinsic for compile-time builtins.
IntrinsicsImport,
Expand Down Expand Up @@ -768,11 +768,12 @@ impl<'a, 'data> Translator<'a, 'data> {
let import = import?;
let types = self.validator.types(0).unwrap();
let ty = types
.component_entity_type_of_import(import.name.0)
.unwrap();
.component_item_for_import(import.name.name)
.unwrap()
.ty;

if self.is_unsafe_intrinsics_import(import.name.0) {
self.check_unsafe_intrinsics_import(import.name.0, ty)?;
if self.is_unsafe_intrinsics_import(import.name.name) {
self.check_unsafe_intrinsics_import(import.name.name, ty)?;
self.result
.initializers
.push(LocalInitializer::IntrinsicsImport);
Expand Down Expand Up @@ -1309,7 +1310,7 @@ 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.0, item);
let prev = self.result.exports.insert(export.name.name, item);
assert!(prev.is_none());
self.result
.initializers
Expand Down Expand Up @@ -1451,7 +1452,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.0, idx);
map.insert(export.name.name, idx);
}

Ok(LocalInitializer::ComponentSynthetic(map, ty))
Expand Down Expand Up @@ -1662,13 +1663,13 @@ impl<'a, 'data> Translator<'a, 'data> {
);

for (name, ty) in &instance_ty.exports {
let ComponentEntityType::Func(func_ty) = ty else {
let ComponentEntityType::Func(func_ty) = ty.ty else {
bail!(
"bad unsafe intrinsics import: imported instance `{import}` must \
only export functions"
)
};
let func_ty = &types[*func_ty];
let func_ty = &types[func_ty];

fn ty_eq(a: &InterfaceType, b: &wasmparser::component_types::ComponentValType) -> bool {
use wasmparser::{PrimitiveValType as P, component_types::ComponentValType as C};
Expand Down
9 changes: 6 additions & 3 deletions crates/environ/src/component/translate/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,12 @@ pub(super) fn run(
if let TypeDef::Interface(_) = ty {
continue;
}
let index = inliner.result.import_types.push((name.0.to_string(), ty));
let index = inliner
.result
.import_types
.push((name.name.to_string(), ty));
let path = ImportPath::root(index);
args.insert(name.0, ComponentItemDef::from_import(path, ty)?);
args.insert(name.name, ComponentItemDef::from_import(path, ty)?);
}

// This will run the inliner to completion after being seeded with the
Expand Down Expand Up @@ -441,7 +444,7 @@ impl<'a> Inliner<'a> {
// was provided as an import at the instantiation-site to what was
// needed during the component's instantiation.
Import(name, ty) => {
let arg = match frame.args.get(name.0) {
let arg = match frame.args.get(name.name) {
Some(arg) => arg,

// Not all arguments need to be provided for instantiation,
Expand Down
12 changes: 6 additions & 6 deletions crates/environ/src/component/types_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,17 +325,17 @@ impl ComponentTypesBuilder {
let ty = &types[id];
let mut result = TypeComponent::default();
for (name, ty) in ty.imports.iter() {
self.register_abstract_component_entity_type(types, *ty);
self.register_abstract_component_entity_type(types, ty.ty);
result.imports.insert(
name.clone(),
self.convert_component_entity_type(types, *ty)?,
self.convert_component_entity_type(types, ty.ty)?,
);
}
for (name, ty) in ty.exports.iter() {
self.register_abstract_component_entity_type(types, *ty);
self.register_abstract_component_entity_type(types, ty.ty);
result.exports.insert(
name.clone(),
self.convert_component_entity_type(types, *ty)?,
self.convert_component_entity_type(types, ty.ty)?,
);
}
Ok(self.component_types.components.push(result))
Expand All @@ -350,10 +350,10 @@ impl ComponentTypesBuilder {
let ty = &types[id];
let mut result = TypeComponentInstance::default();
for (name, ty) in ty.exports.iter() {
self.register_abstract_component_entity_type(types, *ty);
self.register_abstract_component_entity_type(types, ty.ty);
result.exports.insert(
name.clone(),
self.convert_component_entity_type(types, *ty)?,
self.convert_component_entity_type(types, ty.ty)?,
);
}
Ok(self.component_types.component_instances.push(result))
Expand Down
2 changes: 1 addition & 1 deletion crates/environ/src/component/types_builder/resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ impl ResourcesBuilder {
let ty = &types[id];
for (name, ty) in ty.exports.iter() {
path.push(name);
self.register_component_entity_type_(types, *ty, path, register);
self.register_component_entity_type_(types, ty.ty, path, register);
path.pop();
}
}
Expand Down
15 changes: 15 additions & 0 deletions crates/test-util/src/component_fuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1722,6 +1722,21 @@ impl<'a> TestCase<'a> {

let mut options = u.arbitrary::<TestCaseOptions>()?;

// Handle async ABI options. If async is enabled then the function type
// in question must also be `async`.
if let LiftAbi::AsyncStackful | LiftAbi::AsyncCallback = options.caller_lift_abi {
options.guest_caller_async = true;
}
if let LiftAbi::AsyncStackful | LiftAbi::AsyncCallback = options.callee_lift_abi {
options.guest_callee_async = true;
}
if let LowerAbi::Async = options.caller_lower_abi {
options.guest_callee_async = true;
}
if let LowerAbi::Async = options.callee_lower_abi {
options.host_async = true;
}

// Sync tasks cannot call async functions via a sync lower, nor can they
// block in other ways (e.g. by calling `waitable-set.wait`, returning
// `CALLBACK_CODE_WAIT`, etc.) prior to returning. Therefore,
Expand Down
3 changes: 3 additions & 0 deletions crates/test-util/src/wast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,9 @@ impl WastTest {
// changes
"test/async/same-component-stream-future.wast",
"test/async/trap-if-block-and-sync.wast",
// Not updated upstream yet
"test/async/cross-abi-calls.wast",
"test/async/trap-on-reenter.wast",
];
if unsupported.iter().any(|part| self.path.ends_with(part)) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ impl<'a> CodeBuilder<'a> {
// unfortunately the `wasm-compose` API is not powerful
// enough for us to do all that.
ensure!(
imp.name.0 != intrinsics_import,
imp.name.name != intrinsics_import,
"main Wasm cannot import the unsafe intrinsics (`{intrinsics_import}`) \
when using compile-time builtins"
);

if let wasmparser::ComponentTypeRef::Instance(_) = imp.ty {
instance_imports.insert(imp.name.0);
instance_imports.insert(imp.name.name);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/wizer/src/component/rewrite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ impl ReencodeComponent for Reencoder<'_> {
) -> Result<(), Error> {
for export in section {
let export = export?;
if !self.wizer.get_keep_init_func() && export.name.0 == self.wizer.get_init_func() {
if !self.wizer.get_keep_init_func() && export.name.name == self.wizer.get_init_func() {
self.removed_func = Some(self.funcs);
} else {
if export.kind == wasmparser::ComponentExternalKind::Func {
Expand Down
2 changes: 1 addition & 1 deletion crates/wizer/tests/all/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ async fn export_is_removed() -> Result<()> {
wasmparser::Payload::ComponentExportSection(s) => Some(s),
_ => None,
})
.flat_map(|section| section.into_iter().map(|e| e.unwrap().name.0))
.flat_map(|section| section.into_iter().map(|e| e.unwrap().name.name))
.collect()
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/all/component_model/bindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ mod no_imports_concurrent {
(with "" (instance (export "task.return" (func $task-return))))
))

(func $f (export "bar")
(func $f (export "bar") async
(canon lift (core func $i "bar") async (callback (func $i "callback")))
)

Expand Down
4 changes: 2 additions & 2 deletions tests/all/component_model/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,7 @@ async fn test_many_parameters(dynamic: bool, concurrent: bool) -> Result<()> {
(with "libc" (instance $libc))
))

(type $t (func
(type $t (func async
(param "p1" s8) ;; offset 0, size 1
(param "p2" u64) ;; offset 8, size 8
(param "p3" float32) ;; offset 16, size 4
Expand Down Expand Up @@ -1379,7 +1379,7 @@ async fn test_many_results(dynamic: bool, concurrent: bool) -> Result<()> {
(with "libc" (instance $libc))
))

(type $t (func (result $tuple)))
(type $t (func async (result $tuple)))
(func (export "many-results") (type $t)
(canon lift
(core func $i "foo")
Expand Down
Loading
Loading