dive-core 0.1.0

The dive execution core for TLA+: value store, plan compiler, interpreter and successor generation
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
//! The compiled plan: compact node arrays indexed by `u32`, not boxed trees.
//!
//! Value nodes ([`Node`]) evaluate to a handle. Generator nodes ([`GNode`])
//! enumerate successors with TLC's `getNextStates` rules. Every local is a
//! slot of one flat frame per role (or per recursive operator activation);
//! operator applications are inlined, with their arguments substituted,
//! cached in thunk slots, or re-evaluated by name.

use crate::handle::Handle;

/// A value node id.
pub type P = u32;
/// A generator node id.
pub type G = u32;

/// Integer arithmetic.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Arith {
    /// `+`
    Add,
    /// `-`
    Sub,
    /// `*`
    Mul,
    /// `\div`
    Div,
    /// `\div` from `Naturals` without `Integers` (`Naturals.Divide`; floored
    /// in big mode, as `Div`).
    DivNaturals,
    /// `%`
    Mod,
    /// `^`
    Pow,
}

/// Integer comparison.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Cmp {
    /// `<`
    Lt,
    /// `<=`
    Le,
    /// `>`
    Gt,
    /// `>=`
    Ge,
}

/// Binary set operators.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum SetOp {
    /// `\cup`
    Cup,
    /// `\cap`
    Cap,
    /// `\`
    Minus,
}

/// Quantifiers in value position.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Quant {
    /// `\E`
    Exists,
    /// `\A`
    Forall,
    /// `CHOOSE`
    Choose,
}

/// Standard-module operators the core implements.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum StdFn {
    /// `Len(s)`
    Len,
    /// `Head(s)`
    Head,
    /// `Tail(s)`
    Tail,
    /// `Append(s, e)`
    Append,
    /// `s \o t`
    Concat,
    /// `SubSeq(s, m, n)`
    SubSeq,
    /// `Cardinality(S)`
    Cardinality,
    /// `Seq(S)`
    Seq,
    /// `IsFiniteSet(S)`
    IsFiniteSet,
    /// `EmptyBag` (Bags)
    EmptyBag,
    /// `SetToBag(S)` (Bags)
    SetToBag,
    /// `BagToSet(B)` (Bags)
    BagToSet,
    /// `BagIn(e, B)` (Bags)
    BagIn,
    /// `CopiesIn(e, B)` (Bags)
    CopiesIn,
}

/// One bound group: `x, y \in S` or `<<x, y>> \in S`.
#[derive(Clone, Debug)]
pub struct Bind {
    /// The bound variables' frame slots.
    pub slots: Box<[u32]>,
    /// A tuple pattern.
    pub tuple: bool,
    /// The domain.
    pub domain: P,
}

/// One `EXCEPT` clause.
#[derive(Clone, Debug)]
pub struct Update {
    /// The path.
    pub path: Box<[P]>,
    /// The slot `@` is bound in.
    pub at: u32,
    /// The new value.
    pub value: P,
}

/// An argument of a higher-order library operator ([`Node::LibHo`]).
#[derive(Clone, Debug)]
pub enum LibArg {
    /// A value, evaluated (normalized) before the call.
    Value(P),
    /// An operator: its parameters' slots and its body, which the library
    /// evaluates once per application.
    Op {
        /// The parameters' slots.
        params: Box<[u32]>,
        /// The body.
        body: P,
    },
}

