Skip to content

Commit 55a7ea5

Browse files
make ValidationRules clonable, without API breakage
1 parent 2a4792c commit 55a7ea5

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use crate::{
33
stdlib::{
44
cmp::{max, min},
55
prelude::*,
6-
rc::Rc,
76
},
87
types::{builtin_name::BuiltinName, instance_definitions::LowRatio},
98
};
@@ -107,7 +106,7 @@ impl<const N_PARTS: u64> RangeCheckBuiltinRunner<N_PARTS> {
107106
}
108107

109108
pub fn add_validation_rule(&self, memory: &mut Memory) {
110-
let rule = ValidationRule(Rc::new(
109+
let rule = ValidationRule(Box::new(
111110
|memory: &Memory, address: Relocatable| -> Result<Vec<Relocatable>, MemoryError> {
112111
let num = memory
113112
.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(Rc::new(
99+
let rule: ValidationRule = ValidationRule(Box::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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ use bitvec::prelude as bv;
1212
use core::cmp::Ordering;
1313
use num_traits::ToPrimitive;
1414

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

2120
/// [`MemoryCell`] represents an optimized storage layout for the VM memory.
@@ -174,7 +173,7 @@ pub struct Memory {
174173
#[cfg(feature = "extensive_hints")]
175174
pub(crate) relocation_rules: HashMap<usize, MaybeRelocatable>,
176175
pub validated_addresses: AddressSet,
177-
validation_rules: Vec<Option<ValidationRule>>,
176+
validation_rules: Vec<Option<Rc<ValidationRule>>>,
178177
}
179178

180179
impl Memory {
@@ -501,7 +500,8 @@ impl Memory {
501500
self.validation_rules
502501
.resize_with(segment_index + 1, || None);
503502
}
504-
self.validation_rules.insert(segment_index, Some(rule));
503+
self.validation_rules
504+
.insert(segment_index, Some(Rc::new(rule)));
505505
}
506506

507507
fn validate_memory_cell(&mut self, addr: Relocatable) -> Result<(), MemoryError> {

0 commit comments

Comments
 (0)