Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for the vectored IO #3680

Merged
merged 3 commits into from
Mar 15, 2023
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
12 changes: 4 additions & 8 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion lib/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ js-sys = "0.3.51"
#web-sys = { version = "0.3.51", features = [ "console" ] }
wasmer-derive = { path = "../derive", version = "=3.2.0-alpha.1" }
# - Optional dependencies for `js`.
wasmparser = { version = "0.95", default-features = false, optional = true }
wasmparser = { version = "0.83", default-features = false, optional = true }
hashbrown = { version = "0.11", optional = true }
serde-wasm-bindgen = { version = "0.4.5" }
serde = { version = "1.0", features = ["derive"] }
Expand Down
113 changes: 58 additions & 55 deletions lib/api/src/js/module_info_polyfill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ use wasmer_types::{
};

use wasmparser::{
self, BinaryReaderError, Export, ExportSectionReader, ExternalKind, FunctionSectionReader,
GlobalSectionReader, GlobalType as WPGlobalType, ImportSectionReader, MemorySectionReader,
MemoryType as WPMemoryType, NameSectionReader, Parser, Payload, TableSectionReader, TypeRef,
TypeSectionReader,
self, BinaryReaderError, Export, ExportSectionReader, ExternalKind, FuncType as WPFunctionType,
FunctionSectionReader, GlobalSectionReader, GlobalType as WPGlobalType, ImportSectionEntryType,
ImportSectionReader, MemorySectionReader, MemoryType as WPMemoryType, NameSectionReader,
Parser, Payload, TableSectionReader, TypeDef, TypeSectionReader,
};

pub type WasmResult<T> = Result<T, String>;
Expand Down Expand Up @@ -283,17 +283,15 @@ pub fn translate_module<'data>(data: &'data [u8]) -> WasmResult<ModuleInfoPolyfi
parse_export_section(exports, &mut module_info)?;
}

Payload::CustomSection(sectionreader) => {
// We still add the custom section data, but also read it as name section reader
let name = sectionreader.name();
if name == "name" {
parse_name_section(
NameSectionReader::new(sectionreader.data(), sectionreader.data_offset())
.map_err(transform_err)?,
&mut module_info,
)?;
}
}
Payload::CustomSection {
name: "name",
data,
data_offset,
..
} => parse_name_section(
NameSectionReader::new(data, data_offset).map_err(transform_err)?,
&mut module_info,
)?,

_ => {}
}
Expand All @@ -303,15 +301,16 @@ pub fn translate_module<'data>(data: &'data [u8]) -> WasmResult<ModuleInfoPolyfi
}

