Skip to content

Commit a697f57

Browse files
avi-starkwareclaude
andcommitted
give AotWithProgram inherent run/run_with_profile methods
With the ContractExecutor enum gone, AotWithProgram exposes the same run() shape as AotContractExecutor directly, plus a profile-capturing run_with_profile(), so feature-flag builds can swap executor types without call-site changes. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 18cfe2d commit a697f57

2 files changed

Lines changed: 59 additions & 2 deletions

File tree

src/executor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
//! This module provides methods to execute the programs, either via JIT or compiled ahead
44
//! of time. It also provides a cache to avoid recompiling previously compiled programs.
55
6-
#[cfg(feature = "with-libfunc-profiling")]
7-
pub use self::libfunc_profile::AotWithProgram;
86
#[cfg(feature = "sierra-emu")]
97
pub use self::emu_contract_executor::EmuContractExecutor;
8+
#[cfg(feature = "with-libfunc-profiling")]
9+
pub use self::libfunc_profile::AotWithProgram;
1010
pub use self::{aot::AotNativeExecutor, contract::AotContractExecutor, jit::JitNativeExecutor};
1111
use crate::{
1212
arch::{AbiArgument, ValueWithInfoWrapper},

src/executor/libfunc_profile.rs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,63 @@ pub struct AotWithProgram {
2626
pub program: ArcProgram,
2727
}
2828

29+
impl AotWithProgram {
30+
/// Run the contract entry point identified by `selector`, discarding the profile.
31+
///
32+
/// Mirrors [`AotContractExecutor::run`] so the executor types are interchangeable at
33+
/// the call site. The run is still routed through the profiling bookkeeping: the
34+
/// executor's shared library is compiled with profiling instrumentation, and running
35+
/// it without a live profile slot makes every statement log a missing-profiler
36+
/// error. Use [`Self::run_with_profile`] to capture the profile instead.
37+
pub fn run(
38+
&self,
39+
selector: Felt,
40+
args: &[Felt],
41+
gas: u64,
42+
builtin_costs: Option<BuiltinCosts>,
43+
syscall_handler: impl StarknetSyscallHandler,
44+
) -> Result<ContractExecutionResult> {
45+
self.executor.run_with_libfunc_profile(
46+
&self.program,
47+
selector,
48+
args,
49+
gas,
50+
builtin_costs,
51+
syscall_handler,
52+
|_profile| {},
53+
)
54+
}
55+
56+
/// Like [`Self::run`] but hands the captured libfunc profile -- together with the
57+
/// program this executor was paired with -- to `on_profile` after the call returns
58+
/// successfully. The program is included so callers don't have to keep their own
59+
/// copy around just to resolve libfunc samples.
60+
pub fn run_with_profile<H, F>(
61+
&self,
62+
selector: Felt,
63+
args: &[Felt],
64+
gas: u64,
65+
builtin_costs: Option<BuiltinCosts>,
66+
syscall_handler: H,
67+
on_profile: F,
68+
) -> Result<ContractExecutionResult>
69+
where
70+
H: StarknetSyscallHandler,
71+
F: FnOnce(Profile, ArcProgram),
72+
{
73+
let program_for_cb = Arc::clone(&self.program);
74+
self.executor.run_with_libfunc_profile(
75+
&self.program,
76+
selector,
77+
args,
78+
gas,
79+
builtin_costs,
80+
syscall_handler,
81+
move |profile| on_profile(profile, program_for_cb),
82+
)
83+
}
84+
}
85+
2986
/// Process-wide lock that serializes *top-level* profiled runs across threads. The
3087
/// profiler hot-swaps a process-global symbol (`cairo_native__profiler__profile_id`);
3188
/// a concurrent thread would race on that write and on the [`LIBFUNC_PROFILE`] slot

0 commit comments

Comments
 (0)