Skip to main content

Codebase

Struct Codebase 

Source
pub struct Codebase {
Show 16 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 referenced_methods: DashSet<Arc<str>>, pub referenced_properties: DashSet<Arc<str>>, pub referenced_functions: DashSet<Arc<str>>, pub symbol_reference_locations: DashMap<Arc<str>, HashMap<Arc<str>, HashSet<(u32, u32)>>>, pub file_symbol_references: DashMap<Arc<str>, HashSet<Arc<str>>>, 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.

§referenced_methods: DashSet<Arc<str>>

Methods referenced during Pass 2 — key format: "ClassName::methodName". Used by the dead-code detector (M18).

§referenced_properties: DashSet<Arc<str>>

Properties referenced during Pass 2 — key format: "ClassName::propName".

§referenced_functions: DashSet<Arc<str>>

Free functions referenced during Pass 2 — key: fully-qualified name.

§symbol_reference_locations: DashMap<Arc<str>, HashMap<Arc<str>, HashSet<(u32, u32)>>>

Maps symbol key → { file_path → {(start_byte, end_byte)} }. Key format mirrors referenced_methods / referenced_properties / referenced_functions. The inner HashMap groups all spans from the same file under a single key, avoiding Arc duplication per span and enabling O(1) per-file cleanup. HashSet deduplicates spans from union receivers (e.g. Foo|Foo->method()).

§file_symbol_references: DashMap<Arc<str>, HashSet<Arc<str>>>

Reverse index: file_path → unique symbol keys referenced in that file. Used by remove_file_definitions for O(1) cleanup without a full map scan.

§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 invalidate_finalization(&self)

Reset the finalization flag so that finalize() will run again.

Use this when new class definitions have been added after an initial finalize() call (e.g., lazily loaded via PSR-4) and the inheritance graph needs to be rebuilt.

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. After calling this, invalidate_finalization() is called so the next finalize() rebuilds inheritance.

Source

pub fn register_global_var(&self, file: &Arc<str>, name: Arc<str>, ty: Union)

Record an @var-annotated global variable type discovered in Pass 1. If the same variable is annotated in multiple files, the last write wins.

Source

pub fn get_property( &self, fqcn: &str, prop_name: &str, ) -> Option<PropertyStorage>

Resolve a property, walking up the inheritance chain (parent classes and traits).

Source

pub fn get_method(&self, fqcn: &str, method_name: &str) -> Option<MethodStorage>

Resolve a method, walking up the inheritance chain.

Source

pub fn extends_or_implements(&self, child: &str, ancestor: &str) -> bool

Returns true if child extends or implements ancestor (transitively).

Source

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

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

Source

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

Source

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

Returns true if the class is declared abstract. Used to suppress UndefinedMethod on abstract class receivers: the concrete subclass is expected to implement the method, matching Psalm errorLevel=3 behaviour.

Source

pub fn get_class_template_params(&self, fqcn: &str) -> Vec<TemplateParam>

Return the declared template params for fqcn (class or interface), or an empty vec if the type is not found or has no templates.

Source

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

Returns true if the class (or any ancestor/trait) defines a __get magic method. Such classes allow arbitrary property access, suppressing UndefinedProperty.

Source

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

Returns true if the class (or any of its ancestors) has a parent/interface/trait that is NOT present in the codebase. Used to suppress UndefinedMethod false positives: if a method might be inherited from an unscanned external class we cannot confirm or deny its existence.

We use the pre-computed all_parents list (built during finalization) rather than recursive DashMap lookups to avoid potential deadlocks.

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 get_member_location( &self, fqcn: &str, member_name: &str, ) -> Option<Location>

Look up the definition location of a class member (method, property, constant).

Source

pub fn mark_method_referenced(&self, fqcn: &str, method_name: &str)

Mark a method as referenced from user code.

Source

pub fn mark_property_referenced(&self, fqcn: &str, prop_name: &str)

Mark a property as referenced from user code.

Source

pub fn mark_function_referenced(&self, fqn: &str)

Mark a free function as referenced from user code.

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>, start: u32, end: u32, )

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>, start: u32, end: u32, )

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>, start: u32, end: u32, )

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>, start: u32, end: u32, )

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, u32)], )

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

Source

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

Return all reference locations for symbol as a flat Vec<(file, start, end)>. Returns an empty Vec if the symbol has no recorded references.

Source

pub fn finalize(&self)

Must be called after all files have been parsed (pass 1 complete). Resolves inheritance chains and builds method dispatch tables.

Source§

impl Codebase

Source

pub fn visible_members(&self, ty: &Union) -> Vec<MemberInfo>

Return all members (methods, properties, constants) visible on the given type.

Walks the full class hierarchy including parents, interfaces, traits, and enums. For union types, returns the union of members from all constituent types.

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.