1pub mod arrow_ingest;
6pub mod eval;
7pub mod graph;
8pub mod ingest;
9pub mod ingest_builder;
10pub mod plan;
11pub mod range_view;
12pub mod scheduler;
13pub mod spill;
14pub mod vertex;
15
16pub mod csr_edges;
18pub mod debug_views;
19pub mod delta_edges;
20pub mod epoch_tracker;
21pub mod interval_tree;
22pub mod named_range;
23pub mod packed_coord;
24pub mod sheet_index;
25pub mod sheet_registry;
26pub mod topo;
27pub mod vertex_store;
28
29pub mod arena;
31
32pub mod cache;
34pub mod masks;
35pub mod metrics;
36pub mod pass_planner;
37pub mod reference_fingerprint;
38pub mod tuning;
39pub mod warmup;
40
41#[cfg(test)]
42mod tests;
43
44use std::fmt::{Display, Formatter};
45
46pub use eval::{Engine, EvalResult};
47pub use graph::snapshot::VertexSnapshot;
49pub use graph::{
50 ChangeEvent, DependencyGraph, DependencyRef, OperationSummary, StripeKey, StripeType,
51 block_index,
52};
53pub use scheduler::{Layer, Schedule, Scheduler};
54pub use vertex::{VertexId, VertexKind};
55
56pub use graph::editor::{
57 DataUpdateSummary, EditorError, MetaUpdateSummary, RangeSummary, ShiftSummary, TransactionId,
58 VertexDataPatch, VertexEditor, VertexMeta, VertexMetaPatch,
59};
60
61pub use graph::editor::change_log::{ChangeLog, ChangeLogger, NullChangeLogger};
62
63use crate::traits::EvaluationContext;
66use crate::traits::VolatileLevel;
67
68impl<R: EvaluationContext> Engine<R> {
69 pub fn begin_bulk_ingest(&mut self) -> ingest_builder::BulkIngestBuilder<'_> {
70 ingest_builder::BulkIngestBuilder::new(&mut self.graph)
71 }
72}
73
74pub trait CalcObserver: Send + Sync {
76 fn on_eval_start(&self, vertex_id: VertexId);
77 fn on_eval_complete(&self, vertex_id: VertexId, duration: std::time::Duration);
78 fn on_cycle_detected(&self, cycle: &[VertexId]);
79 fn on_dirty_propagation(&self, vertex_id: VertexId, affected_count: usize);
80}
81
82impl CalcObserver for () {
84 fn on_eval_start(&self, _vertex_id: VertexId) {}
85 fn on_eval_complete(&self, _vertex_id: VertexId, _duration: std::time::Duration) {}
86 fn on_cycle_detected(&self, _cycle: &[VertexId]) {}
87 fn on_dirty_propagation(&self, _vertex_id: VertexId, _affected_count: usize) {}
88}
89
90#[derive(Debug, Clone)]
92pub struct EvalConfig {
93 pub enable_parallel: bool,
94 pub max_threads: Option<usize>,
95 pub max_vertices: Option<usize>,
97 pub max_eval_time: Option<std::time::Duration>,
98 pub max_memory_mb: Option<usize>,
99
100 pub workbook_seed: u64,
102
103 pub volatile_level: VolatileLevel,
105
106 pub range_expansion_limit: usize,
109 pub stripe_height: u32,
111 pub stripe_width: u32,
113 pub enable_block_stripes: bool,
115
116 pub spill: SpillConfig,
118
119 pub use_dynamic_topo: bool,
121 pub pk_visit_budget: usize,
123 pub pk_compaction_interval_ops: u64,
125 pub max_layer_width: Option<usize>,
127 pub pk_reject_cycle_edges: bool,
130 pub sheet_index_mode: SheetIndexMode,
132
133 pub warmup: tuning::WarmupConfig,
135
136 pub arrow_storage_enabled: bool,
138 pub arrow_fastpath_enabled: bool,
140 pub delta_overlay_enabled: bool,
142
143 pub write_formula_overlay_enabled: bool,
146
147 pub date_system: DateSystem,
149
150 pub defer_graph_building: bool,
153}
154
155impl Default for EvalConfig {
156 fn default() -> Self {
157 Self {
158 enable_parallel: true,
159 max_threads: None,
160 max_vertices: None,
161 max_eval_time: None,
162 max_memory_mb: None,
163
164 workbook_seed: 0xF0F0_D0D0_AAAA_5555,
166
167 volatile_level: VolatileLevel::Always,
169
170 range_expansion_limit: 64,
172 stripe_height: 256,
173 stripe_width: 256,
174 enable_block_stripes: false,
175 spill: SpillConfig::default(),
176
177 use_dynamic_topo: false, pk_visit_budget: 50_000,
180 pk_compaction_interval_ops: 100_000,
181 max_layer_width: None,
182 pk_reject_cycle_edges: false,
183 sheet_index_mode: SheetIndexMode::Eager,
184 warmup: tuning::WarmupConfig::default(),
185 arrow_storage_enabled: true,
186 arrow_fastpath_enabled: true,
187 delta_overlay_enabled: true,
188 write_formula_overlay_enabled: true,
189 date_system: DateSystem::Excel1900,
190 defer_graph_building: false,
191 }
192 }
193}
194
195#[derive(Debug, Clone, Copy, PartialEq, Eq)]
196pub enum SheetIndexMode {
197 Eager,
199 Lazy,
201 FastBatch,
203}
204
205#[derive(Debug, Clone, Copy, PartialEq, Eq)]
207pub enum DateSystem {
208 Excel1900,
210 Excel1904,
212}
213
214impl Display for DateSystem {
215 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
216 match self {
217 DateSystem::Excel1900 => write!(f, "1900"),
218 DateSystem::Excel1904 => write!(f, "1904"),
219 }
220 }
221}
222
223pub fn new_engine<R>(resolver: R, config: EvalConfig) -> Engine<R>
225where
226 R: EvaluationContext + 'static,
227{
228 Engine::new(resolver, config)
229}
230
231#[derive(Debug, Clone, Copy, PartialEq, Eq)]
233pub struct SpillConfig {
234 pub conflict_policy: SpillConflictPolicy,
236 pub tiebreaker: SpillTiebreaker,
238 pub bounds_policy: SpillBoundsPolicy,
240 pub buffer_mode: SpillBufferMode,
242 pub memory_budget_bytes: Option<u64>,
244 pub cancellation: SpillCancellationPolicy,
246 pub visibility: SpillVisibility,
248}
249
250impl Default for SpillConfig {
251 fn default() -> Self {
252 Self {
253 conflict_policy: SpillConflictPolicy::Error,
254 tiebreaker: SpillTiebreaker::FirstWins,
255 bounds_policy: SpillBoundsPolicy::Strict,
256 buffer_mode: SpillBufferMode::ShadowBuffer,
257 memory_budget_bytes: None,
258 cancellation: SpillCancellationPolicy::Cooperative,
259 visibility: SpillVisibility::OnCommit,
260 }
261 }
262}
263
264#[derive(Debug, Clone, Copy, PartialEq, Eq)]
265pub enum SpillConflictPolicy {
266 Error,
267 Preempt,
268}
269
270#[derive(Debug, Clone, Copy, PartialEq, Eq)]
271pub enum SpillTiebreaker {
272 FirstWins,
273 EvaluationEpochAsc,
274 AnchorAddressAsc,
275 FunctionPriorityThenAddress,
276}
277
278#[derive(Debug, Clone, Copy, PartialEq, Eq)]
279pub enum SpillBoundsPolicy {
280 Strict,
281 Truncate,
282}
283
284#[derive(Debug, Clone, Copy, PartialEq, Eq)]
285pub enum SpillBufferMode {
286 ShadowBuffer,
287 PersistenceJournal,
288}
289
290#[derive(Debug, Clone, Copy, PartialEq, Eq)]
291pub enum SpillCancellationPolicy {
292 Cooperative,
293 Strict,
294}
295
296#[derive(Debug, Clone, Copy, PartialEq, Eq)]
297pub enum SpillVisibility {
298 OnCommit,
299 StagedLayer,
300}