Skip to main content

Codebase

Struct Codebase 

Source
pub struct Codebase {
Show 13 fields pub classes: DashMap<Arc<str>, ClassStorage>, pub interfaces: DashMap<Arc<str>, InterfaceStorage>, pub traits: DashMap<Arc<str>, TraitStorage>, pub enums: DashMap<Arc<str>, EnumStorage>, pub functions: DashMap<Arc<str>, FunctionStorage>, pub constants: DashMap<Arc<str>, Union>, pub global_vars: DashMap<Arc<str>, Union>, pub symbol_interner: Interner, pub file_interner: Interner, pub symbol_to_file: DashMap<Arc<str>, Arc<str>>, pub known_symbols: DashSet<Arc<str>>, pub file_imports: DashMap<Arc<str>, HashMap<String, String>>, pub file_namespaces: DashMap<Arc<str>, String>, /* private fields */
}

Fields§

§classes: DashMap<Arc<str>, ClassStorage>§interfaces: DashMap<Arc<str>, InterfaceStorage>§traits: DashMap<Arc<str>, TraitStorage>§enums: DashMap<Arc<str>, EnumStorage>§functions: DashMap<Arc<str>, FunctionStorage>§constants: DashMap<Arc<str>, Union>§global_vars: DashMap<Arc<str>, Union>

Types of @var-annotated global variables, collected in Pass 1. Key: variable name without the $ prefix.

§symbol_interner: Interner

Interner for symbol keys ("ClassName::method", "ClassName::prop", FQN). Replaces repeated Arc<str> copies (16 bytes) with compact u32 IDs (4 bytes).

§file_interner: Interner

Interner for file paths. Same memory rationale as symbol_interner.

§symbol_to_file: DashMap<Arc<str>, Arc<str>>

Maps every FQCN (class, interface, trait, enum, function) to the absolute path of the file that defines it. Populated during Pass 1.

§known_symbols: DashSet<Arc<str>>

Lightweight FQCN index populated by SymbolTable before Pass 1. Enables O(1) “does this symbol exist?” checks before full definitions are available.

§file_imports: DashMap<Arc<str>, HashMap<String, String>>

Per-file use alias maps: alias → FQCN. Populated during Pass 1.

Key: absolute file path (as Arc<str>). Value: map of alias → fully-qualified class name.

Exposed as pub so that external consumers (e.g. php-lsp) can read import data that mir already collects, instead of reimplementing it.

§file_namespaces: DashMap<Arc<str>, String>

Per-file current namespace (if any). Populated during Pass 1.

Key: absolute file path (as Arc<str>). Value: the declared namespace string (e.g. "App\\Controller").

Exposed as pub so that external consumers (e.g. php-lsp) can read namespace data that mir already collects, instead of reimplementing it.

Implementations§

Source§

impl Codebase

Source

pub fn new() -> Self

Source

pub fn inject_stub_slice(&self, slice: StubSlice)

Insert all definitions from slice into this codebase.

Called by generated stub modules (src/generated/stubs_*.rs) to register their pre-compiled definitions. Later insertions overwrite earlier ones, so custom stubs loaded after PHPStorm stubs act as overrides. Merge a [StubSlice] into the codebase.

When slice.file is Some, this method also writes file-keyed metadata: symbol_to_file, global_vars, file_namespaces, and file_imports. This includes slices produced from PHPStorm stub files — so after this call, file_namespaces and file_imports will contain entries keyed by stub file paths as well as user-code file paths. That is intentional: the lazy-load scan iterates file_imports but is gated by type_exists, so stub-sourced entries are harmlessly short-circuited there.

Source

pub fn compact_reference_index(&self)

Convert the build-phase DashMap reference index into a compact CSR form.

Call this once after Pass 2 completes on all files. The method:

  1. Drains the two build-phase DashMaps into a single flat Vec.
  2. Sorts and deduplicates entries.
  3. Builds two CSR offset arrays (by symbol and by file).
  4. Clears the DashMaps (freeing their allocations).