/// Helper function translating wasmparser types to Wasm Type.
pub fn wptype_to_type(ty: wasmparser::ValType) -> WasmResult<Type> {
pub fn wptype_to_type(ty: wasmparser::Type) -> WasmResult<Type> {
match ty {
wasmparser::ValType::I32 => Ok(Type::I32),
wasmparser::ValType::I64 => Ok(Type::I64),
wasmparser::ValType::F32 => Ok(Type::F32),
wasmparser::ValType::F64 => Ok(Type::F64),
wasmparser::ValType::V128 => Ok(Type::V128),
wasmparser::ValType::ExternRef => Ok(Type::ExternRef),
wasmparser::ValType::FuncRef => Ok(Type::FuncRef),
wasmparser::Type::I32 => Ok(Type::I32),
wasmparser::Type::I64 => Ok(Type::I64),
wasmparser::Type::F32 => Ok(Type::F32),
wasmparser::Type::F64 => Ok(Type::F64),
wasmparser::Type::V128 => Ok(Type::V128),
wasmparser::Type::ExternRef => Ok(Type::ExternRef),
wasmparser::Type::FuncRef => Ok(Type::FuncRef),
ty => Err(format!("wptype_to_type: wasmparser type {:?}", ty)),
}
}

Expand All @@ -324,9 +323,7 @@ pub fn parse_type_section(
module_info.reserve_signatures(count)?;

for entry in types {
if let Ok(wasmparser::Type::Func(functype)) = entry {
let params = functype.params();
let returns = functype.results();
if let Ok(TypeDef::Func(WPFunctionType { params, returns })) = entry {
let sig_params: Vec<Type> = params
.iter()
.map(|ty| {
Expand Down Expand Up @@ -361,20 +358,23 @@ pub fn parse_import_section<'data>(
for entry in imports {
let import = entry.map_err(transform_err)?;
let module_name = import.module;
let field_name = import.name;
let field_name = import.field;

match import.ty {
TypeRef::Func(sig) => {
ImportSectionEntryType::Function(sig) => {
module_info.declare_func_import(
SignatureIndex::from_u32(sig),
module_name,
field_name,
field_name.unwrap_or_default(),
)?;
}
TypeRef::Tag(_) => {
ImportSectionEntryType::Module(_) | ImportSectionEntryType::Instance(_) => {
unimplemented!("module linking not implemented yet")
}
ImportSectionEntryType::Tag(_) => {
unimplemented!("exception handling not implemented yet")
}
TypeRef::Memory(WPMemoryType {
ImportSectionEntryType::Memory(WPMemoryType {
shared,
memory64,
initial,
Expand All @@ -390,28 +390,28 @@ pub fn parse_import_section<'data>(
shared,
},
module_name,
field_name,
field_name.unwrap_or_default(),
)?;
}
TypeRef::Global(ref ty) => {
ImportSectionEntryType::Global(ref ty) => {
module_info.declare_global_import(
GlobalType {
ty: wptype_to_type(ty.content_type).unwrap(),
mutability: ty.mutable.into(),
},
module_name,
field_name,
field_name.unwrap_or_default(),
)?;
}
TypeRef::Table(ref tab) => {
ImportSectionEntryType::Table(ref tab) => {
module_info.declare_table_import(
TableType {
ty: wptype_to_type(tab.element_type).unwrap(),
minimum: tab.initial,
maximum: tab.maximum,
},
module_name,
field_name,
field_name.unwrap_or_default(),
)?;
}
}
Expand Down Expand Up @@ -512,7 +512,7 @@ pub fn parse_export_section<'data>(

for entry in exports {
let Export {
name,
field,
ref kind,
index,
} = entry.map_err(transform_err)?;
Expand All @@ -522,17 +522,20 @@ pub fn parse_export_section<'data>(
// becomes a concern here.
let index = index as usize;
match *kind {
ExternalKind::Func => {
module_info.declare_func_export(FunctionIndex::new(index), name)?
ExternalKind::Function => {
module_info.declare_func_export(FunctionIndex::new(index), field)?
}
ExternalKind::Table => {
module_info.declare_table_export(TableIndex::new(index), name)?
module_info.declare_table_export(TableIndex::new(index), field)?
}
ExternalKind::Memory => {
module_info.declare_memory_export(MemoryIndex::new(index), name)?
module_info.declare_memory_export(MemoryIndex::new(index), field)?
}
ExternalKind::Global => {
module_info.declare_global_export(GlobalIndex::new(index), name)?
module_info.declare_global_export(GlobalIndex::new(index), field)?
}
ExternalKind::Type | ExternalKind::Module | ExternalKind::Instance => {
unimplemented!("module linking not implemented yet")
}
ExternalKind::Tag => {
unimplemented!("exception handling not implemented yet")
Expand All @@ -556,20 +559,20 @@ pub fn parse_name_section<'data>(
while let Ok(subsection) = names.read() {
match subsection {
wasmparser::Name::Function(_function_subsection) => {
//for naming in function_subsection.into_iter().flatten() {
// if naming.index != std::u32::MAX {
// environ.declare_function_name(
// FunctionIndex::from_u32(naming.index),
// naming.name,
// )?;
// }
//}
// if let Some(function_names) = function_subsection
// .get_map()
// .ok()
// .and_then(parse_function_name_subsection)
// {
// for (index, name) in function_names {
// module_info.declare_function_name(index, name)?;
// }
// }
}
wasmparser::Name::Module {
name,
name_range: _,
} => {
module_info.declare_module_name(name)?;
wasmparser::Name::Module(module) => {
if let Ok(name) = module.get_name() {
module_info.declare_module_name(name)?;
}
}
wasmparser::Name::Local(_) => {}
wasmparser::Name::Label(_)
Expand Down
28 changes: 10 additions & 18 deletions lib/c-api/src/wasm_c_api/unstable/parser/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,10 +533,6 @@ pub enum wasmer_parser_operator_t {
F32x4RelaxedMax,
F64x2RelaxedMin,
F64x2RelaxedMax,
I16x8RelaxedQ15mulrS,
I16x8DotI8x16I7x16S,
I32x4DotI8x16I7x16AddS,
F32x4RelaxedDotBf16x8AddF32x4,
}

impl<'a> From<&Operator<'a>> for wasmer_parser_operator_t {
Expand Down Expand Up @@ -1048,8 +1044,8 @@ impl<'a> From<&Operator<'a>> for wasmer_parser_operator_t {
O::V128Store16Lane { .. } => Self::V128Store16Lane,
O::V128Store32Lane { .. } => Self::V128Store32Lane,
O::V128Store64Lane { .. } => Self::V128Store64Lane,
O::I8x16AvgrU => Self::I8x16RoundingAverageU,
O::I16x8AvgrU => Self::I16x8RoundingAverageU,
O::I8x16RoundingAverageU => Self::I8x16RoundingAverageU,
O::I16x8RoundingAverageU => Self::I16x8RoundingAverageU,
O::I16x8Q15MulrSatS => Self::I16x8Q15MulrSatS,
O::F32x4DemoteF64x2Zero => Self::F32x4DemoteF64x2Zero,
O::F64x2PromoteLowF32x4 => Self::F64x2PromoteLowF32x4,
Expand All @@ -1062,22 +1058,18 @@ impl<'a> From<&Operator<'a>> for wasmer_parser_operator_t {
O::I32x4RelaxedTruncSatF32x4U => Self::I32x4RelaxedTruncSatF32x4U,
O::I32x4RelaxedTruncSatF64x2SZero => Self::I32x4RelaxedTruncSatF64x2SZero,
O::I32x4RelaxedTruncSatF64x2UZero => Self::I32x4RelaxedTruncSatF64x2UZero,
O::F32x4RelaxedFma => Self::F32x4Fma,
O::F32x4RelaxedFnma => Self::F32x4Fms,
O::F64x2RelaxedFma => Self::F64x2Fma,
O::F64x2RelaxedFnma => Self::F64x2Fms,
O::I8x16RelaxedLaneselect => Self::I8x16LaneSelect,
O::I16x8RelaxedLaneselect => Self::I16x8LaneSelect,
O::I32x4RelaxedLaneselect => Self::I32x4LaneSelect,
O::I64x2RelaxedLaneselect => Self::I64x2LaneSelect,
O::F32x4Fma => Self::F32x4Fma,
O::F32x4Fms => Self::F32x4Fms,
O::F64x2Fma => Self::F64x2Fma,
O::F64x2Fms => Self::F64x2Fms,
O::I8x16LaneSelect => Self::I8x16LaneSelect,
O::I16x8LaneSelect => Self::I16x8LaneSelect,
O::I32x4LaneSelect => Self::I32x4LaneSelect,
O::I64x2LaneSelect => Self::I64x2LaneSelect,
O::F32x4RelaxedMin => Self::F32x4RelaxedMin,
O::F32x4RelaxedMax => Self::F32x4RelaxedMax,
O::F64x2RelaxedMin => Self::F64x2RelaxedMin,
O::F64x2RelaxedMax => Self::F64x2RelaxedMax,
O::I16x8RelaxedQ15mulrS => Self::I16x8RelaxedQ15mulrS,
O::I16x8DotI8x16I7x16S => Self::I16x8DotI8x16I7x16S,
O::I32x4DotI8x16I7x16AddS => Self::I32x4DotI8x16I7x16AddS,
O::F32x4RelaxedDotBf16x8AddF32x4 => Self::F32x4RelaxedDotBf16x8AddF32x4,
}
}
}
4 changes: 2 additions & 2 deletions lib/compiler-cranelift/src/address_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

use cranelift_codegen::Context;
use cranelift_codegen::MachSrcLoc;
use std::ops::Range;
use wasmer_compiler::wasmparser::Range;
use wasmer_types::{FunctionAddressMap, InstructionAddressMap, SourceLoc};

pub fn get_function_address_map(
context: &Context,
range: Range<usize>,
range: Range,
body_len: usize,
) -> FunctionAddressMap {
let mut instructions = Vec::new();
Expand Down
8 changes: 4 additions & 4 deletions lib/compiler-cranelift/src/func_environ.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use cranelift_codegen::ir::{AbiParam, ArgumentPurpose, Function, InstBuilder, Si
use cranelift_codegen::isa::TargetFrontendConfig;
use cranelift_frontend::FunctionBuilder;
use std::convert::TryFrom;
use wasmer_compiler::wasmparser::ValType;
use wasmer_compiler::wasmparser::Type;
use wasmer_types::entity::EntityRef;
use wasmer_types::entity::PrimaryMap;
use wasmer_types::VMBuiltinFunctionIndex;
Expand Down Expand Up @@ -999,11 +999,11 @@ impl<'module_environment> BaseFuncEnvironment for FuncEnvironment<'module_enviro
fn translate_ref_null(
&mut self,
mut pos: cranelift_codegen::cursor::FuncCursor,
ty: ValType,
ty: Type,
) -> WasmResult<ir::Value> {
Ok(match ty {
ValType::FuncRef => pos.ins().null(self.reference_type()),
ValType::ExternRef => pos.ins().null(self.reference_type()),
Type::FuncRef => pos.ins().null(self.reference_type()),
Type::ExternRef => pos.ins().null(self.reference_type()),
_ => {
return Err(WasmError::Unsupported(
"`ref.null T` that is not a `funcref` or an `externref`".into(),
Expand Down
Loading