Skip to main content

mir_analyzer/
type_env.rs

1// crates/mir-analyzer/src/type_env.rs
2use mir_types::{Name, Type};
3use std::sync::Arc;
4
5/// Identifies a single analysis scope within a project.
6#[derive(Debug, Clone, PartialEq, Eq, Hash)]
7pub enum ScopeId {
8    Function { file: Arc<str>, name: Arc<str> },
9    Method { class: Arc<str>, method: Arc<str> },
10}
11
12/// Variable type environment for one scope — the stable public view of FlowState.vars.
13#[allow(dead_code)]
14#[derive(Debug)]
15pub struct TypeEnv {
16    #[allow(dead_code)]
17    vars: Arc<rustc_hash::FxHashMap<Name, Arc<Type>>>,
18}
19
20impl TypeEnv {
21    pub(crate) fn new(vars: Arc<rustc_hash::FxHashMap<Name, Arc<Type>>>) -> Self {
22        Self { vars }
23    }
24
25    /// Returns the inferred type of `$name`, or `None` if the variable was not tracked.
26    #[allow(dead_code)]
27    pub fn get_var(&self, name: &str) -> Option<&Type> {
28        let sym = Name::from(name);
29        self.vars.get(&sym).map(|arc| arc.as_ref())
30    }
31
32    /// Iterates over all variable names tracked in this scope.
33    #[allow(dead_code)]
34    pub fn var_names(&self) -> impl Iterator<Item = &str> {
35        self.vars.keys().map(|s| s.as_str())
36    }
37}