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