/// A value node.
#[derive(Clone, Debug)]
pub enum Node {
    /// A constant (persistent or scalar).
    Const(Handle),
    /// A frame slot holding a value.
    Slot(u32),
    /// A thunk: evaluated on first use and cached in its slot until the
    /// enclosing scope is entered again.
    Lazy {
        /// The cache slot.
        slot: u32,
        /// The argument.
        body: P,
    },
    /// An unprimed state variable.
    Var(u16),
    /// A primed state variable (the successor buffer).
    Primed(u16),
    /// `~e`
    Not(P),
    /// Conjunction, short-circuit.
    And(Box<[P]>),
    /// Disjunction, short-circuit.
    Or(Box<[P]>),
    /// `a => b`
    Implies(P, P),
    /// `a <=> b`
    Equiv(P, P),
    /// Pure bounded `A \\cdot B`, tested against the complete successor.
    Composition {
        /// Enumerable first-stage action.
        first: G,
        /// Deterministic action assigning every final variable.
        then: G,
        /// Captured lexical slots.
        free: Box<[u32]>,
        /// State-dependent thunk slots of this frame, reset whenever the
        /// stages change the rows they read.
        reset: Box<[u32]>,
    },
    /// `IF c THEN a ELSE b`
    If(P, P, P),
    /// `CASE`
    Case(Box<[(P, P)]>, Option<P>),
    /// `a = b`
    Eq(P, P),
    /// `e = e'` for a subscript `e` compiled to a tuple, possibly nested and
    /// behind thunks, of state variables (`changed_test`). `eq` is that
    /// `Eq`. Outside TLC comparisons, when no thunk on the way is forced and
    /// every leaf of both states is materialized, the result is each leaf's
    /// `Heap::eq`, without building either tuple or forcing a thunk;
    /// otherwise `eq` is evaluated.
    SameVars {
        /// The original `Eq` of the two tuples.
        eq: P,
        /// Each leaf variable and its depth (1 for an outer element).
        leaves: Box<[(u16, u8)]>,
        /// The slots of the thunks (`Node::Lazy`) between `eq` and the leaves.
        thunks: Box<[u32]>,
    },
    /// `a /= b`
    Neq(P, P),
    /// `a \in S`
    In(P, P),
    /// `a \notin S`
    NotIn(P, P),
    /// `A \subseteq B`
    Subseteq(P, P),
    /// Integer arithmetic.
    Arith(Arith, P, P),
    /// Integer comparison.
    Cmp(Cmp, P, P),
    /// `-a`
    Neg(P),
    /// `a..b`
    Range(P, P),
    /// `{a, b, ...}`; finite sets use canonical order by default.
    SetEnum(Box<[P]>),
    /// `A \cup B` and friends.
    SetBin(SetOp, P, P),
    /// `SUBSET S`
    Powerset(P),
    /// `UNION S`
    BigUnion(P),
    /// `S1 \X ... \X Sn`
    Product(Box<[P]>),
    /// `[D -> R]`
    FcnSet(P, P),
    /// `[f : S, ...]`, field names sorted.
    RecSet(Box<[(Handle, P)]>),
    /// `{x \in S : P}`
    Filter {
        /// The bound.
        bind: Bind,
        /// The predicate.
        pred: P,
        /// A proven rewrite of `{E \in SUBSET T : \A e \in E : Q}` as
        /// `SUBSET F`: the node of `F = {e \in T : Q}`. The compiler sets it
        /// only when `Q` is pure, makes no call and does not read `E`, so
        /// the filter's elements are exactly the subsets of `F`. Only
        /// enumeration uses it; membership keeps the filter's own order of
        /// evaluation, and an evaluation error in `F` falls back to the
        /// filter itself.
        subset: Option<P>,
    },
    /// `{e : x \in S, ...}`
    Map {
        /// The bounds.
        binds: Box<[Bind]>,
        /// The element.
        body: P,
    },
    /// `[x \in S |-> e]`
    FcnCons {
        /// The bounds.
        binds: Box<[Bind]>,
        /// The body.
        body: P,
    },
    /// `\E`, `\A`, `CHOOSE`.
    Quant {
        /// Which.
        kind: Quant,
        /// The bounds.
        binds: Box<[Bind]>,
        /// The body.
        body: P,
    },
    /// `f[a]`
    Apply(P, P),
    /// `r.f`
    Select(P, Handle),
    /// `DOMAIN f`
    Domain(P),
    /// `[f EXCEPT ...]`
    Except {
        /// The function.
        base: P,
        /// The clauses.
        updates: Box<[Update]>,
    },
    /// `<<a, b>>`
    Tuple(Box<[P]>),
    /// `[a |-> e, ...]`, field names sorted.
    Record(Box<[(Handle, P)]>),
    /// Resets thunk slots, then evaluates the body (an inlined operator or
    /// a `LET`).
    Scope {
        /// Thunk slots to reset.
        reset: Box<[u32]>,
        /// The body.
        body: P,
    },
    /// A call of a recursive operator, in a new frame.
    Call {
        /// The function.
        fun: u32,
        /// The arguments, evaluated eagerly.
        args: Box<[P]>,
    },
    /// A standard operator.
    Std(StdFn, Box<[P]>),
    /// A standard or CommunityModules operator implemented in
    /// [`crate::stdlib`], on normalized arguments.
    Lib {
        /// The library operator.
        op: dive_ir::StdOp,
        /// Its arguments, evaluated in source order.
        args: Box<[P]>,
        /// Whether reevaluation is proven effect-free without calls or free slots.
        repeatable_args: bool,
    },
    /// A [`crate::stdlib`] operator with operator arguments.
    LibHo(dive_ir::StdOp, Box<[LibArg]>),
    /// `ENABLED A`: whether the action `A` has a successor from the current
    /// state, complete or not (TLC's `Tool.enabled`). `free` holds the
    /// frame slots `A` reads from outside it.
    Enabled {
        /// The action.
        g: G,
        /// The slots read from outside the action.
        free: Box<[u32]>,
    },
    /// An expression the core evaluates eagerly where TLC evaluates it
    /// lazily: an evaluation error inside it
    /// is reported as `unsupported`, because TLC might never raise it.
    Spec(P),
    /// `a \in S` (or `a \notin S` with `neg`) with `S` a set TLC keeps
    /// lazy: a filter or a binary set operation, possibly behind thunks.
    /// Membership is decided on the structure, as TLC's `SetPredValue`,
    /// `SetCupValue`, `SetCapValue` and `SetDiffValue` do, without building
    /// the set.
    InLazy {
        /// The element.
        elem: P,
        /// The set's node.
        set: P,
        /// `\notin`.
        neg: bool,
    },
    /// `f[arg]` with `f` a function constructor TLC keeps lazy
    /// (`FcnLambdaValue.apply`): the body is evaluated for `arg` alone, after
    /// a domain check. `chain` leads to the constructor `fc` through thunks;
    /// a thunk already forced is applied as a value.
    Beta {
        /// The function expression.
        chain: P,
        /// The `FcnCons` node, whose bound variables have no tuple pattern.
        fc: P,
        /// The argument.
        arg: P,
    },
    /// The body of a recursive function `f[x \in S] == e`: checks that the
    /// argument in `slot` is in `domain`, then evaluates `body`.
    DomCheck {
        /// The argument's slot.
        slot: u32,
        /// The domain.
        domain: P,
        /// The body.
        body: P,
    },
    /// A memoized pure body.
    Memo {
        /// The site.
        site: u32,
        /// The body.
        body: P,
    },
}

