pub const MAX_DEPTH: usize = 64;
pub const MAX_NODES: usize = 20_000;
pub const MAX_STEPS: usize = 200_000;
pub const MAX_CALL_DEPTH: usize = 16;
pub const WIDEN_AFTER: usize = 3;
pub const MAX_ROUNDS: usize = 8;
pub const MAX_VARS: usize = 512;
pub const MAX_SUMMARIES: usize = 256;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Exhausted {
Depth,
Nodes,
Steps,
CallDepth,
Recursion,
}
impl Exhausted {
pub fn describe(self) -> &'static str {
match self {
Exhausted::Depth => "nesting deeper than the analysis follows",
Exhausted::Nodes => "a command larger than the analysis reads",
Exhausted::Steps => "more work than the analysis budget allows",
Exhausted::CallDepth => "function calls nested deeper than the analysis follows",
Exhausted::Recursion => "a recursive function",
}
}
}
#[derive(Debug, Clone)]
pub struct Budget {
steps: usize,
}
impl Budget {
pub fn new() -> Budget {
Budget { steps: MAX_STEPS }
}
pub fn step(&mut self) -> Result<(), Exhausted> {
if self.steps == 0 {
return Err(Exhausted::Steps);
}
self.steps -= 1;
Ok(())
}
}
impl Default for Budget {
fn default() -> Budget {
Budget::new()
}
}