After this call all reference queries use the compact index. Incremental re-analysis via [Self::re_analyze_file] will automatically decompress the index back into DashMaps on the first write, then recompact can be called again at the end of that analysis pass.

Source

pub fn remove_file_definitions(&self, file_path: &str)

Remove all definitions and outgoing reference locations contributed by the given file. This clears classes, interfaces, traits, enums, functions, and constants whose defining file matches file_path, the file’s import and namespace entries, and all entries in symbol_reference_locations that originated from this file.

Source

pub fn type_exists(&self, fqcn: &str) -> bool

Whether a class/interface/trait/enum with this FQCN exists.

Source

pub fn resolve_class_name(&self, file: &str, name: &str) -> String

Resolve a short class/function name to its FQCN using the import table and namespace recorded for file during Pass 1.

  • Names already containing \ (after stripping a leading \) are returned as-is (already fully qualified).
  • self, parent, static are returned unchanged (caller handles them).
Source

pub fn get_symbol_location(&self, fqcn: &str) -> Option<Location>

Look up the definition location of any symbol (class, interface, trait, enum, function). Returns the file path and byte offsets.

Source

pub fn is_method_referenced(&self, fqcn: &str, method_name: &str) -> bool

Source

pub fn is_property_referenced(&self, fqcn: &str, prop_name: &str) -> bool

Source

pub fn is_function_referenced(&self, fqn: &str) -> bool

Source

pub fn mark_method_referenced_at( &self, fqcn: &str, method_name: &str, file: Arc<str>, line: u32, col_start: u16, col_end: u16, )

Record a method reference with its source location. Also updates the referenced_methods DashSet for dead-code detection.

Source

pub fn mark_property_referenced_at( &self, fqcn: &str, prop_name: &str, file: Arc<str>, line: u32, col_start: u16, col_end: u16, )

Record a property reference with its source location. Also updates the referenced_properties DashSet for dead-code detection.

Source

pub fn mark_function_referenced_at( &self, fqn: &str, file: Arc<str>, line: u32, col_start: u16, col_end: u16, )

Record a function reference with its source location. Also updates the referenced_functions DashSet for dead-code detection.

Source

pub fn mark_class_referenced_at( &self, fqcn: &str, file: Arc<str>, line: u32, col_start: u16, col_end: u16, )

Record a class reference (e.g. new Foo()) with its source location. Does not update any dead-code DashSet — class instantiation tracking is separate from method/property/function dead-code detection.

Source

pub fn replay_reference_locations( &self, file: Arc<str>, locs: &[(String, u32, u16, u16)], )

Replay cached reference locations for a file into the reference index. Called on cache hits to avoid re-running Pass 2 just to rebuild the index. locs is a slice of (symbol_key, line, col_start, col_end) as stored in the cache.

Source

pub fn get_reference_locations( &self, symbol: &str, ) -> Vec<(Arc<str>, u32, u16, u16)>

Return all reference locations for symbol as Vec<(file, line, col_start, col_end)>. Returns an empty Vec if the symbol has no recorded references.

Source

pub fn extract_file_reference_locations( &self, file: &str, ) -> Vec<(Arc<str>, u32, u16, u16)>

Extract all reference locations recorded for file as (symbol_key, line, col_start, col_end) tuples. Used by the cache layer to persist per-file reference data between runs.

Source

pub fn file_has_symbol_references(&self, file: &str) -> bool

Returns true if the given file has any recorded symbol references.

Source

pub fn resolve_pending_import_types(&self)

Resolve @psalm-import-type declarations collected in Pass 1 by copying each referenced source class’s matching type_aliases entry into the importing class. Idempotent — running it after every Pass 1 batch (or after a lazy load) just re-imports the same aliases.

Must be called after all classes referenced by import-type declarations have been collected; otherwise the source type_aliases map is empty and the import resolves to nothing.

Trait Implementations§

Source§

impl Debug for Codebase

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Codebase

Source§

fn default() -> Codebase

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.