/// A generator node.
#[derive(Clone, Debug)]
pub enum GNode {
    /// Pure bounded `A \\cdot B`, with complete intermediate rows and a
    /// deterministic tail assigning every final variable.
    Composition {
        /// Enumerable first-stage action.
        first: G,
        /// Fully assigning deterministic tail.
        then: G,
        /// State-dependent thunk slots of this frame, reset whenever the
        /// stages change the rows they read.
        reset: Box<[u32]>,
    },
    /// A conjunction: items processed left to right as continuations; each
    /// item has a boolean form for the all-assigned shortcut.
    Conj(Box<[(G, P)]>),
    /// A disjunction.
    Disj(Box<[G]>),
    /// Bounded `\E`.
    Exists {
        /// The bounds.
        binds: Box<[Bind]>,
        /// The body.
        body: G,
        /// The body's boolean form.
        body_p: P,
    },
    /// Bounded `\A`: the first binding, then the others last first.
    Forall {
        /// The bounds.
        binds: Box<[Bind]>,
        /// The body.
        body: G,
        /// The body's boolean form.
        body_p: P,
    },
    /// `IF`
    If {
        /// The guard.
        cond: P,
        /// `THEN`
        then: G,
        /// `ELSE`
        other: G,
    },
    /// `CASE`
    Case {
        /// The arms.
        arms: Box<[(P, G)]>,
        /// `OTHER`
        other: Option<G>,
    },
    /// `P => Q`
    Implies {
        /// `P`
        lhs: P,
        /// `Q`
        rhs: G,
    },
    /// `x' = e`
    Assign {
        /// The variable.
        var: u16,
        /// The right side.
        rhs: P,
    },
    /// `x' \in S`
    AssignIn {
        /// The variable.
        var: u16,
        /// The set.
        set: P,
    },
    /// `x' \in S` where TLC's `elements()` of `S` may list an element more
    /// than once (a lazy union): `raw`
    /// reproduces TLC's multiplicity, and the run refuses when it differs
    /// from the normalized set's.
    AssignInRaw {
        /// The variable.
        var: u16,
        /// The set.
        set: P,
        /// TLC's `elements()` structure.
        raw: Raw,
    },
    /// `UNCHANGED e`, decomposed by TLC's `processUnchanged` into items in
    /// order.
    Unchanged(Box<[Unch]>),
    /// `[A]_v`: `A`, then `UNCHANGED v`.
    StepBox {
        /// `A`
        action: G,
        /// `v`, decomposed.
        vars: Box<[Unch]>,
    },
    /// `<<A>>_v`: `A`, then a `CHANGED v` item.
    StepAngle {
        /// `A`
        action: G,
        /// `v = v'`, evaluated with `v` in `s0` and `v'` in `s1`.
        same: P,
    },
    /// `f[a]` used as an action, where `f` is a function constructor TLC
    /// keeps lazy (`FcnLambdaValue`, `Tool.getFcnContext`): the body is
    /// enumerated with the parameters bound to the argument.
    FcnAction {
        /// The parameters, one group per bound.
        binds: Box<[Bind]>,
        /// The argument.
        arg: P,
        /// The body.
        body: G,
    },
    /// Thunk slots reset around a body (inlined operator or `LET`).
    Scope {
        /// The thunk slots.
        reset: Box<[u32]>,
        /// The body.
        body: G,
    },
    /// Any other formula: a boolean guard.
    Guard(P),
}

