Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preventing temporary segments generation for testing. #6641

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 segments so finalization of segment arena may not occur.
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 @@ -205,6 +205,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
Loading