Skip to content

Commit

Permalink
Merge pull request #976 from fitzgen/implement-most-of-bulk-memory
Browse files Browse the repository at this point in the history
Implement most of bulk memory
  • Loading branch information
fitzgen authored Feb 26, 2020
2 parents 8568732 + 66634cc commit 76e08d6
Show file tree
Hide file tree
Showing 32 changed files with 1,725 additions and 156 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ anyhow = "1.0.19"
target-lexicon = { version = "0.10.0", default-features = false }
pretty_env_logger = "0.3.0"
file-per-thread-logger = "0.1.1"
wat = "1.0.2"
wat = "1.0.10"
libc = "0.2.60"
rayon = "1.2.1"
wasm-webidl-bindings = "0.8"
Expand Down
103 changes: 61 additions & 42 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,40 +26,38 @@ fn main() -> anyhow::Result<()> {
writeln!(out, "#[allow(non_snake_case)]")?;
writeln!(out, "mod {} {{", strategy)?;

test_directory(&mut out, "tests/misc_testsuite", strategy)?;
let spec_tests = test_directory(&mut out, "tests/spec_testsuite", strategy)?;
// Skip running spec_testsuite tests if the submodule isn't checked
// out.
if spec_tests > 0 {
test_directory(&mut out, "tests/spec_testsuite/proposals/simd", strategy)
.expect("generating tests");

test_directory(
&mut out,
"tests/spec_testsuite/proposals/multi-value",
strategy,
)
.expect("generating tests");

test_directory(
&mut out,
"tests/spec_testsuite/proposals/reference-types",
strategy,
)
.expect("generating tests");

test_directory(
&mut out,
"tests/spec_testsuite/proposals/bulk-memory-operations",
strategy,
)
.expect("generating tests");
} else {
println!(
"cargo:warning=The spec testsuite is disabled. To enable, run `git submodule \
with_test_module(&mut out, "misc", |out| {
test_directory(out, "tests/misc_testsuite", strategy)?;
test_directory_module(out, "tests/misc_testsuite/bulk-memory-operations", strategy)?;
test_directory_module(out, "tests/misc_testsuite/reference-types", strategy)?;
Ok(())
})?;

with_test_module(&mut out, "spec", |out| {
let spec_tests = test_directory(out, "tests/spec_testsuite", strategy)?;
// Skip running spec_testsuite tests if the submodule isn't checked
// out.
if spec_tests > 0 {
test_directory_module(out, "tests/spec_testsuite/proposals/simd", strategy)?;
test_directory_module(out, "tests/spec_testsuite/proposals/multi-value", strategy)?;
test_directory_module(
out,
"tests/spec_testsuite/proposals/reference-types",
strategy,
)?;
test_directory_module(
out,
"tests/spec_testsuite/proposals/bulk-memory-operations",
strategy,
)?;
} else {
println!(
"cargo:warning=The spec testsuite is disabled. To enable, run `git submodule \
update --remote`."
);
}
);
}
Ok(())
})?;

writeln!(out, "}}")?;
}
Expand All @@ -72,6 +70,16 @@ fn main() -> anyhow::Result<()> {
Ok(())
}

fn test_directory_module(
out: &mut String,
path: impl AsRef<Path>,
strategy: &str,
) -> anyhow::Result<usize> {
let path = path.as_ref();
let testsuite = &extract_name(path);
with_test_module(out, testsuite, |out| test_directory(out, path, strategy))
}