/// One item of a decomposed `UNCHANGED` (TLC's `processUnchanged`).
#[derive(Clone, Copy, Debug)]
pub enum Unch {
    /// A state variable: bound to its old value, or compared with it. `at`
    /// is the expression TLC's warning 2143 names.
    Var {
        /// The variable.
        var: u16,
        /// Where it is written: the `ExprId` index.
        at: u32,
    },
    /// Any other expression: `e = e'`, with `e` in `s0` and `e'` in `s1`
    /// (`verifyUnchanged`).
    Verify(P),
}

/// TLC's `Enumerable.elements()` multiplicity of a set bound by `x' \in S`.
#[derive(Clone, Debug)]
pub enum Raw {
    /// A set whose `elements()` lists every element once.
    Leaf(P),
    /// `SetCupValue`: the first set's elements, then the second's.
    Cup(Box<Raw>, Box<Raw>),
    /// `UnionValue` of an enumerated set of sets: each distinct member's
    /// elements in turn.
    Union(Box<[Raw]>),
    /// `UnionValue` of another set of sets: each member's elements in turn.
    UnionOf(P),
    /// `SetPredValue`: the bound set's elements, filtered.
    Filter {
        /// The bound variable (its domain is `inner`).
        bind: Bind,
        /// The predicate.
        pred: P,
        /// The bound set.
        inner: Box<Raw>,
    },
    /// `SetCapValue`: the enumerable operand's elements, filtered by
    /// membership in the other.
    Cap(Box<Raw>, Box<Raw>, P, P),
    /// `SetDiffValue`: the first operand's elements not in the second.
    Minus(Box<Raw>, P),
    /// An odometer over components (`[D -> R]`, records, products): an
    /// element repeats when a component's does.
    Odometer(Box<[Raw]>, P),
}

