Skip to content

Commit c15ca42

Browse files
authored
Forward misc. integration changes from #1655 (#1688)
* improve debug_assert failure message * fix field ordering of TableSet operations * add #[inline(always)] to decode impl Benchmarks show significant performance improvements. * add #[inline(always)] to TryFrom<u16> for OpCode * improve code formatting in match * add trivial {Read,Write}As impls for UntypedVal * add From<Memory> for u32 impl * apply rustfmt
1 parent 6b7a6e2 commit c15ca42

File tree

7 files changed

+37
-12
lines changed

7 files changed

+37
-12
lines changed

crates/core/src/typed.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,12 @@ macro_rules! impl_from_typed_value_for {
9393
// since the whole translation process assumes that Wasm validation
9494
// was already performed and thus type checking does not necessarily
9595
// need to happen redundantly outside of debug builds.
96-
debug_assert!(matches!(typed_value.ty, <$ty as Typed>::TY));
96+
debug_assert!(
97+
matches!(typed_value.ty, <$ty as Typed>::TY),
98+
"type mismatch: expected {:?} but found {:?}",
99+
<$ty as Typed>::TY,
100+
typed_value.ty,
101+
);
97102
Self::from(typed_value.value)
98103
}
99104
}

crates/core/src/untyped.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ pub trait ReadAs<T> {
3535
fn read_as(&self) -> T;
3636
}
3737

38+
impl ReadAs<UntypedVal> for UntypedVal {
39+
fn read_as(&self) -> UntypedVal {
40+
*self
41+
}
42+
}
43+
3844
macro_rules! impl_read_as_for_int {
3945
( $( $int:ty ),* $(,)? ) => {
4046
$(
@@ -83,6 +89,12 @@ pub trait WriteAs<T> {
8389
fn write_as(&mut self, value: T);
8490
}
8591

92+
impl WriteAs<UntypedVal> for UntypedVal {
93+
fn write_as(&mut self, value: UntypedVal) {
94+
*self = value;
95+
}
96+
}
97+
8698
macro_rules! impl_write_as_for_int {
8799
( $( $int:ty as $as:ty ),* $(,)? ) => {
88100
$(

crates/fuzz/src/oracle/wasmi.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -166,16 +166,16 @@ impl From<wasmi::Error> for FuzzError {
166166
return FuzzError::Other;
167167
};
168168
let trap_code = match trap_code {
169-
TrapCode::UnreachableCodeReached => crate::TrapCode::UnreachableCodeReached,
170-
TrapCode::MemoryOutOfBounds => crate::TrapCode::MemoryOutOfBounds,
171-
TrapCode::TableOutOfBounds => crate::TrapCode::TableOutOfBounds,
172-
TrapCode::IndirectCallToNull => crate::TrapCode::IndirectCallToNull,
173-
TrapCode::IntegerDivisionByZero => crate::TrapCode::IntegerDivisionByZero,
174-
TrapCode::IntegerOverflow => crate::TrapCode::IntegerOverflow,
175-
TrapCode::BadConversionToInteger => crate::TrapCode::BadConversionToInteger,
176-
TrapCode::StackOverflow => crate::TrapCode::StackOverflow,
177-
TrapCode::BadSignature => crate::TrapCode::BadSignature,
178-
TrapCode::OutOfFuel | TrapCode::GrowthOperationLimited => return FuzzError::Other,
169+
| TrapCode::UnreachableCodeReached => crate::TrapCode::UnreachableCodeReached,
170+
| TrapCode::MemoryOutOfBounds => crate::TrapCode::MemoryOutOfBounds,
171+
| TrapCode::TableOutOfBounds => crate::TrapCode::TableOutOfBounds,
172+
| TrapCode::IndirectCallToNull => crate::TrapCode::IndirectCallToNull,
173+
| TrapCode::IntegerDivisionByZero => crate::TrapCode::IntegerDivisionByZero,
174+
| TrapCode::IntegerOverflow => crate::TrapCode::IntegerOverflow,
175+
| TrapCode::BadConversionToInteger => crate::TrapCode::BadConversionToInteger,
176+
| TrapCode::StackOverflow => crate::TrapCode::StackOverflow,
177+
| TrapCode::BadSignature => crate::TrapCode::BadSignature,
178+
| TrapCode::OutOfFuel | TrapCode::GrowthOperationLimited => return FuzzError::Other,
179179
};
180180
FuzzError::Trap(trap_code)
181181
}

crates/ir2/build/display/op_code.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ impl Display for DisplayOpCode<&'_ Isa> {
7575
\n\
7676
{indent}impl TryFrom<u16> for OpCode {{\n\
7777
{indent} type Error = InvalidOpCode;\n\
78+
{indent} #[inline(always)]
7879
{indent} fn try_from(value: u16) -> Result<Self, Self::Error> {{\n\
7980
{indent} let op_code = match value {{\n\
8081
{match_arms_tryfrom},\n\

crates/ir2/build/op.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2150,7 +2150,7 @@ impl TableSetOp {
21502150
}
21512151

21522152
pub fn fields(&self) -> [Field; 3] {
2153-
[self.index_field(), self.value_field(), self.table_field()]
2153+
[self.table_field(), self.index_field(), self.value_field()]
21542154
}
21552155
}
21562156

crates/ir2/src/decode/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ macro_rules! impl_decode_fallible_using {
169169
( $($ty:ty as $as:ty = $e:expr),* $(,)? ) => {
170170
$(
171171
impl Decode for $ty {
172+
#[inline(always)]
172173
fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError> {
173174
$e(<$as as Decode>::decode(decoder)?)
174175
}

crates/ir2/src/index.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ macro_rules! define_index {
6262
}
6363
for_each_index!(define_index);
6464

65+
impl From<Memory> for u32 {
66+
fn from(value: Memory) -> Self {
67+
u32::from(value.0)
68+
}
69+
}
70+
6571
impl TryFrom<u32> for Memory {
6672
type Error = Error;
6773

0 commit comments

Comments
 (0)