use crate::handle::Handle;
pub type P = u32;
pub type G = u32;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Arith {
Add,
Sub,
Mul,
Div,
DivNaturals,
Mod,
Pow,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Cmp {
Lt,
Le,
Gt,
Ge,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum SetOp {
Cup,
Cap,
Minus,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Quant {
Exists,
Forall,
Choose,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum StdFn {
Len,
Head,
Tail,
Append,
Concat,
SubSeq,
Cardinality,
Seq,
IsFiniteSet,
EmptyBag,
SetToBag,
BagToSet,
BagIn,
CopiesIn,
}
#[derive(Clone, Debug)]
pub struct Bind {
pub slots: Box<[u32]>,
pub tuple: bool,
pub domain: P,
}
#[derive(Clone, Debug)]
pub struct Update {
pub path: Box<[P]>,
pub at: u32,
pub value: P,
}
#[derive(Clone, Debug)]
pub enum LibArg {
Value(P),
Op {
params: Box<[u32]>,
body: P,
},
}
#[derive(Clone, Debug)]
pub enum Node {
Const(Handle),
Slot(u32),
Lazy {
slot: u32,
body: P,
},
Var(u16),
Primed(u16),
Not(P),
And(Box<[P]>),
Or(Box<[P]>),
Implies(P, P),
Equiv(P, P),
Composition {
first: G,
then: G,
free: Box<[u32]>,
reset: Box<[u32]>,
},
If(P, P, P),
Case(Box<[(P, P)]>, Option<P>),
Eq(P, P),
SameVars {
eq: P,
leaves: Box<[(u16, u8)]>,
thunks: Box<[u32]>,
},
Neq(P, P),
In(P, P),
NotIn(P, P),
Subseteq(P, P),
Arith(Arith, P, P),
Cmp(Cmp, P, P),
Neg(P),
Range(P, P),
SetEnum(Box<[P]>),
SetBin(SetOp, P, P),
Powerset(P),
BigUnion(P),
Product(Box<[P]>),
FcnSet(P, P),
RecSet(Box<[(Handle, P)]>),
Filter {
bind: Bind,
pred: P,
subset: Option<P>,
},
Map {
binds: Box<[Bind]>,
body: P,
},
FcnCons {
binds: Box<[Bind]>,
body: P,
},
Quant {
kind: Quant,
binds: Box<[Bind]>,
body: P,
},
Apply(P, P),
Select(P, Handle),
Domain(P),
Except {
base: P,
updates: Box<[Update]>,
},
Tuple(Box<[P]>),
Record(Box<[(Handle, P)]>),
Scope {
reset: Box<[u32]>,
body: P,
},
Call {
fun: u32,
args: Box<[P]>,
},
Std(StdFn, Box<[P]>),
Lib {
op: dive_ir::StdOp,
args: Box<[P]>,
repeatable_args: bool,
},
LibHo(dive_ir::StdOp, Box<[LibArg]>),
Enabled {
g: G,
free: Box<[u32]>,
},
Spec(P),
InLazy {
elem: P,
set: P,
neg: bool,
},
Beta {
chain: P,
fc: P,
arg: P,
},
DomCheck {
slot: u32,
domain: P,
body: P,
},
Memo {
site: u32,
body: P,
},
}
#[derive(Clone, Debug)]
pub enum GNode {
Composition {
first: G,
then: G,
reset: Box<[u32]>,
},
Conj(Box<[(G, P)]>),
Disj(Box<[G]>),
Exists {
binds: Box<[Bind]>,
body: G,
body_p: P,
},
Forall {
binds: Box<[Bind]>,
body: G,
body_p: P,
},
If {
cond: P,
then: G,
other: G,
},
Case {
arms: Box<[(P, G)]>,
other: Option<G>,
},
Implies {
lhs: P,
rhs: G,
},
Assign {
var: u16,
rhs: P,
},
AssignIn {
var: u16,
set: P,
},
AssignInRaw {
var: u16,
set: P,
raw: Raw,
},
Unchanged(Box<[Unch]>),
StepBox {
action: G,
vars: Box<[Unch]>,
},
StepAngle {
action: G,
same: P,
},
FcnAction {
binds: Box<[Bind]>,
arg: P,
body: G,
},
Scope {
reset: Box<[u32]>,
body: G,
},
Guard(P),
}
#[derive(Clone, Copy, Debug)]
pub enum Unch {
Var {
var: u16,
at: u32,
},
Verify(P),
}
#[derive(Clone, Debug)]
pub enum Raw {
Leaf(P),
Cup(Box<Raw>, Box<Raw>),
Union(Box<[Raw]>),
UnionOf(P),
Filter {
bind: Bind,
pred: P,
inner: Box<Raw>,
},
Cap(Box<Raw>, Box<Raw>, P, P),
Minus(Box<Raw>, P),
Odometer(Box<[Raw]>, P),
}
#[derive(Clone, Debug)]
pub struct Fun {
pub name: String,
pub params: u32,
pub frame: u32,
pub body: P,
pub caps: Box<[u32]>,
}
#[derive(Clone, Debug)]
pub struct MemoSite {
pub name: String,
pub vars: Box<[u16]>,
pub slots: Box<[u32]>,
pub primed: Box<[u16]>,
pub step: bool,
pub candidate: bool,
}
impl MemoSite {
#[must_use]
pub fn key_len(&self) -> usize {
self.vars.len() + self.primed.len() + self.slots.len()
}
}
#[derive(Clone, Debug, Default)]
pub struct Code {
pub source_map: Option<crate::debug::SourceMap>,
pub debugger: Option<std::sync::Arc<dyn crate::debug::Observer>>,
pub nodes: Vec<Node>,
pub gnodes: Vec<GNode>,
pub funs: Vec<Fun>,
pub sites: Vec<MemoSite>,
}
#[derive(Clone, Debug)]
pub struct Action {
pub name: String,
pub g: G,
pub frame: u32,
pub preset: Vec<(u32, Handle)>,
}
#[derive(Clone, Debug)]
pub struct Conjunct {
pub p: P,
pub reads: u64,
pub skippable: bool,
pub site: Option<u32>,
}
#[derive(Clone, Debug)]
pub struct Check {
pub name: String,
pub conjuncts: Vec<Conjunct>,
pub frame: u32,
}
#[derive(Clone, Debug)]
pub struct Plan {
pub code: Code,
pub vars: Vec<String>,
pub init: Vec<Action>,
pub next: Vec<Action>,
pub invariants: Vec<Check>,
pub constraints: Vec<Check>,
pub action_constraints: Vec<Check>,
pub implied_inits: Vec<Check>,
pub implied_actions: Vec<Check>,
pub check_deadlock: bool,
pub symmetry: Option<crate::symmetry::Symmetry>,
pub effects: Effects,
pub view: Option<Check>,
pub stats: CompileStats,
pub bound_preset: Vec<(u32, Handle)>,
pub startup_assumptions: Vec<dive_ir::DefId>,
pub startup_assumption_false: Option<dive_ir::DefId>,
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[allow(
clippy::struct_excessive_bools,
reason = "independent facts about the plan"
)]
pub struct Effects {
pub any: bool,
pub prints: bool,
pub draws: bool,
pub registers: bool,
pub level: bool,
}
#[derive(Clone, Copy, Debug, Default)]
pub struct CompileStats {
pub nodes: usize,
pub gnodes: usize,
pub inlined: usize,
pub aliased: usize,
pub thunks: usize,
pub by_name: usize,
pub folded: usize,
pub cached_defs: usize,
pub fold_abandoned: usize,
pub fold_skipped: usize,
pub fold_fuel: u64,
pub fold_nanos: u64,
pub speculative: u64,
pub substituted: usize,
pub beta: u64,
pub startup_values: usize,
pub startup_nanos: u64,
pub startup_call_hits: u64,
pub startup_fallbacks: usize,
}