1
//! The part of a [`SymbolTable`] a recompile pass may change and must restore.
2
//!
3
//! Deliberately excluded: the budget (never refunded), and the recursion,
4
//! guard and inlining counters and the eval BLOCK frames and dead-code flag,
5
//! which every path leaves balanced.
6

            
7
use std::collections::HashMap;
8

            
9
use crate::ast::{Expr, LambdaParams, Place, WasmType};
10

            
11
use super::entry::Symbol;
12
use super::homes::HomeBook;
13
use super::instances::InstanceHeap;
14
use super::structs::StructRegistry;
15
use super::table::SymbolTable;
16

            
17
#[derive(Clone, Debug)]
18
pub(crate) struct SymbolJournal {
19
    symbols: HashMap<String, Symbol>,
20
    structs: StructRegistry,
21
    instances: InstanceHeap,
22
    tests: Vec<(String, Expr)>,
23
    native_coverage: HashMap<String, u32>,
24
    closure_results: HashMap<u32, WasmType>,
25
    closure_params: HashMap<u32, Vec<WasmType>>,
26
    closure_bodies: HashMap<Place, (LambdaParams, Expr)>,
27
    homes: HomeBook,
28
}
29

            
30
impl SymbolTable {
31
161147
    pub(crate) fn journal(&self) -> SymbolJournal {
32
161147
        SymbolJournal {
33
161147
            symbols: self.symbols.clone(),
34
161147
            structs: self.structs.clone(),
35
161147
            instances: self.instances.clone(),
36
161147
            tests: self.tests.clone(),
37
161147
            native_coverage: self.native_coverage.clone(),
38
161147
            closure_results: self.closure_results.clone(),
39
161147
            closure_params: self.closure_params.clone(),
40
161147
            closure_bodies: self.closure_bodies.clone(),
41
161147
            homes: self.home_book(),
42
161147
        }
43
161147
    }
44

            
45
102645
    pub(crate) fn restore_journal(&mut self, journal: SymbolJournal) {
46
        let SymbolJournal {
47
            symbols,
48
            structs,
49
            instances,
50
            tests,
51
            native_coverage,
52
            closure_results,
53
            closure_params,
54
            closure_bodies,
55
            homes,
56
102645
        } = journal;
57
102645
        self.symbols = symbols;
58
102645
        self.structs = structs;
59
102645
        self.instances = instances;
60
102645
        self.tests = tests;
61
102645
        self.native_coverage = native_coverage;
62
102645
        self.closure_results = closure_results;
63
102645
        self.closure_params = closure_params;
64
102645
        self.closure_bodies = closure_bodies;
65
102645
        self.restore_home_book(homes);
66
102645
    }
67

            
68
    #[cfg(test)]
69
10
    pub(crate) fn budget(&self) -> &crate::compiler::budget::SharedBudget {
70
10
        &self.budget
71
10
    }
72
}