File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -158,9 +158,14 @@ impl Engine {
158
158
#[ cfg( feature = "parallel-compilation" ) ]
159
159
{
160
160
use rayon:: prelude:: * ;
161
+ // If we collect into Result<Vec<B>, E> directly, the returned error is not
162
+ // deterministic, because any error could be returned early. So we first materialize
163
+ // all results in order and then return the first error deterministically, or Ok(_).
161
164
return input
162
165
. into_par_iter ( )
163
166
. map ( |a| f ( a) )
167
+ . collect :: < Vec < Result < B , E > > > ( )
168
+ . into_iter ( )
164
169
. collect :: < Result < Vec < B > , E > > ( ) ;
165
170
}
166
171
}
Original file line number Diff line number Diff line change @@ -534,3 +534,27 @@ fn concurrent_type_modifications_and_checks(config: &mut Config) -> Result<()> {
534
534
535
535
Ok ( ( ) )
536
536
}
537
+
538
+ #[ test]
539
+ #[ cfg_attr( miri, ignore) ]
540
+ fn validate_deterministic ( ) {
541
+ let mut faulty_wat = "(module " . to_string ( ) ;
542
+ for i in 0 ..100 {
543
+ faulty_wat. push_str ( & format ! (
544
+ "(func (export \" foo_{i}\" ) (result i64) (i64.add (i32.const 0) (i64.const 1)))"
545
+ ) ) ;
546
+ }
547
+ faulty_wat. push_str ( ")" ) ;
548
+ let binary = wat:: parse_str ( faulty_wat) . unwrap ( ) ;
549
+
550
+ let engine_parallel = Engine :: new ( & Config :: new ( ) . parallel_compilation ( true ) ) . unwrap ( ) ;
551
+ let result_parallel = Module :: validate ( & engine_parallel, & binary)
552
+ . unwrap_err ( )
553
+ . to_string ( ) ;
554
+
555
+ let engine_sequential = Engine :: new ( & Config :: new ( ) . parallel_compilation ( false ) ) . unwrap ( ) ;
556
+ let result_sequential = Module :: validate ( & engine_sequential, & binary)
557
+ . unwrap_err ( )
558
+ . to_string ( ) ;
559
+ assert_eq ! ( result_parallel, result_sequential) ;
560
+ }
You can’t perform that action at this time.
0 commit comments