Skip to content

Commit b918f9b

Browse files
grandizzymattssezerosnacks
authored
v1.3.0: revert perf update, backport anvil fixes (foundry-rs#11150)
* Revert "v1.3.0: backport perf improvements and anvil fixes (foundry-rs#11136)" This reverts commit 13ca215. * fix: use existing functions for accountinfo (foundry-rs#11134) * fix(`anvil`): unwrap panic in `eth/backend/mem/mod.rs` (foundry-rs#11141) make typed request casting not panic and return useful error to user --------- Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de> Co-authored-by: zerosnacks <95942363+zerosnacks@users.noreply.github.com>
1 parent 13ca215 commit b918f9b

File tree

5 files changed

+40
-48
lines changed

5 files changed

+40
-48
lines changed

crates/cheatcodes/src/inspector.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ pub trait CheatcodesExecutor {
111111
}
112112

113113
/// Returns a mutable reference to the tracing inspector if it is available.
114-
fn tracing_inspector(&mut self) -> Option<&mut Option<Box<TracingInspector>>> {
114+
fn tracing_inspector(&mut self) -> Option<&mut Option<TracingInspector>> {
115115
None
116116
}
117117
}

crates/evm/evm/src/executors/invariant/mod.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -609,11 +609,8 @@ impl<'a> InvariantExecutor<'a> {
609609
));
610610
}
611611

612-
self.executor.inspector_mut().set_fuzzer(Fuzzer {
613-
call_generator,
614-
fuzz_state: fuzz_state.clone(),
615-
collect: true,
616-
});
612+
self.executor.inspector_mut().fuzzer =
613+
Some(Fuzzer { call_generator, fuzz_state: fuzz_state.clone(), collect: true });
617614

618615
// Let's make sure the invariant is sound before actually starting the run:
619616
// We'll assert the invariant in its initial state, and if it fails, we'll

crates/evm/evm/src/executors/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ pub struct RawCallResult {
842842
/// The `revm::Env` after the call
843843
pub env: Env,
844844
/// The cheatcode states after execution
845-
pub cheatcodes: Option<Box<Cheatcodes>>,
845+
pub cheatcodes: Option<Cheatcodes>,
846846
/// The raw output of the execution
847847
pub out: Option<Output>,
848848
/// The chisel state

crates/evm/evm/src/inspectors/stack.rs

Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ pub struct InspectorData {
262262
pub traces: Option<SparsedTraceArena>,
263263
pub line_coverage: Option<HitMaps>,
264264
pub edge_coverage: Option<Vec<u8>>,
265-
pub cheatcodes: Option<Box<Cheatcodes>>,
265+
pub cheatcodes: Option<Cheatcodes>,
266266
pub chisel_state: Option<(Vec<U256>, Vec<u8>, Option<InstructionResult>)>,
267267
pub reverter: Option<Address>,
268268
}
@@ -290,7 +290,7 @@ pub struct InnerContextData {
290290
/// collection, etc.
291291
#[derive(Clone, Debug, Default)]
292292
pub struct InspectorStack {
293-
pub cheatcodes: Option<Box<Cheatcodes>>,
293+
pub cheatcodes: Option<Cheatcodes>,
294294
pub inner: InspectorStackInner,
295295
}
296296

@@ -300,17 +300,15 @@ pub struct InspectorStack {
300300
#[derive(Default, Clone, Debug)]
301301
pub struct InspectorStackInner {
302302
// 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>,
314312

315313
// InspectorExt and other internal data.
316314
pub enable_isolation: bool,
@@ -337,7 +335,7 @@ impl CheatcodesExecutor for InspectorStackInner {
337335
Box::new(InspectorStackRefMut { cheatcodes: Some(cheats), inner: self })
338336
}
339337

340-
fn tracing_inspector(&mut self) -> Option<&mut Option<Box<TracingInspector>>> {
338+
fn tracing_inspector(&mut self) -> Option<&mut Option<TracingInspector>> {
341339
Some(&mut self.tracer)
342340
}
343341
}
@@ -400,19 +398,19 @@ impl InspectorStack {
400398
/// Set the cheatcodes inspector.
401399
#[inline]
402400
pub fn set_cheatcodes(&mut self, cheatcodes: Cheatcodes) {
403-
self.cheatcodes = Some(cheatcodes.into());
401+
self.cheatcodes = Some(cheatcodes);
404402
}
405403

406404
/// Set the fuzzer inspector.
407405
#[inline]
408406
pub fn set_fuzzer(&mut self, fuzzer: Fuzzer) {
409-
self.fuzzer = Some(fuzzer.into());
407+
self.fuzzer = Some(fuzzer);
410408
}
411409

412410
/// Set the Chisel inspector.
413411
#[inline]
414412
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));
416414
}
417415

418416
/// Set whether to enable the line coverage collector.
@@ -424,8 +422,7 @@ impl InspectorStack {
424422
/// Set whether to enable the edge coverage collector.
425423
#[inline]
426424
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?
429426
}
430427

431428
/// Set whether to enable call isolation.
@@ -462,7 +459,11 @@ impl InspectorStack {
462459
/// Revert diagnostic inspector is activated when `mode != TraceMode::None`
463460
#[inline]
464461
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+
}
466467

467468
if let Some(config) = mode.into_config() {
468469
*self.tracer.get_or_insert_with(Default::default).config_mut() = config;
@@ -479,6 +480,7 @@ impl InspectorStack {
479480
}
480481

481482
/// Collects all the data gathered during inspection into a single struct.
483+
#[inline]
482484
pub fn collect(self) -> InspectorData {
483485
let Self {
484486
mut cheatcodes,
@@ -529,7 +531,7 @@ impl InspectorStack {
529531

530532
#[inline(always)]
531533
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 }
533535
}
534536
}
535537

@@ -738,16 +740,17 @@ impl InspectorStackRefMut<'_> {
738740
/// it.
739741
fn with_stack<O>(&mut self, f: impl FnOnce(&mut InspectorStack) -> O) -> O {
740742
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()))),
744747
inner: std::mem::take(self.inner),
745748
};
746749