/// A recursive operator, compiled once with its own frame.
#[derive(Clone, Debug)]
pub struct Fun {
    /// The name.
    pub name: String,
    /// Number of parameters (slots `0..params`).
    pub params: u32,
    /// The frame size.
    pub frame: u32,
    /// The body.
    pub body: P,
    /// The slots of the values captured from enclosing definitions (a
    /// recursive `LET` operator's free locals, lambda-lifted): a call
    /// passes them after the parameters.
    pub caps: Box<[u32]>,
}

/// A memoization site.
#[derive(Clone, Debug)]
pub struct MemoSite {
    /// A description for statistics.
    pub name: String,
    /// The unprimed variables the body reads.
    pub vars: Box<[u16]>,
    /// The free slots the body reads.
    pub slots: Box<[u32]>,
    /// The primed variables the body reads: in a step predicate, whose
    /// pair is complete (`Compiler::step`), or in an action's primed
    /// definition, whose site is bypassed while one is unassigned
    /// (`Opts::primed_memo`).
    pub primed: Box<[u16]>,
    /// A step predicate's or primed definition's site (`Opts::step_memo`,
    /// `Opts::primed_memo`): on whatever `Opts::memo` says, and its results
    /// are interned to be kept.
    pub step: bool,
    /// A primed definition's site (`Opts::primed_memo`), evaluated once per
    /// enumeration candidate: its primed keys are candidate values, so the
    /// bytes its persistent keys and results add to the store are bounded
    /// (`Memo::charge_kept`).
    pub candidate: bool,
}

impl MemoSite {
    /// The length of the site's key, in handles.
    #[must_use]
    pub fn key_len(&self) -> usize {
        self.vars.len() + self.primed.len() + self.slots.len()
    }
}

/// The node arrays.
#[derive(Clone, Debug, Default)]
pub struct Code {
    /// Explicit compiled source maps; None allocates no tables.
    pub source_map: Option<crate::debug::SourceMap>,
    /// Producer observation capability, installed only in search machines.
    pub debugger: Option<std::sync::Arc<dyn crate::debug::Observer>>,
    /// Value nodes.
    pub nodes: Vec<Node>,
    /// Generator nodes.
    pub gnodes: Vec<GNode>,
    /// Recursive operators.
    pub funs: Vec<Fun>,
    /// Memo sites.
    pub sites: Vec<MemoSite>,
}

/// An initial predicate or next-state action.
#[derive(Clone, Debug)]
pub struct Action {
    /// TLC's name of the action.
    pub name: String,
    /// The generator.
    pub g: G,
    /// The frame size.
    pub frame: u32,
    /// The frame slots preset by splitting (`\E` and parameter values).
    pub preset: Vec<(u32, Handle)>,
}

/// One conjunct of an invariant or constraint.
#[derive(Clone, Debug)]
pub struct Conjunct {
    /// The boolean body.
    pub p: P,
    /// The unprimed variables it reads, as a mask.
    pub reads: u64,
    /// Whether the parent-delta skip applies (pure, no free slots, read set
    /// known).
    pub skippable: bool,
    /// The memo site, if any.
    pub site: Option<u32>,
}

/// An invariant or state constraint.
#[derive(Clone, Debug)]
pub struct Check {
    /// The configured name.
    pub name: String,
    /// The conjuncts, in order.
    pub conjuncts: Vec<Conjunct>,
    /// The frame size.
    pub frame: u32,
}

