Skip to content

Commit fd093e7

Browse files
Make fields clonable
1 parent 065c8f4 commit fd093e7

File tree

8 files changed

+13
-8
lines changed

8 files changed

+13
-8
lines changed

vm/src/types/instance_definitions/builtins_instance_def.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub(crate) const BUILTIN_INSTANCES_PER_COMPONENT: u32 = 1;
1313

1414
use serde::Serialize;
1515

16-
#[derive(Serialize, Debug, PartialEq)]
16+
#[derive(Clone, Serialize, Debug, PartialEq)]
1717
pub(crate) struct BuiltinsInstanceDef {
1818
pub(crate) output: bool,
1919
pub(crate) pedersen: Option<PedersenInstanceDef>,

vm/src/types/instance_definitions/diluted_pool_instance_def.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use serde::Serialize;
22

3-
#[derive(Serialize, Debug, PartialEq)]
3+
#[derive(Clone, Serialize, Debug, PartialEq)]
44
pub(crate) struct DilutedPoolInstanceDef {
55
pub(crate) units_per_step: u32, // 2 ^ log_units_per_step (for cairo_lang comparison)
66
pub(crate) fractional_units_per_step: bool, // true when log_units_per_step is negative

vm/src/types/instance_definitions/range_check_instance_def.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use serde::Serialize;
33
use super::LowRatio;
44
pub(crate) const CELLS_PER_RANGE_CHECK: u32 = 1;
55

6-
#[derive(Serialize, Debug, PartialEq)]
6+
#[derive(Clone, Serialize, Debug, PartialEq)]
77
pub(crate) struct RangeCheckInstanceDef {
88
pub(crate) ratio: Option<LowRatio>,
99
}

vm/src/types/layout.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub(crate) const DEFAULT_CPU_COMPONENT_STEP: u32 = 1;
1313

1414
use serde::{Deserialize, Deserializer, Serialize};
1515

16-
#[derive(Serialize, Debug)]
16+
#[derive(Clone, Serialize, Debug)]
1717
pub struct CairoLayout {
1818
pub(crate) name: LayoutName,
1919
pub(crate) cpu_component_step: u32,

vm/src/vm/runners/builtin_runner/range_check.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::{
33
stdlib::{
44
cmp::{max, min},
55
prelude::*,
6+
rc::Rc,
67
},
78
types::{builtin_name::BuiltinName, instance_definitions::LowRatio},
89
};
@@ -106,7 +107,7 @@ impl<const N_PARTS: u64> RangeCheckBuiltinRunner<N_PARTS> {
106107
}
107108

108109
pub fn add_validation_rule(&self, memory: &mut Memory) {
109-
let rule = ValidationRule(Box::new(
110+
let rule = ValidationRule(Rc::new(
110111
|memory: &Memory, address: Relocatable| -> Result<Vec<Relocatable>, MemoryError> {
111112
let num = memory
112113
.get_integer(address)

vm/src/vm/runners/builtin_runner/signature.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl SignatureBuiltinRunner {
9696
pub fn add_validation_rule(&self, memory: &mut Memory) {
9797
let cells_per_instance = CELLS_PER_SIGNATURE;
9898
let signatures = Rc::clone(&self.signatures);
99-
let rule: ValidationRule = ValidationRule(Box::new(
99+
let rule: ValidationRule = ValidationRule(Rc::new(
100100
move |memory: &Memory, addr: Relocatable| -> Result<Vec<Relocatable>, MemoryError> {
101101
let cell_index = addr.offset % cells_per_instance as usize;
102102

vm/src/vm/vm_memory/memory.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::stdlib::{borrow::Cow, collections::HashMap, fmt, prelude::*};
1+
use crate::stdlib::{borrow::Cow, collections::HashMap, fmt, prelude::*, rc::Rc};
22

33
use crate::types::errors::math_errors::MathError;
44
use crate::vm::runners::cairo_pie::CairoPieMemory;
@@ -12,9 +12,10 @@ use bitvec::prelude as bv;
1212
use core::cmp::Ordering;
1313
use num_traits::ToPrimitive;
1414

15+
#[derive(Clone)]
1516
pub struct ValidationRule(
1617
#[allow(clippy::type_complexity)]
17-
pub Box<dyn Fn(&Memory, Relocatable) -> Result<Vec<Relocatable>, MemoryError>>,
18+
pub Rc<dyn Fn(&Memory, Relocatable) -> Result<Vec<Relocatable>, MemoryError>>,
1819
);
1920

2021
/// [`MemoryCell`] represents an optimized storage layout for the VM memory.
@@ -106,6 +107,7 @@ impl From<MemoryCell> for MaybeRelocatable {
106107
}
107108
}
108109

110+
#[derive(Clone)]
109111
pub struct AddressSet(Vec<bv::BitVec>);
110112

111113
impl AddressSet {
@@ -156,6 +158,7 @@ impl AddressSet {
156158
}
157159
}
158160

161+
#[derive(Clone)]
159162
pub struct Memory {
160163
pub(crate) data: Vec<Vec<MemoryCell>>,
161164
/// Temporary segments are used when it's necessary to write data, but we

vm/src/vm/vm_memory/memory_segments.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use crate::{
2020

2121
use super::memory::MemoryCell;
2222

23+
#[derive(Clone)]
2324
pub struct MemorySegmentManager {
2425
pub segment_sizes: HashMap<usize, usize>,
2526
pub segment_used_sizes: Option<Vec<usize>>,

0 commit comments

Comments
 (0)