747750
let out = f(&mut stack);
748751

749752
if let Some(cheats) = self.cheatcodes.as_deref_mut() {
750-
*cheats = *stack.cheatcodes.take().unwrap();
753+
*cheats = stack.cheatcodes.take().unwrap();
751754
}
752755

753756
*self.inner = stack.inner;
@@ -788,11 +791,6 @@ impl InspectorStackRefMut<'_> {
788791
}
789792
}
790793

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-
796794
#[inline(always)]
797795
fn step_inlined(
798796
&mut self,
@@ -801,18 +799,17 @@ impl InspectorStackRefMut<'_> {
801799
) {
802800
call_inspectors!(
803801
[
804-
// These are sorted in definition order.
805-
&mut self.edge_coverage,
806802
&mut self.fuzzer,
803+
&mut self.tracer,
807804
&mut self.line_coverage,
805+
&mut self.edge_coverage,
806+
&mut self.script_execution_inspector,
808807
&mut self.printer,
809808
&mut self.revert_diag,
810-
&mut self.script_execution_inspector,
811-
&mut self.tracer,
812809
// Keep `cheatcodes` last to make use of the tail call.
813810
&mut self.cheatcodes,
814811
],
815-
|inspector| (**inspector).step(interpreter, ecx),
812+
|inspector| (*inspector).step(interpreter, ecx),
816813
);
817814
}
818815

@@ -824,15 +821,14 @@ impl InspectorStackRefMut<'_> {
824821
) {
825822
call_inspectors!(
826823
[
827-
// These are sorted in definition order.
824+
&mut self.tracer,
828825
&mut self.chisel_state,
829826
&mut self.printer,
830827
&mut self.revert_diag,
831-
&mut self.tracer,
832828
// Keep `cheatcodes` last to make use of the tail call.
833829
&mut self.cheatcodes,
834830
],
835-
|inspector| (**inspector).step_end(interpreter, ecx),
831+
|inspector| (*inspector).step_end(interpreter, ecx),
836832
);
837833
}
838834
}

crates/evm/fuzz/src/inspector.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ use revm::{
99
/// An inspector that can fuzz and collect data for that effect.
1010
#[derive(Clone, Debug)]
1111
pub struct Fuzzer {
12-
/// If set, it collects `stack` and `memory` values for fuzzing purposes.
13-
pub collect: bool,
1412
/// Given a strategy, it generates a random call.
1513
pub call_generator: Option<RandomCallGenerator>,
14+
/// If set, it collects `stack` and `memory` values for fuzzing purposes.
15+
pub collect: bool,
1616
/// If `collect` is set, we store the collected values in this fuzz dictionary.
1717
pub fuzz_state: EvmFuzzState,
1818
}
@@ -21,7 +21,6 @@ impl<CTX> Inspector<CTX> for Fuzzer
2121
where
2222
CTX: ContextTr<Journal: JournalExt>,
2323
{
24-
#[inline]
2524
fn step(&mut self, interp: &mut Interpreter, _context: &mut CTX) {
2625
// We only collect `stack` and `memory` data before and after calls.
2726
if self.collect {

0 commit comments

Comments
 (0)