Update wasm-tools crates (#3997)

* Update wasm-tools crates

This commit updates the wasm-tools family of crates as used in Wasmtime.
Notably this brings in the update which removes module linking support
as well as a number of internal refactorings around names and such
within wasmparser itself. This updates all of the wasm translation
support which binds to wasmparser as appropriate.

Other crates all had API-compatible changes for at least what Wasmtime
used so no further changes were necessary beyond updating version
requirements.

* Update a test expectation
This commit is contained in:
Alex Crichton
2022-04-05 14:32:33 -05:00
committed by GitHub
parent 7ac2598009
commit d147802d51
26 changed files with 178 additions and 299 deletions

View File

@@ -24,7 +24,7 @@ wasmtime = { path = "../wasmtime", default-features = false, features = ['cranel
wasmtime-c-api-macros = { path = "macros" }
# Optional dependency for the `wat2wasm` API
wat = { version = "1.0.36", optional = true }
wat = { version = "1.0.42", optional = true }
# Optional dependencies for the `wasi` feature
wasi-cap-std-sync = { path = "../wasi-common/cap-std-sync", optional = true }

View File

@@ -19,7 +19,7 @@ cranelift-codegen = { path = "../../cranelift/codegen", version = "0.84.0" }
cranelift-frontend = { path = "../../cranelift/frontend", version = "0.84.0" }
cranelift-entity = { path = "../../cranelift/entity", version = "0.84.0" }
cranelift-native = { path = "../../cranelift/native", version = "0.84.0" }
wasmparser = "0.83.0"
wasmparser = "0.84.0"
target-lexicon = "0.12"
gimli = { version = "0.26.0", default-features = false, features = ['read', 'std'] }
object = { version = "0.27.0", default-features = false, features = ['write'] }

View File

@@ -184,7 +184,6 @@ fn value_type(isa: &dyn TargetIsa, ty: WasmType) -> ir::types::Type {
WasmType::F64 => ir::types::F64,
WasmType::V128 => ir::types::I8X16,
WasmType::FuncRef | WasmType::ExternRef => reference_type(ty, isa.pointer_type()),
WasmType::ExnRef => unimplemented!(),
}
}

View File

@@ -14,7 +14,7 @@ edition = "2021"
anyhow = "1.0"
cranelift-entity = { path = "../../cranelift/entity", version = "0.84.0" }
wasmtime-types = { path = "../types", version = "0.37.0" }
wasmparser = "0.83.0"
wasmparser = "0.84.0"
indexmap = { version = "1.0.2", features = ["serde-1"] }
thiserror = "1.0.4"
serde = { version = "1.0.94", features = ["derive"] }

View File

@@ -16,8 +16,8 @@ use std::sync::Arc;
use wasmparser::Type as WasmType;
use wasmparser::{
DataKind, ElementItem, ElementKind, ExternalKind, FuncValidator, FunctionBody,
ImportSectionEntryType, NameSectionReader, Naming, Operator, Parser, Payload, TypeDef,
Validator, ValidatorResources, WasmFeatures,
NameSectionReader, Naming, Operator, Parser, Payload, TypeDef, TypeRef, Validator,
ValidatorResources, WasmFeatures,
};
/// Object containing the standalone environment information.
@@ -169,8 +169,7 @@ impl<'data> ModuleEnvironment<'data> {
mut self,
data: &'data [u8],
) -> WasmResult<(ModuleTranslation<'data>, TypeTables)> {
let mut validator = Validator::new();
validator.wasm_features(self.features);
let mut validator = Validator::new_with_features(self.features);
for payload in Parser::new(0).parse_all(data) {
self.translate_payload(&mut validator, payload?)?;
@@ -185,12 +184,16 @@ impl<'data> ModuleEnvironment<'data> {
payload: Payload<'data>,
) -> WasmResult<()> {
match payload {
Payload::Version { num, range } => {
validator.version(num, &range)?;
Payload::Version {
num,
encoding,
range,
} => {
validator.version(num, encoding, &range)?;
}
Payload::End => {
validator.end()?;
Payload::End(offset) => {
validator.end(offset)?;
// With the `escaped_funcs` set of functions finished
// we can calculate the set of signatures that are exported as
@@ -223,11 +226,6 @@ impl<'data> ModuleEnvironment<'data> {
TypeDef::Func(wasm_func_ty) => {
self.declare_type_func(wasm_func_ty.try_into()?)?;
}
// doesn't get past validation
TypeDef::Module(_) | TypeDef::Instance(_) => {
unreachable!();
}
}
}
}
@@ -241,35 +239,33 @@ impl<'data> ModuleEnvironment<'data> {
for entry in imports {
let import = entry?;
let ty = match import.ty {
ImportSectionEntryType::Function(index) => {
TypeRef::Func(index) => {
let index = TypeIndex::from_u32(index);
let sig_index = self.result.module.types[index].unwrap_function();
self.result.module.num_imported_funcs += 1;
self.result.debuginfo.wasm_file.imported_func_count += 1;
EntityType::Function(sig_index)
}
ImportSectionEntryType::Memory(ty) => {
TypeRef::Memory(ty) => {
if ty.shared {
return Err(WasmError::Unsupported("shared memories".to_owned()));
}
self.result.module.num_imported_memories += 1;
EntityType::Memory(ty.into())
}
ImportSectionEntryType::Global(ty) => {
TypeRef::Global(ty) => {
self.result.module.num_imported_globals += 1;
EntityType::Global(Global::new(ty, GlobalInit::Import)?)
}
ImportSectionEntryType::Table(ty) => {
TypeRef::Table(ty) => {
self.result.module.num_imported_tables += 1;
EntityType::Table(ty.try_into()?)
}
// doesn't get past validation
ImportSectionEntryType::Module(_)
| ImportSectionEntryType::Instance(_)
| ImportSectionEntryType::Tag(_) => unreachable!(),
TypeRef::Tag(_) => unreachable!(),
};
self.declare_import(import.module, import.field.unwrap(), ty);
self.declare_import(import.module, import.name, ty);
}
}
@@ -368,9 +364,9 @@ impl<'data> ModuleEnvironment<'data> {
self.result.module.exports.reserve(cnt);
for entry in exports {
let wasmparser::Export { field, kind, index } = entry?;
let wasmparser::Export { name, kind, index } = entry?;
let entity = match kind {
ExternalKind::Function => {
ExternalKind::Func => {
let index = FuncIndex::from_u32(index);
self.flag_func_escaped(index);
EntityIndex::Function(index)
@@ -380,15 +376,12 @@ impl<'data> ModuleEnvironment<'data> {
ExternalKind::Global => EntityIndex::Global(GlobalIndex::from_u32(index)),
// this never gets past validation
ExternalKind::Module
| ExternalKind::Instance
| ExternalKind::Tag
| ExternalKind::Type => unreachable!(),
ExternalKind::Tag => unreachable!(),
};
self.result
.module
.exports
.insert(String::from(field), entity);
.insert(String::from(name), entity);
}
}
@@ -502,7 +495,7 @@ impl<'data> ModuleEnvironment<'data> {
}
Payload::CodeSectionEntry(mut body) => {
let validator = validator.code_section_entry()?;
let validator = validator.code_section_entry(&body)?;
let func_index =
self.result.code_index + self.result.module.num_imported_funcs as u32;
let func_index = FuncIndex::from_u32(func_index);
@@ -617,30 +610,6 @@ impl<'data> ModuleEnvironment<'data> {
// the passive count, do not reserve anything here.
}
Payload::AliasSection(s) => {
validator.alias_section(&s)?;
unreachable!() // should never get past validation
}
Payload::InstanceSection(s) => {
validator.instance_section(&s)?;
unreachable!() // should never get past validation
}
Payload::ModuleSectionStart {
count,
range,
size: _,
} => {
validator.module_section_start(count, &range)?;
unreachable!() // should never get past validation
}
Payload::ModuleSectionEntry { .. } => {
validator.module_section_entry();
unreachable!() // should never get past validation
}
Payload::CustomSection {
name: "name",
data,
@@ -683,9 +652,13 @@ and for re-adding support for interface types you can see this issue:
self.register_dwarf_section(name, data);
}
Payload::UnknownSection { id, range, .. } => {
validator.unknown_section(id, &range)?;
unreachable!();
// It's expected that validation will probably reject other
// payloads such as `UnknownSection` or those related to the
// component model. If, however, something gets past validation then
// that's a bug in Wasmtime as we forgot to implement something.
other => {
validator.payload(&other)?;
panic!("unimplemented section in wasm file {:?}", other);
}
}
Ok(())

View File

@@ -15,13 +15,13 @@ log = "0.4.8"
rayon = "1.2.1"
target-lexicon = "0.12.3"
tempfile = "3.3.0"
wasmparser = "0.83.0"
wasmprinter = "0.2.32"
wasmparser = "0.84.0"
wasmprinter = "0.2.34"
wasmtime = { path = "../wasmtime" }
wasmtime-wast = { path = "../wast" }
wasm-encoder = "0.10.0"
wasm-smith = "0.9.0"
wasm-mutate = "0.2"
wasm-encoder = "0.11.0"
wasm-smith = "0.10.0"
wasm-mutate = "0.2.2"
wasm-spec-interpreter = { path = "./wasm-spec-interpreter", optional = true }
wasmi = "0.7.0"

View File

@@ -95,9 +95,9 @@ impl TableOps {
// Import the GC function.
let mut imports = ImportSection::new();
imports.import("", Some("gc"), EntityType::Function(0));
imports.import("", Some("take_refs"), EntityType::Function(2));
imports.import("", Some("make_refs"), EntityType::Function(3));
imports.import("", "gc", EntityType::Function(0));
imports.import("", "take_refs", EntityType::Function(2));
imports.import("", "make_refs", EntityType::Function(3));
// Define our table.
let mut tables = TableSection::new();
@@ -422,10 +422,12 @@ mod tests {
global.get 0
call 1
br 0 (;@1;)
end)
end
)
(table (;0;) 20 externref)
(global (;0;) (mut externref) ref.null extern)
(export "run" (func 3)))
(export "run" (func 3))
)
"#;
eprintln!("expected WAT = {}", expected);

View File

@@ -20,7 +20,7 @@ pretty_env_logger = "0.4.0"
tempfile = "3.1.0"
os_pipe = "0.9"
anyhow = "1.0.19"
wat = "1.0.37"
wat = "1.0.42"
cap-std = "0.24.1"
tokio = { version = "1.8.0", features = ["rt-multi-thread"] }

View File

@@ -12,4 +12,4 @@ edition = "2021"
cranelift-entity = { path = "../../cranelift/entity", version = "0.84.0", features = ['enable-serde'] }
serde = { version = "1.0.94", features = ["derive"] }
thiserror = "1.0.4"
wasmparser = { version = "0.83.0", default-features = false }
wasmparser = { version = "0.84.0", default-features = false }

View File

@@ -29,8 +29,6 @@ pub enum WasmType {
FuncRef,
/// ExternRef type
ExternRef,
/// ExnRef type
ExnRef,
}
impl TryFrom<wasmparser::Type> for WasmType {
@@ -45,11 +43,6 @@ impl TryFrom<wasmparser::Type> for WasmType {
V128 => Ok(WasmType::V128),
FuncRef => Ok(WasmType::FuncRef),
ExternRef => Ok(WasmType::ExternRef),
ExnRef => Ok(WasmType::ExnRef),
EmptyBlockType | Func => Err(WasmError::InvalidWebAssembly {
message: "unexpected value type".to_string(),
offset: 0,
}),
}
}
}
@@ -64,7 +57,6 @@ impl From<WasmType> for wasmparser::Type {
WasmType::V128 => wasmparser::Type::V128,
WasmType::FuncRef => wasmparser::Type::FuncRef,
WasmType::ExternRef => wasmparser::Type::ExternRef,
WasmType::ExnRef => wasmparser::Type::ExnRef,
}
}
}
@@ -79,7 +71,6 @@ impl fmt::Display for WasmType {
WasmType::V128 => write!(f, "v128"),
WasmType::ExternRef => write!(f, "externref"),
WasmType::FuncRef => write!(f, "funcref"),
WasmType::ExnRef => write!(f, "exnref"),
}
}
}
@@ -356,8 +347,10 @@ pub struct Tag {
impl From<wasmparser::TagType> for Tag {
fn from(ty: wasmparser::TagType) -> Tag {
Tag {
ty: TypeIndex::from_u32(ty.type_index),
match ty.kind {
wasmparser::TagKind::Exception => Tag {
ty: TypeIndex::from_u32(ty.func_type_idx),
},
}
}
}

View File

@@ -20,14 +20,14 @@ wasmtime-cache = { path = "../cache", version = "=0.37.0", optional = true }
wasmtime-fiber = { path = "../fiber", version = "=0.37.0", optional = true }
wasmtime-cranelift = { path = "../cranelift", version = "=0.37.0", optional = true }
target-lexicon = { version = "0.12.0", default-features = false }
wasmparser = "0.83.0"
wasmparser = "0.84.0"
anyhow = "1.0.19"
region = "2.2.0"
libc = "0.2"
cfg-if = "1.0"
backtrace = { version = "0.3.61", optional = true }
log = "0.4.8"
wat = { version = "1.0.36", optional = true }
wat = { version = "1.0.42", optional = true }
serde = { version = "1.0.94", features = ["derive"] }
bincode = "1.2.1"
indexmap = "1.6"

View File

@@ -542,8 +542,7 @@ impl Module {
///
/// [binary]: https://webassembly.github.io/spec/core/binary/index.html
pub fn validate(engine: &Engine, binary: &[u8]) -> Result<()> {
let mut validator = Validator::new();
validator.wasm_features(engine.config().features);
let mut validator = Validator::new_with_features(engine.config().features);
let mut functions = Vec::new();
for payload in Parser::new(0).parse_all(binary) {

View File

@@ -60,7 +60,7 @@ struct WasmFeatures {
pub reference_types: bool,
pub multi_value: bool,
pub bulk_memory: bool,
pub module_linking: bool,
pub component_model: bool,
pub simd: bool,
pub threads: bool,
pub tail_call: bool,
@@ -78,7 +78,7 @@ impl From<&wasmparser::WasmFeatures> for WasmFeatures {
reference_types,
multi_value,
bulk_memory,
module_linking,
component_model,
simd,
threads,
tail_call,
@@ -99,7 +99,7 @@ impl From<&wasmparser::WasmFeatures> for WasmFeatures {
reference_types,
multi_value,
bulk_memory,
module_linking,
component_model,
simd,
threads,
tail_call,
@@ -479,7 +479,7 @@ impl<'a> SerializedModule<'a> {
reference_types,
multi_value,
bulk_memory,
module_linking,
component_model,
simd,
threads,
tail_call,
@@ -507,9 +507,9 @@ impl<'a> SerializedModule<'a> {
"WebAssembly bulk memory support",
)?;
Self::check_bool(
module_linking,
other.module_linking,
"WebAssembly module linking support",
component_model,
other.component_model,
"WebAssembly component model support",
)?;
Self::check_bool(simd, other.simd, "WebAssembly SIMD support")?;
Self::check_bool(threads, other.threads, "WebAssembly threads support")?;

View File

@@ -92,7 +92,6 @@ impl ValType {
WasmType::V128 => Self::V128,
WasmType::FuncRef => Self::FuncRef,
WasmType::ExternRef => Self::ExternRef,
WasmType::ExnRef => unimplemented!(),
}
}
}

View File

@@ -12,7 +12,7 @@ edition = "2021"
[dependencies]
anyhow = "1.0.19"
wasmtime = { path = "../wasmtime", version = "0.37.0", default-features = false, features = ['cranelift'] }
wast = "39.0.0"
wast = "40.0.0"
[badges]
maintenance = { status = "actively-developed" }