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: InternerInterner for symbol keys ("ClassName::method", "ClassName::prop", FQN).
Replaces repeated Arc<str> copies (16 bytes) with compact u32 IDs (4 bytes).
file_interner: InternerInterner 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
impl Codebase
pub fn new() -> Self
Sourcepub fn inject_stub_slice(&self, slice: StubSlice)
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.
Sourcepub fn compact_reference_index(&self)
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:
- Drains the two build-phase
DashMaps into a single flatVec. - Sorts and deduplicates entries.
- Builds two CSR offset arrays (by symbol and by file).
- 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.
Sourcepub fn invalidate_finalization(&self)
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.
Sourcepub fn remove_file_definitions(&self, file_path: &str)
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.
Sourcepub fn file_structural_snapshot(&self, file_path: &str) -> StructuralSnapshot
pub fn file_structural_snapshot(&self, file_path: &str) -> StructuralSnapshot
Capture the inheritance structure of all symbols defined in file_path.
Call this before remove_file_definitions to preserve the data that
finalize() would otherwise have to recompute. The snapshot records, for
each class/interface in the file, the fields that feed into
all_parents (parent class, implemented interfaces, used traits, extended
interfaces) as well as the already-computed all_parents list itself.
Sourcepub fn structural_unchanged_after_pass1(
&self,
file_path: &str,
old: &StructuralSnapshot,
) -> bool
pub fn structural_unchanged_after_pass1( &self, file_path: &str, old: &StructuralSnapshot, ) -> bool
After Pass 1 completes, check whether the inheritance structure in
file_path matches the snapshot taken before remove_file_definitions.
Returns true if finalize() can be skipped — i.e. only method bodies,
properties, or annotations changed, not any class/interface hierarchy.
Sourcepub fn restore_all_parents(
&self,
file_path: &str,
snapshot: &StructuralSnapshot,
)
pub fn restore_all_parents( &self, file_path: &str, snapshot: &StructuralSnapshot, )
Restore all_parents from a snapshot and mark the codebase as finalized.
Call this instead of finalize() when structural_unchanged_after_pass1
returns true. The newly re-registered symbols (written by Pass 1) have
all_parents = []; this method repopulates them from the snapshot so that
all downstream lookups that depend on all_parents keep working correctly.
Sourcepub fn register_global_var(&self, file: &Arc<str>, name: Arc<str>, ty: Union)
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.
Sourcepub fn get_property(
&self,
fqcn: &str,
prop_name: &str,
) -> Option<PropertyStorage>
pub fn get_property( &self, fqcn: &str, prop_name: &str, ) -> Option<PropertyStorage>
Resolve a property, walking up the inheritance chain (parent classes and traits).
Sourcepub fn get_class_constant(
&self,
fqcn: &str,
const_name: &str,
) -> Option<ConstantStorage>
pub fn get_class_constant( &self, fqcn: &str, const_name: &str, ) -> Option<ConstantStorage>
Resolve a class constant by name, walking up the inheritance chain.
Sourcepub fn get_method(
&self,
fqcn: &str,
method_name: &str,
) -> Option<Arc<MethodStorage>>
pub fn get_method( &self, fqcn: &str, method_name: &str, ) -> Option<Arc<MethodStorage>>
Resolve a method, walking up the full inheritance chain (own → traits → ancestors).
Sourcepub fn extends_or_implements(&self, child: &str, ancestor: &str) -> bool
pub fn extends_or_implements(&self, child: &str, ancestor: &str) -> bool
Returns true if child extends or implements ancestor (transitively).
Sourcepub fn type_exists(&self, fqcn: &str) -> bool
pub fn type_exists(&self, fqcn: &str) -> bool
Whether a class/interface/trait/enum with this FQCN exists.
pub fn function_exists(&self, fqn: &str) -> bool
Sourcepub fn is_abstract_class(&self, fqcn: &str) -> bool
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.
Sourcepub fn get_class_template_params(&self, fqcn: &str) -> Vec<TemplateParam>
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.
Sourcepub fn get_inherited_template_bindings(
&self,
fqcn: &str,
) -> HashMap<Arc<str>, Union>
pub fn get_inherited_template_bindings( &self, fqcn: &str, ) -> HashMap<Arc<str>, Union>
Walk the parent chain collecting template bindings from @extends type args.
For class UserRepo extends BaseRepo with @extends BaseRepo<User>, this returns
{ T → User } where T is BaseRepo’s declared template parameter.
Sourcepub fn has_magic_get(&self, fqcn: &str) -> bool
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.
Sourcepub fn has_unknown_ancestor(&self, fqcn: &str) -> bool
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.
Sourcepub fn resolve_class_name(&self, file: &str, name: &str) -> String
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,staticare returned unchanged (caller handles them).
Sourcepub fn get_symbol_location(&self, fqcn: &str) -> Option<Location>
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.
Sourcepub fn get_member_location(
&self,
fqcn: &str,
member_name: &str,
) -> Option<Location>
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).
Sourcepub fn mark_method_referenced(&self, fqcn: &str, method_name: &str)
pub fn mark_method_referenced(&self, fqcn: &str, method_name: &str)
Mark a method as referenced from user code.
Sourcepub fn mark_property_referenced(&self, fqcn: &str, prop_name: &str)
pub fn mark_property_referenced(&self, fqcn: &str, prop_name: &str)
Mark a property as referenced from user code.
Sourcepub fn mark_function_referenced(&self, fqn: &str)
pub fn mark_function_referenced(&self, fqn: &str)
Mark a free function as referenced from user code.
pub fn is_method_referenced(&self, fqcn: &str, method_name: &str) -> bool
pub fn is_property_referenced(&self, fqcn: &str, prop_name: &str) -> bool
pub fn is_function_referenced(&self, fqn: &str) -> bool
Sourcepub fn mark_method_referenced_at(
&self,
fqcn: &str,
method_name: &str,
file: Arc<str>,
start: u32,
end: u32,
)
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.
Sourcepub fn mark_property_referenced_at(
&self,
fqcn: &str,
prop_name: &str,
file: Arc<str>,
start: u32,
end: u32,
)
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.
Sourcepub fn mark_function_referenced_at(
&self,
fqn: &str,
file: Arc<str>,
start: u32,
end: u32,
)
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.
Sourcepub fn mark_class_referenced_at(
&self,
fqcn: &str,
file: Arc<str>,
start: u32,
end: u32,
)
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.
Sourcepub fn replay_reference_locations(
&self,
file: Arc<str>,
locs: &[(String, u32, u32)],
)
pub fn replay_reference_locations( &self, file: Arc<str>, locs: &[(String, u32, u32)], )
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, start_byte, end_byte) as stored in the cache.
Sourcepub fn get_reference_locations(&self, symbol: &str) -> Vec<(Arc<str>, u32, u32)>
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.
Sourcepub fn extract_file_reference_locations(
&self,
file: &str,
) -> Vec<(Arc<str>, u32, u32)>
pub fn extract_file_reference_locations( &self, file: &str, ) -> Vec<(Arc<str>, u32, u32)>
Extract all reference locations recorded for file as (symbol_key, start, end) triples.
Used by the cache layer to persist per-file reference data between runs.
Sourcepub fn file_has_symbol_references(&self, file: &str) -> bool
pub fn file_has_symbol_references(&self, file: &str) -> bool
Returns true if the given file has any recorded symbol references.
Source§impl Codebase
impl Codebase
Sourcepub fn visible_members(&self, ty: &Union) -> Vec<MemberInfo>
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.