Skip to content

Commit

Permalink
Preventing temporary segments generation for testing.
Browse files Browse the repository at this point in the history
commit-id:c7159ee0
  • Loading branch information
orizi committed Nov 12, 2024
1 parent 5bbc6a7 commit a1bc5d7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
8 changes: 6 additions & 2 deletions crates/cairo-lang-runner/src/casm_run/dict_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,14 @@ impl DictManagerExecScope {
pub const DICT_DEFAULT_VALUE: usize = 0;

/// Allocates a new segment for a new dictionary and return the start of the segment.
pub fn new_default_dict(&mut self, vm: &mut VirtualMachine) -> Relocatable {
pub fn new_default_dict(
&mut self,
vm: &mut VirtualMachine,
no_temporary_segments: bool,
) -> Relocatable {
// If we are not on the first segment - using a temporary segments to later be merged into
// the previous segments.
let dict_segment = if self.trackers.is_empty() {
let dict_segment = if self.trackers.is_empty() || no_temporary_segments {
vm.add_memory_segment()
} else {
vm.add_temporary_segment()
Expand Down
16 changes: 13 additions & 3 deletions crates/cairo-lang-runner/src/casm_run/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ pub struct CairoHintProcessor<'a> {
/// Resources used during syscalls - does not include resources used during the current VM run.
/// At the end of the run - adding both would result in the actual expected resource usage.
pub syscalls_used_resources: StarknetExecutionResources,
/// Avoid allocating memory segements so finalization of segment arena may not occur.

Check warning on line 103 in crates/cairo-lang-runner/src/casm_run/mod.rs

View workflow job for this annotation

GitHub Actions / typos

"segements" should be "segments".
pub no_temporary_segments: bool,
}

pub fn cell_ref_to_relocatable(cell_ref: &CellRef, vm: &VirtualMachine) -> Relocatable {
Expand Down Expand Up @@ -421,7 +423,12 @@ impl HintProcessorLogic for CairoHintProcessor<'_> {
let hint = match hint {
Hint::Starknet(hint) => hint,
Hint::Core(core_hint_base) => {
return execute_core_hint_base(vm, exec_scopes, core_hint_base);
return execute_core_hint_base(
vm,
exec_scopes,
core_hint_base,
self.no_temporary_segments,
);
}
Hint::External(hint) => {
return self.execute_external_hint(vm, hint);
Expand Down Expand Up @@ -1649,10 +1656,11 @@ pub fn execute_core_hint_base(
vm: &mut VirtualMachine,
exec_scopes: &mut ExecutionScopes,
core_hint_base: &cairo_lang_casm::hints::CoreHintBase,
no_temporary_segments: bool,
) -> Result<(), HintError> {
match core_hint_base {
cairo_lang_casm::hints::CoreHintBase::Core(core_hint) => {
execute_core_hint(vm, exec_scopes, core_hint)
execute_core_hint(vm, exec_scopes, core_hint, no_temporary_segments)
}
cairo_lang_casm::hints::CoreHintBase::Deprecated(deprecated_hint) => {
execute_deprecated_hint(vm, exec_scopes, deprecated_hint)
Expand Down Expand Up @@ -1723,6 +1731,7 @@ pub fn execute_core_hint(
vm: &mut VirtualMachine,
exec_scopes: &mut ExecutionScopes,
core_hint: &CoreHint,
no_temporary_segments: bool,
) -> Result<(), HintError> {
match core_hint {
CoreHint::AllocSegment { dst } => {
Expand Down Expand Up @@ -1921,7 +1930,8 @@ pub fn execute_core_hint(
exec_scopes.get_mut_ref::<DictManagerExecScope>("dict_manager_exec_scope")?
}
};
let new_dict_segment = dict_manager_exec_scope.new_default_dict(vm);
let new_dict_segment =
dict_manager_exec_scope.new_default_dict(vm, no_temporary_segments);
vm.insert_value((dict_infos_base + 3 * n_dicts)?, new_dict_segment)?;
}
CoreHint::Felt252DictEntryInit { dict_ptr, key } => {
Expand Down
2 changes: 2 additions & 0 deletions crates/cairo-lang-runner/src/casm_run/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ fn test_runner(function: CasmContext, n_returns: usize, expected: &[i128]) {
starknet_state: StarknetState::default(),
run_resources: RunResources::default(),
syscalls_used_resources: Default::default(),
no_temporary_segments: true,
};

let RunFunctionResult { ap, memory, .. } =
Expand Down Expand Up @@ -157,6 +158,7 @@ fn test_allocate_segment() {
starknet_state: StarknetState::default(),
run_resources: RunResources::default(),
syscalls_used_resources: Default::default(),
no_temporary_segments: true,
};

let RunFunctionResult { ap, memory, .. } =
Expand Down
1 change: 1 addition & 0 deletions crates/cairo-lang-runner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ impl SierraCasmRunner {
string_to_hint,
run_resources: RunResources::default(),
syscalls_used_resources: Default::default(),
no_temporary_segments: true,
};
let RunResult { gas_counter, memory, value, used_resources, profiling_info } = self
.run_function(
Expand Down

0 comments on commit a1bc5d7

Please sign in to comment.