/// The compiled specification.
#[derive(Clone, Debug)]
pub struct Plan {
    /// The node arrays.
    pub code: Code,
    /// State variable names, by index.
    pub vars: Vec<String>,
    /// The initial predicates.
    pub init: Vec<Action>,
    /// The next-state actions, in TLC's order.
    pub next: Vec<Action>,
    /// `INVARIANT`s.
    pub invariants: Vec<Check>,
    /// `CONSTRAINT`s.
    pub constraints: Vec<Check>,
    /// `ACTION_CONSTRAINT`s.
    pub action_constraints: Vec<Check>,
    /// Implied initial predicates (`PROPERTY` parts checked on the initial
    /// states).
    pub implied_inits: Vec<Check>,
    /// Implied actions (`[A]_v` of `[][A]_v` in `PROPERTY`s), step
    /// predicates.
    pub implied_actions: Vec<Check>,
    /// Whether deadlock is checked.
    pub check_deadlock: bool,
    /// `SYMMETRY`: states are keyed by their canonical image.
    pub symmetry: Option<crate::symmetry::Symmetry>,
    /// The plan's effects: the engine then runs one worker, in TLC's
    /// order.
    pub effects: Effects,
    /// `VIEW`: its value, the one conjunct, keys the state.
    pub view: Option<Check>,
    /// Compile statistics.
    pub stats: CompileStats,
    /// The frame slots a bound optional atom's role binds
    /// ([`crate::compile::compile_bound_test`]: `\E` variables and inlined
    /// parameters of its scope), with their values, which the caller
    /// installs after entering the check's frame; empty otherwise.
    pub bound_preset: Vec<(u32, Handle)>,
    /// The pure `ASSUME`s ([`crate::compile::Handoff::assumptions`]) the
    /// compiler evaluated to `TRUE`, in order.
    pub startup_assumptions: Vec<dive_ir::DefId>,
    /// The pure `ASSUME` after [`Self::startup_assumptions`] that the
    /// compiler evaluated to `FALSE`, where it stopped; `None` when it found
    /// them all `TRUE` or stopped at one it did not evaluate to a Boolean.
    pub startup_assumption_false: Option<dive_ir::DefId>,
}

/// What effects a plan has (`Info::effect`).
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[allow(
    clippy::struct_excessive_bools,
    reason = "independent facts about the plan"
)]
pub struct Effects {
    /// Any effect (`Print`, `PrintT`, `RandomElement`, `TLCSet`, `TLCGet`).
    pub any: bool,
    /// `Print` or `PrintT`.
    pub prints: bool,
    /// `RandomElement`: the engine starts each expansion's random stream
    /// (`crate::random`).
    pub draws: bool,
    /// `TLCSet` or `TLCGet` of a register (not of `"level"`).
    pub registers: bool,
    /// `TLCGet("level")`: the engine sets `Machine::level`.
    pub level: bool,
}

/// What the compiler did.
#[derive(Clone, Copy, Debug, Default)]
pub struct CompileStats {
    /// Value nodes.
    pub nodes: usize,
    /// Generator nodes.
    pub gnodes: usize,
    /// Operator applications inlined.
    pub inlined: usize,
    /// Arguments substituted directly.
    pub aliased: usize,
    /// Arguments bound to thunks.
    pub thunks: usize,
    /// Arguments re-evaluated by name.
    pub by_name: usize,
    /// Subexpressions folded to constants.
    pub folded: usize,
    /// State-level definitions cached once per frame activation.
    pub cached_defs: usize,
    /// Folds abandoned because they ran out of fuel.
    pub fold_abandoned: usize,
    /// Folds not attempted because the compile-time budget was spent.
    pub fold_skipped: usize,
    /// Loop iterations spent folding.
    pub fold_fuel: u64,
    /// Wall time spent folding, in nanoseconds.
    pub fold_nanos: u64,
    /// Filters, function constructors and set operations the core builds
    /// eagerly where TLC is lazy (`Node::Spec`).
    pub speculative: u64,
    /// `INSTANCE` substitutions bound.
    pub substituted: usize,
    /// Applications of lazy function constructors evaluated for their
    /// argument alone (`Node::Beta`).
    pub beta: u64,
    /// Constant definitions the binder left to the core, evaluated here
    /// ([`crate::compile::Handoff::deferred`]), and closed zero-arity
    /// definitions too large to fold, evaluated once at their first use
    /// ([`crate::compile::SETTLE_FUEL`]).
    pub startup_values: usize,
    /// Wall time spent evaluating them, in nanoseconds.
    pub startup_nanos: u64,
    /// Calls their evaluation answered from its call results.
    pub startup_call_hits: u64,
    /// Those the core did not evaluate whose value the binder's evaluation
    /// supplied ([`crate::compile::Handoff::startup_evaluator`]).
    pub startup_fallbacks: usize,
}