Use the more-asserts crate in more places.
This provides assert_le, assert_lt, and so on, which can print the values of the operands.
This commit is contained in:
@@ -40,6 +40,7 @@ wat = "1.0.2"
|
||||
libc = "0.2.60"
|
||||
rayon = "1.1"
|
||||
wasm-webidl-bindings = "0.6"
|
||||
more-asserts = "0.2.1"
|
||||
|
||||
[build-dependencies]
|
||||
anyhow = "1.0.19"
|
||||
|
||||
@@ -68,8 +68,8 @@ fn main() -> Result<()> {
|
||||
println!("Printing result...");
|
||||
println!("> {} {}", results[0].i64(), results[1].i32());
|
||||
|
||||
debug_assert!(results[0].i64() == 4);
|
||||
debug_assert!(results[1].i32() == 2);
|
||||
debug_assert_eq!(results[0].i64(), 4);
|
||||
debug_assert_eq!(results[1].i32(), 2);
|
||||
|
||||
// Shut down.
|
||||
println!("Shutting down...");
|
||||
|
||||
@@ -43,7 +43,7 @@ fn into_valtype(ty: &wasmparser::Type) -> ValType {
|
||||
}
|
||||
|
||||
fn into_func_type(mt: wasmparser::FuncType) -> FuncType {
|
||||
assert!(mt.form == wasmparser::Type::Func);
|
||||
assert_eq!(mt.form, wasmparser::Type::Func);
|
||||
let params = mt.params.iter().map(into_valtype).collect::<Vec<_>>();
|
||||
let returns = mt.returns.iter().map(into_valtype).collect::<Vec<_>>();
|
||||
FuncType::new(params.into_boxed_slice(), returns.into_boxed_slice())
|
||||
|
||||
@@ -131,7 +131,7 @@ impl ExternType {
|
||||
|
||||
// Function Types
|
||||
fn from_cranelift_abiparam(param: &ir::AbiParam) -> ValType {
|
||||
assert!(param.purpose == ir::ArgumentPurpose::Normal);
|
||||
assert_eq!(param.purpose, ir::ArgumentPurpose::Normal);
|
||||
ValType::from_cranelift_type(param.value_type)
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ macro_rules! declare_vec {
|
||||
fn set_from_slice(&mut self, source: &[$elem_ty]) {
|
||||
let mut buffer = Vec::with_capacity(source.len());
|
||||
buffer.extend_from_slice(source);
|
||||
assert!(buffer.len() == buffer.capacity());
|
||||
assert_eq!(buffer.len(), buffer.capacity());
|
||||
self.size = buffer.len();
|
||||
self.data = buffer.as_mut_ptr();
|
||||
mem::forget(buffer);
|
||||
@@ -38,7 +38,7 @@ macro_rules! declare_vec {
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn set_buffer(&mut self, mut buffer: Vec<$elem_ty>) {
|
||||
assert!(buffer.len() == buffer.capacity());
|
||||
assert_eq!(buffer.len(), buffer.capacity());
|
||||
self.size = buffer.len();
|
||||
self.data = buffer.as_mut_ptr();
|
||||
mem::forget(buffer);
|
||||
@@ -65,7 +65,7 @@ macro_rules! declare_vec {
|
||||
|
||||
impl From<Vec<$elem_ty>> for $name {
|
||||
fn from(mut vec: Vec<$elem_ty>) -> Self {
|
||||
assert!(vec.len() == vec.capacity());
|
||||
assert_eq!(vec.len(), vec.capacity());
|
||||
let result = $name {
|
||||
size: vec.len(),
|
||||
data: vec.as_mut_ptr(),
|
||||
@@ -95,7 +95,7 @@ macro_rules! declare_vec {
|
||||
fn set_from_slice(&mut self, source: &[*mut $elem_ty]) {
|
||||
let mut buffer = Vec::with_capacity(source.len());
|
||||
buffer.extend_from_slice(source);
|
||||
assert!(buffer.len() == buffer.capacity());
|
||||
assert_eq!(buffer.len(), buffer.capacity());
|
||||
self.size = buffer.len();
|
||||
self.data = buffer.as_mut_ptr();
|
||||
mem::forget(buffer);
|
||||
@@ -103,7 +103,7 @@ macro_rules! declare_vec {
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn set_buffer(&mut self, mut buffer: Vec<*mut $elem_ty>) {
|
||||
assert!(buffer.len() == buffer.capacity());
|
||||
assert_eq!(buffer.len(), buffer.capacity());
|
||||
self.size = buffer.len();
|
||||
self.data = buffer.as_mut_ptr();
|
||||
mem::forget(buffer);
|
||||
@@ -132,7 +132,7 @@ macro_rules! declare_vec {
|
||||
|
||||
impl From<Vec<*mut $elem_ty>> for $name {
|
||||
fn from(mut vec: Vec<*mut $elem_ty>) -> Self {
|
||||
assert!(vec.len() == vec.capacity());
|
||||
assert_eq!(vec.len(), vec.capacity());
|
||||
let result = $name {
|
||||
size: vec.len(),
|
||||
data: vec.as_mut_ptr(),
|
||||
|
||||
@@ -23,6 +23,7 @@ target-lexicon = { version = "0.9.0", default-features = false }
|
||||
failure = { version = "0.1.3", default-features = false }
|
||||
hashbrown = { version = "0.6.0", optional = true }
|
||||
thiserror = "1.0.4"
|
||||
more-asserts = "0.2.1"
|
||||
|
||||
[features]
|
||||
default = ["std"]
|
||||
|
||||
@@ -7,13 +7,13 @@ use alloc::vec::Vec;
|
||||
use cranelift_codegen::isa::TargetFrontendConfig;
|
||||
use faerie::{Artifact, Decl};
|
||||
use failure::Error;
|
||||
use target_lexicon::{BinaryFormat, Triple};
|
||||
use wasmtime_environ::{ModuleAddressMap, ModuleVmctxInfo, ValueLabelsRanges};
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
use hashbrown::{hash_map, HashMap, HashSet};
|
||||
use more_asserts::assert_gt;
|
||||
#[cfg(feature = "std")]
|
||||
use std::collections::{hash_map, HashMap, HashSet};
|
||||
use target_lexicon::{BinaryFormat, Triple};
|
||||
use wasmtime_environ::{ModuleAddressMap, ModuleVmctxInfo, ValueLabelsRanges};
|
||||
|
||||
pub use crate::read_debuginfo::{read_debuginfo, DebugInfoData, WasmFileInfo};
|
||||
pub use crate::transform::transform_dwarf;
|
||||
@@ -77,7 +77,7 @@ pub fn emit_debugsections_image(
|
||||
let dwarf = transform_dwarf(target_config, debuginfo_data, at, vmctx_info, ranges)?;
|
||||
|
||||
// Assuming all functions in the same code block, looking min/max of its range.
|
||||
assert!(funcs.len() > 0);
|
||||
assert_gt!(funcs.len(), 0);
|
||||
let mut segment_body: (usize, usize) = (!0, 0);
|
||||
for (body_ptr, body_len) in funcs {
|
||||
segment_body.0 = ::core::cmp::min(segment_body.0, *body_ptr as usize);
|
||||
@@ -116,9 +116,9 @@ fn convert_faerie_elf_to_loadable_file(bytes: &mut Vec<u8>, code_ptr: *const u8)
|
||||
"program header table is empty"
|
||||
);
|
||||
let e_phentsize = unsafe { *(bytes.as_ptr().offset(0x36) as *const u16) };
|
||||
assert!(e_phentsize == 0x38, "size of ph");
|
||||
assert_eq!(e_phentsize, 0x38, "size of ph");
|
||||
let e_shentsize = unsafe { *(bytes.as_ptr().offset(0x3A) as *const u16) };
|
||||
assert!(e_shentsize == 0x40, "size of sh");
|
||||
assert_eq!(e_shentsize, 0x40, "size of sh");
|
||||
|
||||
let e_shoff = unsafe { *(bytes.as_ptr().offset(0x28) as *const u64) };
|
||||
let e_shnum = unsafe { *(bytes.as_ptr().offset(0x3C) as *const u16) };
|
||||
|
||||
@@ -8,6 +8,7 @@ use cranelift_codegen::ir::SourceLoc;
|
||||
use cranelift_entity::{EntityRef, PrimaryMap};
|
||||
use cranelift_wasm::DefinedFuncIndex;
|
||||
use gimli::write;
|
||||
use more_asserts::assert_le;
|
||||
use wasmtime_environ::{FunctionAddressMap, ModuleAddressMap};
|
||||
|
||||
pub type GeneratedAddress = usize;
|
||||
@@ -87,10 +88,10 @@ fn build_function_lookup(
|
||||
ft: &FunctionAddressMap,
|
||||
code_section_offset: u64,
|
||||
) -> (WasmAddress, WasmAddress, FuncLookup) {
|
||||
assert!(code_section_offset <= ft.start_srcloc.bits() as u64);
|
||||
assert_le!(code_section_offset, ft.start_srcloc.bits() as u64);
|
||||
let fn_start = get_wasm_code_offset(ft.start_srcloc, code_section_offset);
|
||||
let fn_end = get_wasm_code_offset(ft.end_srcloc, code_section_offset);
|
||||
assert!(fn_start <= fn_end);
|
||||
assert_le!(fn_start, fn_end);
|
||||
|
||||
// Build ranges of continuous source locations. The new ranges starts when
|
||||
// non-descending order is interrupted. Assuming the same origin location can
|
||||
@@ -107,7 +108,8 @@ fn build_function_lookup(
|
||||
}
|
||||
|
||||
let offset = get_wasm_code_offset(t.srcloc, code_section_offset);
|
||||
assert!(fn_start <= offset && offset <= fn_end);
|
||||
assert_le!(fn_start, offset);
|
||||
assert_le!(offset, fn_end);
|
||||
|
||||
let inst_gen_start = t.code_offset;
|
||||
let inst_gen_end = t.code_offset + t.code_len;
|
||||
@@ -191,7 +193,7 @@ fn build_function_addr_map(
|
||||
if cfg!(debug) {
|
||||
// fn_map is sorted by the generated field -- see FunctionAddressMap::instructions.
|
||||
for i in 1..fn_map.len() {
|
||||
assert!(fn_map[i - 1].generated <= fn_map[i].generated);
|
||||
assert_le!(fn_map[i - 1].generated, fn_map[i].generated);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use super::address_transform::AddressTransform;
|
||||
use crate::{HashMap, HashSet};
|
||||
use alloc::vec::Vec;
|
||||
use cranelift_codegen::ir::{StackSlots, ValueLabel, ValueLoc};
|
||||
@@ -8,8 +9,7 @@ use cranelift_wasm::{get_vmctx_value_label, DefinedFuncIndex};
|
||||
use failure::Error;
|
||||
use gimli::write;
|
||||
use gimli::{self, Expression, Operation, Reader, ReaderOffset, Register, X86_64};
|
||||
|
||||
use super::address_transform::AddressTransform;
|
||||
use more_asserts::{assert_le, assert_lt};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct FunctionFrameInfo<'a> {
|
||||
@@ -103,7 +103,7 @@ fn translate_loc(loc: ValueLoc, frame_info: Option<&FunctionFrameInfo>) -> Optio
|
||||
match loc {
|
||||
ValueLoc::Reg(reg) => {
|
||||
let machine_reg = map_reg(reg).0 as u8;
|
||||
assert!(machine_reg < 32); // FIXME
|
||||
assert_lt!(machine_reg, 32); // FIXME
|
||||
Some(vec![gimli::constants::DW_OP_reg0.0 + machine_reg])
|
||||
}
|
||||
ValueLoc::Stack(ss) => {
|
||||
@@ -437,7 +437,7 @@ impl<'a, 'b> ValueLabelRangesBuilder<'a, 'b> {
|
||||
if range_start == range_end {
|
||||
continue;
|
||||
}
|
||||
assert!(range_start < range_end);
|
||||
assert_lt!(range_start, range_end);
|
||||
// Find acceptable scope of ranges to intersect with.
|
||||
let i = match ranges.binary_search_by(|s| s.start.cmp(&range_start)) {
|
||||
Ok(i) => i,
|
||||
@@ -465,7 +465,7 @@ impl<'a, 'b> ValueLabelRangesBuilder<'a, 'b> {
|
||||
tail.start = range_end;
|
||||
ranges.insert(i + 1, tail);
|
||||
}
|
||||
assert!(ranges[i].end <= range_end);
|
||||
assert_le!(ranges[i].end, range_end);
|
||||
if range_start <= ranges[i].start {
|
||||
ranges[i].label_location.insert(label, loc);
|
||||
continue;
|
||||
|
||||
@@ -1,18 +1,15 @@
|
||||
use super::address_transform::AddressTransform;
|
||||
use super::attr::clone_attr_string;
|
||||
use super::{Reader, TransformError};
|
||||
use alloc::collections::BTreeMap;
|
||||
use alloc::vec::Vec;
|
||||
use core::iter::FromIterator;
|
||||
use cranelift_entity::EntityRef;
|
||||
use failure::Error;
|
||||
|
||||
use gimli;
|
||||
|
||||
use gimli::{DebugLine, DebugLineOffset, DebugStr, DebuggingInformationEntry, LineEncoding, Unit};
|
||||
|
||||
use gimli::write;
|
||||
|
||||
use super::address_transform::AddressTransform;
|
||||
use super::attr::clone_attr_string;
|
||||
use super::{Reader, TransformError};
|
||||
use gimli::{DebugLine, DebugLineOffset, DebugStr, DebuggingInformationEntry, LineEncoding, Unit};
|
||||
use more_asserts::assert_le;
|
||||
|
||||
#[derive(Debug)]
|
||||
enum SavedLineProgramRow {
|
||||
@@ -80,7 +77,7 @@ where
|
||||
);
|
||||
if let Ok(program) = program {
|
||||
let header = program.header();
|
||||
assert!(header.version() <= 4, "not supported 5");
|
||||
assert_le!(header.version(), 4, "not supported 5");
|
||||
let line_encoding = LineEncoding {
|
||||
minimum_instruction_length: header.minimum_instruction_length(),
|
||||
maximum_operations_per_instruction: header.maximum_operations_per_instruction(),
|
||||
|
||||
@@ -1,17 +1,14 @@
|
||||
use super::address_transform::AddressTransform;
|
||||
use super::DebugInputContext;
|
||||
use super::Reader;
|
||||
use alloc::vec::Vec;
|
||||
use cranelift_entity::EntityRef;
|
||||
use cranelift_wasm::DefinedFuncIndex;
|
||||
use failure::Error;
|
||||
|
||||
use gimli;
|
||||
|
||||
use gimli::{AttributeValue, DebuggingInformationEntry, RangeListsOffset};
|
||||
|
||||
use gimli::write;
|
||||
|
||||
use super::address_transform::AddressTransform;
|
||||
use super::DebugInputContext;
|
||||
use super::Reader;
|
||||
use gimli::{AttributeValue, DebuggingInformationEntry, RangeListsOffset};
|
||||
use more_asserts::assert_lt;
|
||||
|
||||
pub(crate) enum RangeInfoBuilder {
|
||||
Undefined,
|
||||
@@ -206,7 +203,7 @@ impl RangeInfoBuilder {
|
||||
if let RangeInfoBuilder::Ranges(ranges) = self {
|
||||
let mut range_list = Vec::new();
|
||||
for (begin, end) in ranges {
|
||||
assert!(begin < end);
|
||||
assert_lt!(begin, end);
|
||||
for tr in addr_tr.translate_ranges(*begin, *end) {
|
||||
if tr.1 == 0 {
|
||||
// Ignore empty range
|
||||
|
||||
@@ -174,7 +174,7 @@ where
|
||||
let mut entries = unit.entries();
|
||||
let (mut comp_unit, file_map, cu_low_pc, wp_die_id, vmctx_die_id) =
|
||||
if let Some((depth_delta, entry)) = entries.next_dfs()? {
|
||||
assert!(depth_delta == 0);
|
||||
assert_eq!(depth_delta, 0);
|
||||
let (out_line_program, debug_line_offset, file_map) = clone_line_program(
|
||||
&unit,
|
||||
entry,
|
||||
@@ -298,7 +298,7 @@ where
|
||||
stack.pop();
|
||||
}
|
||||
} else {
|
||||
assert!(depth_delta == 1);
|
||||
assert_eq!(depth_delta, 1);
|
||||
}
|
||||
|
||||
if let Some(AttributeValue::Exprloc(expr)) = entry.attr_value(gimli::DW_AT_frame_base)? {
|
||||
@@ -323,7 +323,7 @@ where
|
||||
&mut pending_die_refs,
|
||||
)?;
|
||||
stack.push(die_id);
|
||||
assert!(stack.len() == new_stack_len);
|
||||
assert_eq!(stack.len(), new_stack_len);
|
||||
die_ref_map.insert(entry.offset(), die_id);
|
||||
continue;
|
||||
}
|
||||
@@ -331,7 +331,7 @@ where
|
||||
let die_id = comp_unit.add(*parent, entry.tag());
|
||||
|
||||
stack.push(die_id);
|
||||
assert!(stack.len() == new_stack_len);
|
||||
assert_eq!(stack.len(), new_stack_len);
|
||||
die_ref_map.insert(entry.offset(), die_id);
|
||||
|
||||
clone_die_attributes(
|
||||
|
||||
@@ -30,6 +30,7 @@ log = { version = "0.4.8", default-features = false }
|
||||
zstd = "0.5"
|
||||
toml = "0.5.5"
|
||||
file-per-thread-logger = "0.1.1"
|
||||
more-asserts = "0.2.1"
|
||||
|
||||
[target.'cfg(target_os = "windows")'.dependencies]
|
||||
winapi = "0.3.7"
|
||||
|
||||
18
crates/environ/src/cache/worker/tests.rs
vendored
18
crates/environ/src/cache/worker/tests.rs
vendored
@@ -1,6 +1,7 @@
|
||||
use super::*;
|
||||
use crate::cache::config::tests::test_prolog;
|
||||
use core::iter::repeat;
|
||||
use more_asserts::{assert_ge, assert_gt, assert_lt};
|
||||
use std::process;
|
||||
// load_config! comes from crate::cache(::config::tests);
|
||||
|
||||
@@ -149,7 +150,10 @@ fn test_on_get_recompress_with_mod_file() {
|
||||
let scenarios = [(4, false), (7, true), (2, false)];
|
||||
|
||||
let mut usages = start_stats.usages;
|
||||
assert!(usages < cache_config.optimized_compression_usage_counter_threshold());
|
||||
assert_lt!(
|
||||
usages,
|
||||
cache_config.optimized_compression_usage_counter_threshold()
|
||||
);
|
||||
let mut tested_higher_opt_compr_lvl = false;
|
||||
for (times_used, lower_compr_lvl) in &scenarios {
|
||||
for _ in 0..*times_used {
|
||||
@@ -176,13 +180,19 @@ fn test_on_get_recompress_with_mod_file() {
|
||||
assert_eq!(decoded_data, mod_data.as_bytes());
|
||||
|
||||
if *lower_compr_lvl {
|
||||
assert!(usages >= cache_config.optimized_compression_usage_counter_threshold());
|
||||
assert_ge!(
|
||||
usages,
|
||||
cache_config.optimized_compression_usage_counter_threshold()
|
||||
);
|
||||
tested_higher_opt_compr_lvl = true;
|
||||
stats.compression_level -= 1;
|
||||
assert!(write_stats_file(&stats_file, &stats));
|
||||
}
|
||||
}
|
||||
assert!(usages >= cache_config.optimized_compression_usage_counter_threshold());
|
||||
assert_ge!(
|
||||
usages,
|
||||
cache_config.optimized_compression_usage_counter_threshold()
|
||||
);
|
||||
assert!(tested_higher_opt_compr_lvl);
|
||||
}
|
||||
|
||||
@@ -418,7 +428,7 @@ fn test_on_update_cleanup_limits_trash_locks() {
|
||||
"past",
|
||||
&Duration::from_secs(secs_ago),
|
||||
);
|
||||
assert!(secs_ago > 0);
|
||||
assert_gt!(secs_ago, 0);
|
||||
secs_ago -= 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ impl binemit::RelocSink for RelocSink {
|
||||
} else if *name == get_imported_memory32_size_name() {
|
||||
RelocationTarget::ImportedMemory32Size
|
||||
} else if let ExternalName::User { namespace, index } = *name {
|
||||
debug_assert!(namespace == 0);
|
||||
debug_assert_eq!(namespace, 0);
|
||||
RelocationTarget::UserFunc(FuncIndex::from_u32(index))
|
||||
} else if let ExternalName::LibCall(libcall) = *name {
|
||||
RelocationTarget::LibCall(libcall)
|
||||
|
||||
@@ -13,6 +13,7 @@ use cranelift_wasm::{
|
||||
GlobalIndex, Memory, MemoryIndex, SignatureIndex, Table, TableIndex,
|
||||
};
|
||||
use indexmap::IndexMap;
|
||||
use more_asserts::assert_ge;
|
||||
|
||||
/// A WebAssembly table initializer.
|
||||
#[derive(Clone, Debug, Hash)]
|
||||
@@ -59,7 +60,7 @@ impl MemoryStyle {
|
||||
if maximum <= tunables.static_memory_bound {
|
||||
// A heap with a declared maximum can be immovable, so make
|
||||
// it static.
|
||||
assert!(tunables.static_memory_bound >= memory.minimum);
|
||||
assert_ge!(tunables.static_memory_bound, memory.minimum);
|
||||
return (
|
||||
Self::Static {
|
||||
bound: tunables.static_memory_bound,
|
||||
|
||||
@@ -9,6 +9,7 @@ use cranelift_wasm::{
|
||||
DefinedGlobalIndex, DefinedMemoryIndex, DefinedTableIndex, FuncIndex, GlobalIndex, MemoryIndex,
|
||||
SignatureIndex, TableIndex,
|
||||
};
|
||||
use more_asserts::assert_lt;
|
||||
|
||||
#[cfg(target_pointer_width = "32")]
|
||||
fn cast_to_u32(sz: usize) -> u32 {
|
||||
@@ -365,7 +366,7 @@ impl VMOffsets {
|
||||
|
||||
/// Return the offset to `VMSharedSignatureId` index `index`.
|
||||
pub fn vmctx_vmshared_signature_id(&self, index: SignatureIndex) -> u32 {
|
||||
assert!(index.as_u32() < self.num_signature_ids);
|
||||
assert_lt!(index.as_u32(), self.num_signature_ids);
|
||||
self.vmctx_signature_ids_begin()
|
||||
.checked_add(
|
||||
index
|
||||
@@ -378,7 +379,7 @@ impl VMOffsets {
|
||||
|
||||
/// Return the offset to `VMFunctionImport` index `index`.
|
||||
pub fn vmctx_vmfunction_import(&self, index: FuncIndex) -> u32 {
|
||||
assert!(index.as_u32() < self.num_imported_functions);
|
||||
assert_lt!(index.as_u32(), self.num_imported_functions);
|
||||
self.vmctx_imported_functions_begin()
|
||||
.checked_add(
|
||||
index
|
||||
@@ -391,7 +392,7 @@ impl VMOffsets {
|
||||
|
||||
/// Return the offset to `VMTableImport` index `index`.
|
||||
pub fn vmctx_vmtable_import(&self, index: TableIndex) -> u32 {
|
||||
assert!(index.as_u32() < self.num_imported_tables);
|
||||
assert_lt!(index.as_u32(), self.num_imported_tables);
|
||||
self.vmctx_imported_tables_begin()
|
||||
.checked_add(
|
||||
index
|
||||
@@ -404,7 +405,7 @@ impl VMOffsets {
|
||||
|
||||
/// Return the offset to `VMMemoryImport` index `index`.
|
||||
pub fn vmctx_vmmemory_import(&self, index: MemoryIndex) -> u32 {
|
||||
assert!(index.as_u32() < self.num_imported_memories);
|
||||
assert_lt!(index.as_u32(), self.num_imported_memories);
|
||||
self.vmctx_imported_memories_begin()
|
||||
.checked_add(
|
||||
index
|
||||
@@ -417,7 +418,7 @@ impl VMOffsets {
|
||||
|
||||
/// Return the offset to `VMGlobalImport` index `index`.
|
||||
pub fn vmctx_vmglobal_import(&self, index: GlobalIndex) -> u32 {
|
||||
assert!(index.as_u32() < self.num_imported_globals);
|
||||
assert_lt!(index.as_u32(), self.num_imported_globals);
|
||||
self.vmctx_imported_globals_begin()
|
||||
.checked_add(
|
||||
index
|
||||
@@ -430,7 +431,7 @@ impl VMOffsets {
|
||||
|
||||
/// Return the offset to `VMTableDefinition` index `index`.
|
||||
pub fn vmctx_vmtable_definition(&self, index: DefinedTableIndex) -> u32 {
|
||||
assert!(index.as_u32() < self.num_defined_tables);
|
||||
assert_lt!(index.as_u32(), self.num_defined_tables);
|
||||
self.vmctx_tables_begin()
|
||||
.checked_add(
|
||||
index
|
||||
@@ -443,7 +444,7 @@ impl VMOffsets {
|
||||
|
||||
/// Return the offset to `VMMemoryDefinition` index `index`.
|
||||
pub fn vmctx_vmmemory_definition(&self, index: DefinedMemoryIndex) -> u32 {
|
||||
assert!(index.as_u32() < self.num_defined_memories);
|
||||
assert_lt!(index.as_u32(), self.num_defined_memories);
|
||||
self.vmctx_memories_begin()
|
||||
.checked_add(
|
||||
index
|
||||
@@ -456,7 +457,7 @@ impl VMOffsets {
|
||||
|
||||
/// Return the offset to the `VMGlobalDefinition` index `index`.
|
||||
pub fn vmctx_vmglobal_definition(&self, index: DefinedGlobalIndex) -> u32 {
|
||||
assert!(index.as_u32() < self.num_defined_globals);
|
||||
assert_lt!(index.as_u32(), self.num_defined_globals);
|
||||
self.vmctx_globals_begin()
|
||||
.checked_add(
|
||||
index
|
||||
|
||||
@@ -24,6 +24,7 @@ thiserror = "1.0.4"
|
||||
target-lexicon = { version = "0.9.0", default-features = false }
|
||||
hashbrown = { version = "0.6.0", optional = true }
|
||||
wasmparser = { version = "0.39.2", default-features = false }
|
||||
more-asserts = "0.2.1"
|
||||
|
||||
[target.'cfg(target_os = "windows")'.dependencies]
|
||||
winapi = { version = "0.3.7", features = ["winnt", "impl-default"] }
|
||||
|
||||
@@ -185,7 +185,7 @@ impl CodeMemory {
|
||||
if previous.0.len() > 0 {
|
||||
self.mmaps.push(previous);
|
||||
} else {
|
||||
assert!(previous.1.len() == 0);
|
||||
assert_eq!(previous.1.len(), 0);
|
||||
}
|
||||
|
||||
self.position = 0;
|
||||
|
||||
@@ -101,8 +101,9 @@ impl FunctionTable {
|
||||
|
||||
unsafe {
|
||||
// Windows heap allocations are 32-bit aligned, but assert just in case
|
||||
assert!(
|
||||
(self.functions.as_mut_ptr() as u64) % 4 == 0,
|
||||
assert_eq!(
|
||||
(self.functions.as_mut_ptr() as u64) % 4,
|
||||
0,
|
||||
"function table allocation was not aligned"
|
||||
);
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ use cranelift_codegen::binemit::Reloc;
|
||||
use cranelift_codegen::ir::JumpTableOffsets;
|
||||
use cranelift_entity::PrimaryMap;
|
||||
use cranelift_wasm::{DefinedFuncIndex, Global, GlobalInit, Memory, Table, TableElementType};
|
||||
use more_asserts::assert_ge;
|
||||
use wasmtime_environ::{
|
||||
MemoryPlan, MemoryStyle, Module, Relocation, RelocationTarget, Relocations, TablePlan,
|
||||
};
|
||||
@@ -132,11 +133,11 @@ pub fn link_module(
|
||||
bound: import_bound,
|
||||
},
|
||||
) => {
|
||||
assert!(bound >= *import_bound);
|
||||
assert_ge!(bound, *import_bound);
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
assert!(memory.offset_guard_size >= import_memory.offset_guard_size);
|
||||
assert_ge!(memory.offset_guard_size, import_memory.offset_guard_size);
|
||||
|
||||
dependencies.insert(unsafe { InstanceHandle::from_vmctx(vmctx) });
|
||||
memory_imports.push(VMMemoryImport {
|
||||
|
||||
@@ -24,6 +24,7 @@ cranelift-codegen = "0.49"
|
||||
multi_mut = "0.1"
|
||||
either = "1.5"
|
||||
typemap = "0.3"
|
||||
more-asserts = "0.2.1"
|
||||
|
||||
[dev-dependencies]
|
||||
lazy_static = "1.2"
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#![allow(clippy::float_cmp)]
|
||||
|
||||
use self::registers::*;
|
||||
use crate::error::Error;
|
||||
use crate::microwasm::{BrTarget, Ieee32, Ieee64, SignlessType, Type, Value, F32, F64, I32, I64};
|
||||
use crate::module::ModuleContext;
|
||||
@@ -8,6 +9,7 @@ use dynasm::dynasm;
|
||||
use dynasmrt::x64::Assembler;
|
||||
use dynasmrt::{AssemblyOffset, DynamicLabel, DynasmApi, DynasmLabelApi, ExecutableBuffer};
|
||||
use either::Either;
|
||||
use more_asserts::assert_le;
|
||||
use std::{
|
||||
any::{Any, TypeId},
|
||||
collections::HashMap,
|
||||
@@ -18,8 +20,6 @@ use std::{
|
||||
ops::RangeInclusive,
|
||||
};
|
||||
|
||||
use self::registers::*;
|
||||
|
||||
// TODO: Get rid of this! It's a total hack.
|
||||
mod magic {
|
||||
use cranelift_codegen::ir;
|
||||
@@ -1954,7 +1954,7 @@ macro_rules! store {
|
||||
ctx.block_state.regs.release(src);
|
||||
}
|
||||
|
||||
assert!(offset <= i32::max_value() as u32);
|
||||
assert_le!(offset, i32::max_value() as u32);
|
||||
|
||||
let mut src = self.pop();
|
||||
let base = self.pop();
|
||||
|
||||
@@ -9,6 +9,7 @@ use core::{fmt, mem};
|
||||
use cranelift_codegen::binemit;
|
||||
use dynasmrt::DynasmApi;
|
||||
use either::{Either, Left, Right};
|
||||
use more_asserts::assert_ge;
|
||||
use multi_mut::HashMapMultiMut;
|
||||
use std::{collections::HashMap, hash::Hash};
|
||||
|
||||
@@ -152,26 +153,6 @@ where
|
||||
block.is_next = true;
|
||||
}
|
||||
|
||||
macro_rules! assert_ge {
|
||||
($left:expr, $right:expr) => ({
|
||||
match (&$left, &$right) {
|
||||
(left_val, right_val) => {
|
||||
if !(*left_val >= *right_val) {
|
||||
// The reborrows below are intentional. Without them, the stack slot for the
|
||||
// borrow is initialized even before the values are compared, leading to a
|
||||
// noticeable slow down.
|
||||
panic!(r#"assertion failed: `(left >= right)`
|
||||
left: `{:?}`,
|
||||
right: `{:?}`"#, &*left_val, &*right_val)
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
($left:expr, $right:expr,) => ({
|
||||
assert_ge!($left, $right)
|
||||
});
|
||||
}
|
||||
|
||||
// `cfg` on blocks doesn't work in the compiler right now, so we have to write a dummy macro
|
||||
#[cfg(debug_assertions)]
|
||||
macro_rules! assertions {
|
||||
|
||||
@@ -7,6 +7,7 @@ use cranelift_codegen::{
|
||||
ir::{self, AbiParam, Signature as CraneliftSignature},
|
||||
isa,
|
||||
};
|
||||
use more_asserts::assert_le;
|
||||
use wasmparser::{FuncType, MemoryType, ModuleReader, SectionCode, Type};
|
||||
|
||||
pub trait AsValueType {
|
||||
@@ -554,8 +555,9 @@ pub fn translate_only(data: &[u8]) -> Result<TranslatedModule, Error> {
|
||||
let memories = section.get_memory_section_reader()?;
|
||||
let mem = translate_sections::memory(memories)?;
|
||||
|
||||
assert!(
|
||||
mem.len() <= 1,
|
||||
assert_le!(
|
||||
mem.len(),
|
||||
1,
|
||||
"Multiple memory sections not yet unimplemented"
|
||||
);
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ cranelift-entity = { version = "0.49", features = ["enable-serde"] }
|
||||
cranelift-wasm = { version = "0.49", features = ["enable-serde"] }
|
||||
wasmtime-environ = { path = "../environ" }
|
||||
faerie = "0.12.0"
|
||||
more-asserts = "0.2.1"
|
||||
|
||||
[badges]
|
||||
maintenance = { status = "experimental" }
|
||||
|
||||
@@ -6,6 +6,7 @@ use core::ptr;
|
||||
use cranelift_codegen::isa::TargetFrontendConfig;
|
||||
use cranelift_entity::EntityRef;
|
||||
use cranelift_wasm::GlobalInit;
|
||||
use more_asserts::assert_le;
|
||||
use std::collections::hash_map::Entry;
|
||||
use std::collections::HashMap;
|
||||
use wasmtime_environ::{Module, TargetSharedSignatureIndex, VMOffsets};
|
||||
@@ -31,7 +32,7 @@ pub fn layout_vmcontext(
|
||||
let target_index = match signature_registry.entry(sig) {
|
||||
Entry::Occupied(o) => *o.get(),
|
||||
Entry::Vacant(v) => {
|
||||
assert!(signature_registry_len <= ::core::u32::MAX as usize);
|
||||
assert_le!(signature_registry_len, ::core::u32::MAX as usize);
|
||||
let id = TargetSharedSignatureIndex::new(signature_registry_len as u32);
|
||||
signature_registry_len += 1;
|
||||
*v.insert(id)
|
||||
|
||||
@@ -23,6 +23,7 @@ indexmap = "1.0.2"
|
||||
hashbrown = { version = "0.6.0", optional = true }
|
||||
spin = { version = "0.5.2", optional = true }
|
||||
thiserror = "1.0.4"
|
||||
more-asserts = "0.2.1"
|
||||
|
||||
[target.'cfg(target_os = "windows")'.dependencies]
|
||||
winapi = { version = "0.3.7", features = ["winbase", "memoryapi"] }
|
||||
|
||||
@@ -33,6 +33,7 @@ use cranelift_wasm::{
|
||||
GlobalIndex, GlobalInit, MemoryIndex, SignatureIndex, TableIndex,
|
||||
};
|
||||
use indexmap;
|
||||
use more_asserts::assert_lt;
|
||||
use thiserror::Error;
|
||||
use wasmtime_environ::{DataInitializer, Module, TableElements, VMOffsets};
|
||||
|
||||
@@ -458,7 +459,7 @@ impl Instance {
|
||||
(body, self.vmctx_mut() as *mut VMContext)
|
||||
}
|
||||
None => {
|
||||
assert!(index.index() < self.module.imported_funcs.len());
|
||||
assert_lt!(index.index(), self.module.imported_funcs.len());
|
||||
let import = self.imported_function(index);
|
||||
(import.body, import.vmctx)
|
||||
}
|
||||
@@ -526,7 +527,7 @@ impl Instance {
|
||||
let index = DefinedTableIndex::new(
|
||||
(end as usize - begin as usize) / mem::size_of::<VMTableDefinition>(),
|
||||
);
|
||||
assert!(index.index() < self.tables.len());
|
||||
assert_lt!(index.index(), self.tables.len());
|
||||
index
|
||||
}
|
||||
|
||||
@@ -542,7 +543,7 @@ impl Instance {
|
||||
let index = DefinedMemoryIndex::new(
|
||||
(end as usize - begin as usize) / mem::size_of::<VMMemoryDefinition>(),
|
||||
);
|
||||
assert!(index.index() < self.memories.len());
|
||||
assert_lt!(index.index(), self.memories.len());
|
||||
index
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ use crate::mmap::Mmap;
|
||||
use crate::vmcontext::VMMemoryDefinition;
|
||||
use alloc::string::String;
|
||||
use core::convert::TryFrom;
|
||||
use more_asserts::{assert_ge, assert_le};
|
||||
use wasmtime_environ::{MemoryPlan, MemoryStyle, WASM_MAX_PAGES, WASM_PAGE_SIZE};
|
||||
|
||||
/// A linear memory instance.
|
||||
@@ -33,7 +34,7 @@ impl LinearMemory {
|
||||
/// Create a new linear memory instance with specified minimum and maximum number of wasm pages.
|
||||
pub fn new(plan: &MemoryPlan) -> Result<Self, String> {
|
||||
// `maximum` cannot be set to more than `65536` pages.
|
||||
assert!(plan.memory.minimum <= WASM_MAX_PAGES);
|
||||
assert_le!(plan.memory.minimum, WASM_MAX_PAGES);
|
||||
assert!(plan.memory.maximum.is_none() || plan.memory.maximum.unwrap() <= WASM_MAX_PAGES);
|
||||
|
||||
let offset_guard_bytes = plan.offset_guard_size as usize;
|
||||
@@ -50,7 +51,7 @@ impl LinearMemory {
|
||||
let minimum_pages = match plan.style {
|
||||
MemoryStyle::Dynamic => plan.memory.minimum,
|
||||
MemoryStyle::Static { bound } => {
|
||||
assert!(bound >= plan.memory.minimum);
|
||||
assert_ge!(bound, plan.memory.minimum);
|
||||
bound
|
||||
}
|
||||
} as usize;
|
||||
|
||||
@@ -7,6 +7,8 @@ use core::ptr;
|
||||
use core::slice;
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
use libc;
|
||||
use more_asserts::assert_le;
|
||||
use more_asserts::assert_lt;
|
||||
use region;
|
||||
use std::io;
|
||||
|
||||
@@ -51,7 +53,7 @@ impl Mmap {
|
||||
mapping_size: usize,
|
||||
) -> Result<Self, String> {
|
||||
let page_size = region::page::size();
|
||||
assert!(accessible_size <= mapping_size);
|
||||
assert_le!(accessible_size, mapping_size);
|
||||
assert_eq!(mapping_size & (page_size - 1), 0);
|
||||
assert_eq!(accessible_size & (page_size - 1), 0);
|
||||
|
||||
@@ -123,7 +125,7 @@ impl Mmap {
|
||||
use winapi::um::winnt::{MEM_COMMIT, MEM_RESERVE, PAGE_NOACCESS, PAGE_READWRITE};
|
||||
|
||||
let page_size = region::page::size();
|
||||
assert!(accessible_size <= mapping_size);
|
||||
assert_le!(accessible_size, mapping_size);
|
||||
assert_eq!(mapping_size & (page_size - 1), 0);
|
||||
assert_eq!(accessible_size & (page_size - 1), 0);
|
||||
|
||||
@@ -175,8 +177,8 @@ impl Mmap {
|
||||
let page_size = region::page::size();
|
||||
assert_eq!(start & (page_size - 1), 0);
|
||||
assert_eq!(len & (page_size - 1), 0);
|
||||
assert!(len < self.len);
|
||||
assert!(start < self.len - len);
|
||||
assert_lt!(len, self.len);
|
||||
assert_lt!(start, self.len - len);
|
||||
|
||||
// Commit the accessible size.
|
||||
unsafe { region::protect(self.ptr.add(start), len, region::Protection::ReadWrite) }
|
||||
@@ -194,8 +196,8 @@ impl Mmap {
|
||||
let page_size = region::page::size();
|
||||
assert_eq!(start & (page_size - 1), 0);
|
||||
assert_eq!(len & (page_size - 1), 0);
|
||||
assert!(len < self.len);
|
||||
assert!(start < self.len - len);
|
||||
assert_lt!(len, self.len);
|
||||
assert_lt!(start, self.len - len);
|
||||
|
||||
// Commit the accessible size.
|
||||
if unsafe {
|
||||
|
||||
@@ -5,6 +5,7 @@ use crate::vmcontext::VMSharedSignatureIndex;
|
||||
use crate::{hash_map, HashMap};
|
||||
use core::convert::TryFrom;
|
||||
use cranelift_codegen::ir;
|
||||
use more_asserts::{assert_lt, debug_assert_lt};
|
||||
|
||||
/// WebAssembly requires that the caller and callee signatures in an indirect
|
||||
/// call must match. To implement this efficiently, keep a registry of all
|
||||
@@ -31,8 +32,9 @@ impl SignatureRegistry {
|
||||
hash_map::Entry::Vacant(entry) => {
|
||||
// Keep `signature_hash` len under 2**32 -- VMSharedSignatureIndex::new(core::u32::MAX)
|
||||
// is reserved for VMSharedSignatureIndex::default().
|
||||
debug_assert!(
|
||||
len < core::u32::MAX as usize,
|
||||
debug_assert_lt!(
|
||||
len,
|
||||
core::u32::MAX as usize,
|
||||
"Invariant check: signature_hash.len() < core::u32::MAX"
|
||||
);
|
||||
let sig_id = VMSharedSignatureIndex::new(u32::try_from(len).unwrap());
|
||||
|
||||
@@ -260,15 +260,16 @@ pub struct VMGlobalDefinition {
|
||||
mod test_vmglobal_definition {
|
||||
use super::VMGlobalDefinition;
|
||||
use core::mem::{align_of, size_of};
|
||||
use more_asserts::assert_ge;
|
||||
use wasmtime_environ::{Module, VMOffsets};
|
||||
|
||||
#[test]
|
||||
fn check_vmglobal_definition_alignment() {
|
||||
assert!(align_of::<VMGlobalDefinition>() >= align_of::<i32>());
|
||||
assert!(align_of::<VMGlobalDefinition>() >= align_of::<i64>());
|
||||
assert!(align_of::<VMGlobalDefinition>() >= align_of::<f32>());
|
||||
assert!(align_of::<VMGlobalDefinition>() >= align_of::<f64>());
|
||||
assert!(align_of::<VMGlobalDefinition>() >= align_of::<[u8; 16]>());
|
||||
assert_ge!(align_of::<VMGlobalDefinition>(), align_of::<i32>());
|
||||
assert_ge!(align_of::<VMGlobalDefinition>(), align_of::<i64>());
|
||||
assert_ge!(align_of::<VMGlobalDefinition>(), align_of::<f32>());
|
||||
assert_ge!(align_of::<VMGlobalDefinition>(), align_of::<f64>());
|
||||
assert_ge!(align_of::<VMGlobalDefinition>(), align_of::<[u8; 16]>());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -20,6 +20,7 @@ cranelift-wasm = { version = "0.49", features = ["enable-serde"] }
|
||||
target-lexicon = "0.9.0"
|
||||
log = { version = "0.4.8", default-features = false }
|
||||
libc = "0.2.60"
|
||||
more-asserts = "0.2.1"
|
||||
|
||||
[build-dependencies]
|
||||
cmake = "0.1.35"
|
||||
|
||||
@@ -1385,7 +1385,7 @@ syscalls! {
|
||||
return return_encoded_errno(e);
|
||||
}
|
||||
|
||||
assert!(in_.len() == host_out.len());
|
||||
assert_eq!(in_.len(), host_out.len());
|
||||
|
||||
let e = host::wasmtime_ssp_poll_oneoff(
|
||||
curfds,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use crate::host;
|
||||
use crate::wasm32;
|
||||
use core::convert::TryFrom;
|
||||
use more_asserts::assert_le;
|
||||
use std::mem::{align_of, size_of, zeroed};
|
||||
use std::slice;
|
||||
use wasmtime_runtime::{Export, VMContext};
|
||||
@@ -571,6 +572,6 @@ pub unsafe fn encode_filestat_byref(
|
||||
}
|
||||
|
||||
pub fn encode_errno(e: host::__wasi_errno_t) -> wasm32::__wasi_errno_t {
|
||||
assert!(e <= wasm32::__WASI_ENOTCAPABLE);
|
||||
assert_le!(e, wasm32::__WASI_ENOTCAPABLE);
|
||||
e
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ use alloc::rc::Rc;
|
||||
use core::cell::RefCell;
|
||||
use cranelift_codegen::settings;
|
||||
use cranelift_codegen::settings::Configurable;
|
||||
use more_asserts::assert_gt;
|
||||
use std::collections::HashMap;
|
||||
use std::path::PathBuf;
|
||||
use wasmtime_jit::{instantiate, CompilationStrategy, Compiler, NullResolver};
|
||||
@@ -15,7 +16,7 @@ const PATH_MODULE_RS2WASM_ADD_FUNC: &str = r"tests/wat/rs2wasm-add-func.wat";
|
||||
fn test_environ_translate() {
|
||||
let path = PathBuf::from(PATH_MODULE_RS2WASM_ADD_FUNC);
|
||||
let data = wat::parse_file(path).expect("expecting valid wat-file");
|
||||
assert!(data.len() > 0);
|
||||
assert_gt!(data.len(), 0);
|
||||
|
||||
let mut flag_builder = settings::builder();
|
||||
flag_builder.enable("enable_verifier").unwrap();
|
||||
|
||||
Reference in New Issue
Block a user