fn test_directory(
out: &mut String,
path: impl AsRef<Path>,
Expand Down Expand Up @@ -100,11 +108,10 @@ fn test_directory(
dir_entries.sort();

let testsuite = &extract_name(path);
start_test_module(out, testsuite)?;
for entry in dir_entries.iter() {
write_testsuite_tests(out, entry, testsuite, strategy)?;
}
finish_test_module(out)?;

Ok(dir_entries.len())
}

Expand All @@ -119,14 +126,19 @@ fn extract_name(path: impl AsRef<Path>) -> String {
.replace("/", "_")
}

fn start_test_module(out: &mut String, testsuite: &str) -> anyhow::Result<()> {
writeln!(out, "mod {} {{", testsuite)?;
Ok(())
}
fn with_test_module<T>(
out: &mut String,
testsuite: &str,
f: impl FnOnce(&mut String) -> anyhow::Result<T>,
) -> anyhow::Result<T> {
out.push_str("mod ");
out.push_str(testsuite);
out.push_str(" {\n");

let result = f(out)?;

fn finish_test_module(out: &mut String) -> anyhow::Result<()> {
out.push_str("}\n");
Ok(())
Ok(result)
}

fn write_testsuite_tests(
Expand Down Expand Up @@ -180,8 +192,15 @@ fn ignore(testsuite: &str, testname: &str, strategy: &str) -> bool {
("simd", "simd_load_splat") => return true, // FIXME Unsupported feature: proposed SIMD operator V8x16LoadSplat { memarg: MemoryImmediate { flags: 0, offset: 0 } }
("simd", "simd_splat") => return true, // FIXME Unsupported feature: proposed SIMD operator I8x16ShrS

// Still working on implementing these. See #929.
("reference_types", "table_copy_on_imported_tables") => return false,
("reference_types", _) => return true,
("bulk_memory_operations", _) => return true,

// Still working on implementing these. See #928
("bulk_memory_operations", "bulk")
| ("bulk_memory_operations", "data")
| ("bulk_memory_operations", "memory_init")
| ("bulk_memory_operations", "imports") => return true,

_ => {}
},
Expand Down
2 changes: 1 addition & 1 deletion crates/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ wasi-common = { path = "../wasi-common", version = "0.12.0" }
pretty_env_logger = "0.3.0"
rayon = "1.2.1"
file-per-thread-logger = "0.1.1"
wat = "1.0"
wat = "1.0.10"
tempfile = "3.1"

[badges]
Expand Down
39 changes: 37 additions & 2 deletions crates/api/src/externals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use crate::{ExternType, GlobalType, MemoryType, TableType, ValType};
use crate::{Func, Store};
use anyhow::{anyhow, bail, Result};
use std::slice;
use wasmtime_environ::wasm;
use wasmtime_runtime::InstanceHandle;
use wasmtime_environ::{ir, wasm};
use wasmtime_runtime::{self as runtime, InstanceHandle};

// Externals

Expand Down Expand Up @@ -407,6 +407,41 @@ impl Table {
}
}

/// Copy `len` elements from `src_table[src_index..]` into
/// `dst_table[dst_index..]`.
///
/// # Errors
///
/// Returns an error if the range is out of bounds of either the source or
/// destination tables.
pub fn copy(
dst_table: &Table,
dst_index: u32,
src_table: &Table,
src_index: u32,
len: u32,
) -> Result<()> {
// NB: We must use the `dst_table`'s `wasmtime_handle` for the
// `dst_table_index` and vice versa for `src_table` since each table can
// come from different modules.

let dst_table_index = dst_table.wasmtime_table_index();
let dst_table = dst_table.wasmtime_handle.get_defined_table(dst_table_index);

let src_table_index = src_table.wasmtime_table_index();
let src_table = src_table.wasmtime_handle.get_defined_table(src_table_index);

runtime::Table::copy(
dst_table,
src_table,
dst_index,
src_index,
len,
ir::SourceLoc::default(),
)?;
Ok(())
}

pub(crate) fn wasmtime_export(&self) -> &wasmtime_runtime::Export {
&self.wasmtime_export
}
Expand Down
15 changes: 11 additions & 4 deletions crates/api/src/instance.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::externals::Extern;
use crate::module::Module;
use crate::runtime::Store;
use crate::runtime::{Config, Store};
use crate::trap::Trap;
use anyhow::{Error, Result};
use wasmtime_jit::{CompiledModule, Resolver};
Expand All @@ -19,16 +19,22 @@ impl Resolver for SimpleResolver<'_> {
}

fn instantiate(
config: &Config,
compiled_module: &CompiledModule,
imports: &[Extern],
) -> Result<InstanceHandle, Error> {
let mut resolver = SimpleResolver { imports };
unsafe {
let instance = compiled_module
.instantiate(&mut resolver)
.instantiate(
config.validating_config.operator_config.enable_bulk_memory,
&mut resolver,
)
.map_err(|e| -> Error {
match e {
InstantiationError::StartTrap(trap) => Trap::from_jit(trap).into(),
InstantiationError::StartTrap(trap) | InstantiationError::Trap(trap) => {
Trap::from_jit(trap).into()
}
other => other.into(),
}
})?;
Expand Down Expand Up @@ -105,7 +111,8 @@ impl Instance {
/// [issue]: https://github.com/bytecodealliance/wasmtime/issues/727
pub fn new(module: &Module, imports: &[Extern]) -> Result<Instance, Error> {
let store = module.store();
let instance_handle = instantiate(module.compiled_module(), imports)?;
let config = store.engine().config();
let instance_handle = instantiate(config, module.compiled_module(), imports)?;

let exports = {
let mut exports = Vec::with_capacity(module.exports().len());
Expand Down
6 changes: 6 additions & 0 deletions crates/api/src/trampoline/create_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ pub(crate) fn create_handle(
&data_initializers,
signatures.into_boxed_slice(),
None,
store
.engine()
.config()
.validating_config
.operator_config
.enable_bulk_memory,
state,
)?)
}
Expand Down
4 changes: 2 additions & 2 deletions crates/environ/src/data_structures.rs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ pub mod isa {
}

pub mod entity {
pub use cranelift_entity::{BoxedSlice, EntityRef, PrimaryMap};
pub use cranelift_entity::{packed_option, BoxedSlice, EntityRef, PrimaryMap};
}

pub mod wasm {
pub use cranelift_wasm::{
get_vmctx_value_label, DefinedFuncIndex, DefinedGlobalIndex, DefinedMemoryIndex,
DefinedTableIndex, FuncIndex, Global, GlobalIndex, GlobalInit, Memory, MemoryIndex,
SignatureIndex, Table, TableElementType, TableIndex,
PassiveElemIndex, SignatureIndex, Table, TableElementType, TableIndex,
};
}
Loading

0 comments on commit 76e08d6

Please sign in to comment.