@@ -262,7 +262,7 @@ pub struct InspectorData {
262
262
pub traces : Option < SparsedTraceArena > ,
263
263
pub line_coverage : Option < HitMaps > ,
264
264
pub edge_coverage : Option < Vec < u8 > > ,
265
- pub cheatcodes : Option < Box < Cheatcodes > > ,
265
+ pub cheatcodes : Option < Cheatcodes > ,
266
266
pub chisel_state : Option < ( Vec < U256 > , Vec < u8 > , Option < InstructionResult > ) > ,
267
267
pub reverter : Option < Address > ,
268
268
}
@@ -290,7 +290,7 @@ pub struct InnerContextData {
290
290
/// collection, etc.
291
291
#[ derive( Clone , Debug , Default ) ]
292
292
pub struct InspectorStack {
293
- pub cheatcodes : Option < Box < Cheatcodes > > ,
293
+ pub cheatcodes : Option < Cheatcodes > ,
294
294
pub inner : InspectorStackInner ,
295
295
}
296
296
@@ -300,17 +300,15 @@ pub struct InspectorStack {
300
300
#[ derive( Default , Clone , Debug ) ]
301
301
pub struct InspectorStackInner {
302
302
// Inspectors.
303
- // These are boxed to reduce the size of the struct and slightly improve performance of the
304
- // `if let Some` checks.
305
- pub chisel_state : Option < Box < ChiselState > > ,
306
- pub edge_coverage : Option < Box < EdgeCovInspector > > ,
307
- pub fuzzer : Option < Box < Fuzzer > > ,
308
- pub line_coverage : Option < Box < LineCoverageCollector > > ,
309
- pub log_collector : Option < Box < LogCollector > > ,
310
- pub printer : Option < Box < CustomPrintTracer > > ,
311
- pub revert_diag : Option < Box < RevertDiagnostic > > ,
312
- pub script_execution_inspector : Option < Box < ScriptExecutionInspector > > ,
313
- pub tracer : Option < Box < TracingInspector > > ,
303
+ pub chisel_state : Option < ChiselState > ,
304
+ pub edge_coverage : Option < EdgeCovInspector > ,
305
+ pub fuzzer : Option < Fuzzer > ,
306
+ pub line_coverage : Option < LineCoverageCollector > ,
307
+ pub log_collector : Option < LogCollector > ,
308
+ pub printer : Option < CustomPrintTracer > ,
309
+ pub revert_diag : Option < RevertDiagnostic > ,
310
+ pub script_execution_inspector : Option < ScriptExecutionInspector > ,
311
+ pub tracer : Option < TracingInspector > ,
314
312
315
313
// InspectorExt and other internal data.
316
314
pub enable_isolation : bool ,
@@ -337,7 +335,7 @@ impl CheatcodesExecutor for InspectorStackInner {
337
335
Box :: new ( InspectorStackRefMut { cheatcodes : Some ( cheats) , inner : self } )
338
336
}
339
337
340
- fn tracing_inspector ( & mut self ) -> Option < & mut Option < Box < TracingInspector > > > {
338
+ fn tracing_inspector ( & mut self ) -> Option < & mut Option < TracingInspector > > {
341
339
Some ( & mut self . tracer )
342
340
}
343
341
}
@@ -400,19 +398,19 @@ impl InspectorStack {
400
398
/// Set the cheatcodes inspector.
401
399
#[ inline]
402
400
pub fn set_cheatcodes ( & mut self , cheatcodes : Cheatcodes ) {
403
- self . cheatcodes = Some ( cheatcodes. into ( ) ) ;
401
+ self . cheatcodes = Some ( cheatcodes) ;
404
402
}
405
403
406
404
/// Set the fuzzer inspector.
407
405
#[ inline]
408
406
pub fn set_fuzzer ( & mut self , fuzzer : Fuzzer ) {
409
- self . fuzzer = Some ( fuzzer. into ( ) ) ;
407
+ self . fuzzer = Some ( fuzzer) ;
410
408
}
411
409
412
410
/// Set the Chisel inspector.
413
411
#[ inline]
414
412
pub fn set_chisel ( & mut self , final_pc : usize ) {
415
- self . chisel_state = Some ( ChiselState :: new ( final_pc) . into ( ) ) ;
413
+ self . chisel_state = Some ( ChiselState :: new ( final_pc) ) ;
416
414
}
417
415
418
416
/// Set whether to enable the line coverage collector.
@@ -424,8 +422,7 @@ impl InspectorStack {
424
422
/// Set whether to enable the edge coverage collector.
425
423
#[ inline]
426
424
pub fn collect_edge_coverage ( & mut self , yes : bool ) {
427
- // TODO: configurable edge size?
428
- self . edge_coverage = yes. then ( EdgeCovInspector :: new) . map ( Into :: into) ;
425
+ self . edge_coverage = yes. then ( EdgeCovInspector :: new) ; // TODO configurable edge size?
429
426
}
430
427
431
428
/// Set whether to enable call isolation.
@@ -462,7 +459,11 @@ impl InspectorStack {
462
459
/// Revert diagnostic inspector is activated when `mode != TraceMode::None`
463
460
#[ inline]
464
461
pub fn tracing ( & mut self , mode : TraceMode ) {
465
- self . revert_diag = ( !mode. is_none ( ) ) . then ( RevertDiagnostic :: default) . map ( Into :: into) ;
462
+ if mode. is_none ( ) {
463
+ self . revert_diag = None ;
464
+ } else {
465
+ self . revert_diag = Some ( RevertDiagnostic :: default ( ) ) ;
466
+ }
466
467
467
468
if let Some ( config) = mode. into_config ( ) {
468
469
* self . tracer . get_or_insert_with ( Default :: default) . config_mut ( ) = config;
@@ -479,6 +480,7 @@ impl InspectorStack {
479
480
}
480
481
481
482
/// Collects all the data gathered during inspection into a single struct.
483
+ #[ inline]
482
484
pub fn collect ( self ) -> InspectorData {
483
485
let Self {
484
486
mut cheatcodes,
@@ -529,7 +531,7 @@ impl InspectorStack {
529
531
530
532
#[ inline( always) ]
531
533
fn as_mut ( & mut self ) -> InspectorStackRefMut < ' _ > {
532
- InspectorStackRefMut { cheatcodes : self . cheatcodes . as_deref_mut ( ) , inner : & mut self . inner }
534
+ InspectorStackRefMut { cheatcodes : self . cheatcodes . as_mut ( ) , inner : & mut self . inner }
533
535
}
534
536
}
535
537
@@ -738,16 +740,17 @@ impl InspectorStackRefMut<'_> {
738
740
/// it.
739
741
fn with_stack < O > ( & mut self , f : impl FnOnce ( & mut InspectorStack ) -> O ) -> O {
740
742
let mut stack = InspectorStack {
741
- cheatcodes : self . cheatcodes . as_deref_mut ( ) . map ( |cheats| {
742
- core:: mem:: replace ( cheats, Cheatcodes :: new ( cheats. config . clone ( ) ) ) . into ( )
743
- } ) ,
743
+ cheatcodes : self
744
+ . cheatcodes
745
+ . as_deref_mut ( )
746
+ . map ( |cheats| core:: mem:: replace ( cheats, Cheatcodes :: new ( cheats. config . clone ( ) ) ) ) ,
744
747
inner : std:: mem:: take ( self . inner ) ,
745
748
} ;
746
749
747
750
let out = f ( & mut stack) ;
748
751
749
752
if let Some ( cheats) = self . cheatcodes . as_deref_mut ( ) {
750
- * cheats = * stack. cheatcodes . take ( ) . unwrap ( ) ;
753
+ * cheats = stack. cheatcodes . take ( ) . unwrap ( ) ;
751
754
}
752
755
753
756
* self . inner = stack. inner ;
@@ -788,11 +791,6 @@ impl InspectorStackRefMut<'_> {
788
791
}
789
792
}
790
793
791
- // We take extra care in optimizing `step` and `step_end`, as they're are likely the most
792
- // hot functions in all of Foundry.
793
- // We want to `#[inline(always)]` these functions so that `InspectorStack` does not
794
- // delegate to `InspectorStackRefMut` in this case.
795
-
796
794
#[ inline( always) ]
797
795
fn step_inlined (
798
796
& mut self ,
@@ -801,18 +799,17 @@ impl InspectorStackRefMut<'_> {
801
799
) {
802
800
call_inspectors ! (
803
801
[
804
- // These are sorted in definition order.
805
- & mut self . edge_coverage,
806
802
& mut self . fuzzer,
803
+ & mut self . tracer,
807
804
& mut self . line_coverage,
805
+ & mut self . edge_coverage,
806
+ & mut self . script_execution_inspector,
808
807
& mut self . printer,
809
808
& mut self . revert_diag,
810
- & mut self . script_execution_inspector,
811
- & mut self . tracer,
812
809
// Keep `cheatcodes` last to make use of the tail call.
813
810
& mut self . cheatcodes,
814
811
] ,
815
- |inspector| ( * * inspector) . step( interpreter, ecx) ,
812
+ |inspector| ( * inspector) . step( interpreter, ecx) ,
816
813
) ;
817
814
}
818
815
@@ -824,15 +821,14 @@ impl InspectorStackRefMut<'_> {
824
821
) {
825
822
call_inspectors ! (
826
823
[
827
- // These are sorted in definition order.
824
+ & mut self . tracer ,
828
825
& mut self . chisel_state,
829
826
& mut self . printer,
830
827
& mut self . revert_diag,
831
- & mut self . tracer,
832
828
// Keep `cheatcodes` last to make use of the tail call.
833
829
& mut self . cheatcodes,
834
830
] ,
835
- |inspector| ( * * inspector) . step_end( interpreter, ecx) ,
831
+ |inspector| ( * inspector) . step_end( interpreter, ecx) ,
836
832
) ;
837
833
}
838
834
}
0 commit comments