Files
wasmtime/cranelift/wasm/tests/wasm_testsuite.rs
Chris Fallin 43f1765272 Cranellift: remove Baldrdash support and related features. (#4571)
* Cranellift: remove Baldrdash support and related features.

As noted in Mozilla's bugzilla bug 1781425 [1], the SpiderMonkey team
has recently determined that their current form of integration with
Cranelift is too hard to maintain, and they have chosen to remove it
from their codebase. If and when they decide to build updated support
for Cranelift, they will adopt different approaches to several details
of the integration.

In the meantime, after discussion with the SpiderMonkey folks, they
agree that it makes sense to remove the bits of Cranelift that exist
to support the integration ("Baldrdash"), as they will not need
them. Many of these bits are difficult-to-maintain special cases that
are not actually tested in Cranelift proper: for example, the
Baldrdash integration required Cranelift to emit function bodies
without prologues/epilogues, and instead communicate very precise
information about the expected frame size and layout, then stitched
together something post-facto. This was brittle and caused a lot of
incidental complexity ("fallthrough returns", the resulting special
logic in block-ordering); this is just one example. As another
example, one particular Baldrdash ABI variant processed stack args in
reverse order, so our ABI code had to support both traversal
orders. We had a number of other Baldrdash-specific settings as well
that did various special things.

This PR removes Baldrdash ABI support, the `fallthrough_return`
instruction, and pulls some threads to remove now-unused bits as a
result of those two, with the  understanding that the SpiderMonkey folks
will build new functionality as needed in the future and we can perhaps
find cleaner abstractions to make it all work.

[1] https://bugzilla.mozilla.org/show_bug.cgi?id=1781425

* Review feedback.

* Fix (?) DWARF debug tests: add `--disable-cache` to wasmtime invocations.

The debugger tests invoke `wasmtime` from within each test case under
the control of a debugger (gdb or lldb). Some of these tests started to
inexplicably fail in CI with unrelated changes, and the failures were
only inconsistently reproducible locally. It seems to be cache related:
if we disable cached compilation on the nested `wasmtime` invocations,
the tests consistently pass.

* Review feedback.
2022-08-02 19:37:56 +00:00

163 lines
4.6 KiB
Rust

use cranelift_codegen::isa::{CallConv, TargetFrontendConfig};
use cranelift_codegen::print_errors::pretty_verifier_error;
use cranelift_codegen::settings::{self, Flags};
use cranelift_codegen::verifier;
use cranelift_wasm::{translate_module, DummyEnvironment, FuncIndex};
use std::fs;
use std::path::Path;
use target_lexicon::PointerWidth;
#[test]
fn testsuite() {
let mut paths: Vec<_> = fs::read_dir("./wasmtests")
.unwrap()
.map(|r| r.unwrap())
.filter(|p| {
// Ignore files starting with `.`, which could be editor temporary files
if let Some(stem) = p.path().file_stem() {
if let Some(stemstr) = stem.to_str() {
return !stemstr.starts_with('.');
}
}
false
})
.collect();
paths.sort_by_key(|dir| dir.path());
let flags = Flags::new(settings::builder());
for path in paths {
let path = path.path();
println!("=== {} ===", path.display());
let data = read_module(&path);
handle_module(data, &flags);
}
}
#[test]
fn use_name_section() {
let data = wat::parse_str(
r#"
(module $module_name
(func $func_name (local $loc_name i32)
)
)"#,
)
.unwrap();
let mut dummy_environ = DummyEnvironment::new(
TargetFrontendConfig {
default_call_conv: CallConv::SystemV,
pointer_width: PointerWidth::U32,
},
false,
);
translate_module(data.as_ref(), &mut dummy_environ).unwrap();
assert_eq!(
dummy_environ.get_func_name(FuncIndex::from_u32(0)).unwrap(),
"func_name"
);
}
fn read_module(path: &Path) -> Vec<u8> {
match path.extension() {
None => {
panic!("the file extension is not wasm or wat");
}
Some(ext) => match ext.to_str() {
Some("wasm") => std::fs::read(path).expect("error reading wasm file"),
Some("wat") => wat::parse_file(path)
.map_err(|e| e.to_string())
.expect("failed to parse wat"),
None | Some(&_) => panic!("the file extension for {:?} is not wasm or wat", path),
},
}
}
fn handle_module(data: Vec<u8>, flags: &Flags) {
let mut dummy_environ = DummyEnvironment::new(
TargetFrontendConfig {
default_call_conv: CallConv::SystemV,
pointer_width: PointerWidth::U64,
},
false,
);
translate_module(&data, &mut dummy_environ).unwrap();
for func in dummy_environ.info.function_bodies.values() {
verifier::verify_function(func, flags)
.map_err(|errors| panic!("{}", pretty_verifier_error(func, None, errors)))
.unwrap();
}
}
#[test]
fn reachability_is_correct() {
let tests = vec![
(
r#"
(module (func (param i32)
(loop
(block
local.get 0
br_if 0
br 1))))"#,
vec![
(true, true), // Loop
(true, true), // Block
(true, true), // LocalGet
(true, true), // BrIf
(true, false), // Br
(false, true), // End
(true, true), // End
(true, true), // End
],
),
(
r#"
(module (func (param i32)
(loop
(block
br 1
nop))))"#,
vec![
(true, true), // Loop
(true, true), // Block
(true, false), // Br
(false, false), // Nop
(false, false), // Nop
(false, false), // Nop
(false, false), // End
],
),
(
r#"
(module (func (param i32) (result i32)
i32.const 1
return
i32.const 42))"#,
vec![
(true, true), // I32Const
(true, false), // Return
(false, false), // I32Const
(false, false), // End
],
),
];
for (wat, expected_reachability) in tests {
println!("testing wat:\n{}", wat);
let mut env = DummyEnvironment::new(
TargetFrontendConfig {
default_call_conv: CallConv::SystemV,
pointer_width: PointerWidth::U64,
},
false,
);
env.test_expected_reachability(expected_reachability);
let data = wat::parse_str(wat).unwrap();
translate_module(data.as_ref(), &mut env).unwrap();
}
}