Skip to main content

mir_analyzer/
type_env.rs

1// crates/mir-analyzer/src/type_env.rs
2use indexmap::IndexMap;
3use mir_types::Union;
4use std::sync::Arc;
5
6/// Identifies a single analysis scope within a project.
7#[derive(Debug, Clone, PartialEq, Eq, Hash)]
8pub enum ScopeId {
9    Function { file: Arc<str>, name: Arc<str> },
10    Method { class: Arc<str>, method: Arc<str> },
11}
12
13/// Variable type environment for one scope — the stable public view of Context.vars.
14#[allow(dead_code)]
15#[derive(Debug)]
16pub struct TypeEnv {
17    #[allow(dead_code)]
18    vars: IndexMap<String, Union>,
19}
20
21impl TypeEnv {
22    pub(crate) fn new(vars: IndexMap<String, Union>) -> Self {
23        Self { vars }
24    }
25
26    /// Returns the inferred type of `$name`, or `None` if the variable was not tracked.
27    #[allow(dead_code)]
28    pub fn get_var(&self, name: &str) -> Option<&Union> {
29        self.vars.get(name)
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}