Skip to main content

lisette_semantics/
context.rs

1//! Shared immutable view of the program after registration finishes.
2//! Inference reads through this handle; it cannot mutate.
3//!
4//! Invariant: only `&` references. No `RefCell`, `Cell`, `Rc`, or owned
5//! mutable state. The `analysis_context_is_send_sync` test below
6//! enforces this at compile time.
7
8use rustc_hash::FxHashSet as HashSet;
9
10use crate::store::Store;
11
12pub struct AnalysisContext<'r> {
13    pub store: &'r Store,
14    pub ufcs_methods: &'r HashSet<(String, String)>,
15}
16
17impl<'r> AnalysisContext<'r> {
18    pub fn new(store: &'r Store, ufcs_methods: &'r HashSet<(String, String)>) -> Self {
19        Self {
20            store,
21            ufcs_methods,
22        }
23    }
24}
25
26#[cfg(test)]
27mod tests {
28    use super::*;
29    use diagnostics::LocalSink;
30
31    #[test]
32    fn analysis_context_is_send_sync() {
33        fn assert_send_sync<T: Send + Sync>() {}
34        assert_send_sync::<AnalysisContext<'_>>();
35        assert_send_sync::<&Store>();
36    }
37
38    #[test]
39    fn local_sink_is_send_not_sync() {
40        fn assert_send<T: Send>() {}
41        assert_send::<LocalSink>();
42    }
43}