1
//! The compilation's measured counters: the store-scan and fold counters are
2
//! rendered in the behaviour snapshot, the rest are read by tests.
3

            
4
/// Compilation counters.
5
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
6
pub(crate) struct CompileStats {
7
    /// Compound forms `eval_value` reduced to a constant datum, nested
8
    /// reductions and discarded probes included (plan 0014 Stage 0).
9
    pub(crate) folds: u64,
10
    /// Macro expansions whose body read a variable the macro did not bind.
11
    pub(crate) macro_bodies_reading_globals: u64,
12
    /// Globals the unit's store scan found a direct store to (0014 Stage 2).
13
    pub(crate) stored_globals: u64,
14
    /// Whether the scan saw a `SETF` it could not tie to a place.
15
    pub(crate) possibly_storing: bool,
16
    /// Macro uses whose expansion the scan did not run.
17
    pub(crate) opaque_macro_uses: u64,
18
    /// `compile_for_stack` entries, speculative ones included.
19
    pub(crate) stack_compiles: u64,
20
    /// `eval_value` and `form_diverges` entries, discarded probes included.
21
    pub(crate) probe_walks: u64,
22
    /// The most passes any one BLOCK took.
23
    pub(crate) block_passes_max: u64,
24
    /// Passes over all BLOCKs.
25
    pub(crate) block_passes_total: u64,
26
    /// Attempts the unit took to settle its homes.
27
    pub(crate) unit_attempts: u64,
28
}
29

            
30
impl CompileStats {
31
    /// The counters after one more attempt: the compile-work counters add up,
32
    /// the measured ones describe the latest attempt.
33
2352271
    pub(crate) fn after_attempt(self, attempt: Self) -> Self {
34
2352271
        Self {
35
2352271
            stack_compiles: self.stack_compiles.saturating_add(attempt.stack_compiles),
36
2352271
            block_passes_max: self.block_passes_max.max(attempt.block_passes_max),
37
2352271
            block_passes_total: self
38
2352271
                .block_passes_total
39
2352271
                .saturating_add(attempt.block_passes_total),
40
2352271
            unit_attempts: self.unit_attempts.saturating_add(1),
41
2352271
            ..attempt
42
2352271
        }
43
2352271
    }
44

            
45
18950506
    pub(crate) fn note_stack_compile(&mut self) {
46
18950506
        self.stack_compiles = self.stack_compiles.saturating_add(1);
47
18950506
    }
48

            
49
48859
    pub(crate) fn note_block_passes(&mut self, passes: u64) {
50
48859
        self.block_passes_max = self.block_passes_max.max(passes);
51
48859
        self.block_passes_total = self.block_passes_total.saturating_add(passes);
52
48859
    }
53
}