1
+ use std:: sync:: Arc ;
2
+
1
3
use derive_new:: new;
2
4
use openvm_circuit:: system:: memory:: MemoryTraceHeights ;
3
5
use openvm_instructions:: program:: DEFAULT_MAX_NUM_PUBLIC_VALUES ;
@@ -13,12 +15,12 @@ pub use super::testing::{
13
15
POSEIDON2_DIRECT_BUS , RANGE_TUPLE_CHECKER_BUS , READ_INSTRUCTION_BUS ,
14
16
} ;
15
17
use super :: {
18
+ segment:: { DefaultSegmentationStrategy , SegmentationStrategy } ,
16
19
AnyEnum , InstructionExecutor , SystemComplex , SystemExecutor , SystemPeriphery , VmChipComplex ,
17
20
VmInventoryError , PUBLIC_VALUES_AIR_ID ,
18
21
} ;
19
22
use crate :: system:: memory:: BOUNDARY_AIR_OFFSET ;
20
23
21
- const DEFAULT_MAX_SEGMENT_LEN : usize = ( 1 << 22 ) - 100 ;
22
24
// sbox is decomposed to have this max degree for Poseidon2. We set to 3 so quotient_degree = 2
23
25
// allows log_blowup = 1
24
26
const DEFAULT_POSEIDON2_MAX_CONSTRAINT_DEGREE : usize = 3 ;
@@ -86,11 +88,18 @@ pub struct SystemConfig {
86
88
/// cannot read public values directly, but they can decommit the public values from the memory
87
89
/// merkle root.
88
90
pub num_public_values : usize ,
89
- /// When continuations are enabled, a heuristic used to determine when to segment execution.
90
- pub max_segment_len : usize ,
91
91
/// Whether to collect detailed profiling metrics.
92
92
/// **Warning**: this slows down the runtime.
93
93
pub profiling : bool ,
94
+ /// Segmentation strategy
95
+ /// This field is skipped in serde as it's only used in execution and
96
+ /// not needed after any serialize/deserialize.
97
+ #[ serde( skip, default = "get_default_segmentation_strategy" ) ]
98
+ pub segmentation_strategy : Arc < dyn SegmentationStrategy > ,
99
+ }
100
+
101
+ pub fn get_default_segmentation_strategy ( ) -> Arc < dyn SegmentationStrategy > {
102
+ Arc :: new ( DefaultSegmentationStrategy :: default ( ) )
94
103
}
95
104
96
105
#[ derive( Debug , Clone , Serialize , Deserialize , PartialEq , Eq ) ]
@@ -105,12 +114,13 @@ impl SystemConfig {
105
114
memory_config : MemoryConfig ,
106
115
num_public_values : usize ,
107
116
) -> Self {
117
+ let segmentation_strategy = get_default_segmentation_strategy ( ) ;
108
118
Self {
109
119
max_constraint_degree,
110
120
continuation_enabled : false ,
111
121
memory_config,
112
122
num_public_values,
113
- max_segment_len : DEFAULT_MAX_SEGMENT_LEN ,
123
+ segmentation_strategy ,
114
124
profiling : false ,
115
125
}
116
126
}
@@ -136,10 +146,16 @@ impl SystemConfig {
136
146
}
137
147
138
148
pub fn with_max_segment_len ( mut self , max_segment_len : usize ) -> Self {
139
- self . max_segment_len = max_segment_len;
149
+ self . segmentation_strategy = Arc :: new (
150
+ DefaultSegmentationStrategy :: new_with_max_segment_len ( max_segment_len) ,
151
+ ) ;
140
152
self
141
153
}
142
154
155
+ pub fn set_segmentation_strategy < S : SegmentationStrategy + ' static > ( & mut self , strategy : S ) {
156
+ self . segmentation_strategy = Arc :: new ( strategy) ;
157
+ }
158
+
143
159
pub fn with_profiling ( mut self ) -> Self {
144
160
self . profiling = true ;
145
161
self
0 commit comments