@@ -8,6 +8,7 @@ use wasmer::wasmparser::{
8
8
9
9
use crate :: { VmError , VmResult } ;
10
10
11
+ #[ derive( Default ) ]
11
12
pub struct OpaqueDebug < T > ( pub T ) ;
12
13
13
14
impl < T > fmt:: Debug for OpaqueDebug < T > {
@@ -19,18 +20,18 @@ impl<T> fmt::Debug for OpaqueDebug<T> {
19
20
20
21
#[ derive( Debug ) ]
21
22
pub enum FunctionValidator < ' a > {
22
- Pending ( Vec < OpaqueDebug < ( FuncToValidate < ValidatorResources > , FunctionBody < ' a > ) > > ) ,
23
+ Pending ( OpaqueDebug < Vec < ( FuncToValidate < ValidatorResources > , FunctionBody < ' a > ) > > ) ,
23
24
Success ,
24
25
Error ( BinaryReaderError ) ,
25
26
}
26
27
27
28
impl < ' a > FunctionValidator < ' a > {
28
29
fn push ( & mut self , item : ( FuncToValidate < ValidatorResources > , FunctionBody < ' a > ) ) {
29
- let Self :: Pending ( ref mut funcs) = self else {
30
+ let Self :: Pending ( OpaqueDebug ( ref mut funcs) ) = self else {
30
31
panic ! ( "attempted to push function into non-pending validator" ) ;
31
32
} ;
32
33
33
- funcs. push ( OpaqueDebug ( item) ) ;
34
+ funcs. push ( item) ;
34
35
}
35
36
}
36
37
@@ -97,7 +98,7 @@ impl<'a> ParsedWasm<'a> {
97
98
max_func_params : 0 ,
98
99
max_func_results : 0 ,
99
100
total_func_params : 0 ,
100
- func_validator : FunctionValidator :: Pending ( Vec :: new ( ) ) ,
101
+ func_validator : FunctionValidator :: Pending ( OpaqueDebug :: default ( ) ) ,
101
102
} ;
102
103
103
104
for p in Parser :: new ( 0 ) . parse_all ( wasm) {
@@ -181,10 +182,10 @@ impl<'a> ParsedWasm<'a> {
181
182
/// Note: This function caches the output of this function into the field `funcs_to_validate` so repeated invocations are cheap.
182
183
pub fn validate_funcs ( & mut self ) -> VmResult < ( ) > {
183
184
match self . func_validator {
184
- FunctionValidator :: Pending ( ref mut funcs) => {
185
+ FunctionValidator :: Pending ( OpaqueDebug ( ref mut funcs) ) => {
185
186
let result = mem:: take ( funcs) // This is fine since `Vec::default()` doesn't allocate
186
187
. into_par_iter ( )
187
- . try_for_each ( |OpaqueDebug ( ( func, body) ) | {
188
+ . try_for_each ( |( func, body) | {
188
189
// Reusing the allocations between validations only results in an ~6% performance improvement
189
190
// The parallelization is blowing this out of the water by a magnitude of 5x
190
191
// Especially when combining this with a high-performance allocator, the missing buffer reuse will be pretty much irrelevant
0 commit comments