FunctionIndex

Struct FunctionIndex 

Source
pub struct FunctionIndex {
    pub stats: IndexStats,
    /* private fields */
}
Expand description

Arena-based function index that stores each function once and uses indices for multiple lookup strategies.

Provides O(1) lookup by name, qualified name, file+name, or class+method. Handles ambiguity when multiple functions share the same name.

§Memory Efficiency

Each FunctionDef is stored exactly once in the functions arena. All lookup maps use usize indices into this arena, reducing memory from ~7x duplication (with Arc clones) to 1x + indices.

For a project with 10,000 functions:

  • Old: 10,000 FunctionDefs + ~50,000 Arc clones
  • New: 10,000 FunctionDefs + ~50,000 usize indices (8 bytes each)

Fields§

§stats: IndexStats

Statistics for debugging

Implementations§

Source§

impl FunctionIndex

Source

pub fn build(files: &[PathBuf]) -> Result<Self>

Build index from a list of source files using parallel extraction.

Uses rayon for parallel file processing, then merges results.

§Arguments
  • files - List of source file paths to index
§Returns
  • Result<Self> - Built index or error
Source

pub fn build_with_root(files: &[PathBuf], root: Option<&Path>) -> Result<Self>

Build index with an explicit project root for relative path calculation.

§Arguments
  • files - List of source file paths to index
  • root - Optional project root for computing relative paths
§Returns
  • Result<Self> - Built index or error
Source

pub fn lookup(&self, name: &str) -> Vec<&FunctionRef>

Look up all functions with a given simple name.

Returns all functions matching the name, which may be in different files or classes. Use lookup_qualified or lookup_in_file for more precise lookups.

§Arguments
  • name - Simple function name (without module/class prefix)
§Returns
  • Vec<&FunctionRef> - All matching function references
Source

pub fn lookup_qualified(&self, qname: &str) -> Option<&FunctionRef>

Look up a function by its fully qualified name.

§Arguments
  • qname - Fully qualified name (e.g., “module.Class.method”)
§Returns
  • Option<&FunctionRef> - Function reference if found
Source

pub fn lookup_in_file(&self, file: &str, name: &str) -> Option<&FunctionRef>

Look up a function in a specific file by name.

Useful for resolving calls within the same file or to known modules.

§Arguments
  • file - File path (relative or absolute)
  • name - Function name
§Returns
  • Option<&FunctionRef> - Function reference if found
Source

pub fn lookup_method( &self, class_name: &str, method_name: &str, ) -> Vec<&FunctionRef>

Look up a method in a specific class.

Uses the by_class_method secondary index for O(1) average-case lookup. Returns all methods matching the class and method name (may exist in multiple files with the same class name).

§Arguments
  • class_name - Name of the class
  • method_name - Name of the method
§Returns
  • Vec<&FunctionRef> - All matching method references
§Performance

O(1) average case via HashMap lookup, O(k) where k is the number of methods with the same class/method name in different files.

Source

pub fn lookup_simple( &self, simple_module: &str, func_name: &str, ) -> Vec<&FunctionRef>

Look up functions by simple module name and function name.

Enables lookups like “module.func” even when the full qualified name is “pkg.subpkg.module.func”. This matches Python’s indexing strategy where both full and simple module names are indexed.

§Arguments
  • simple_module - Module basename without extension (e.g., “utils”, “helper”)
  • func_name - Function name
§Returns
  • Vec<&FunctionRef> - All matching function references
§Performance

O(1) average case via HashMap lookup.

§Example
// For a function defined in pkg/subpkg/utils.py:
index.lookup_simple("utils", "helper_func") // Finds it!
Source

pub fn get_definition(&self, qname: &str) -> Option<&FunctionDef>

Get full metadata for a function by qualified name.

§Arguments
  • qname - Fully qualified name
§Returns
  • Option<&FunctionDef> - Full function metadata if found
Source

pub fn all_functions(&self) -> impl Iterator<Item = &FunctionRef>

Get all functions in the index.

Source

pub fn len(&self) -> usize

Get the number of indexed functions.

Source

pub fn is_empty(&self) -> bool

Check if the index is empty.

Source

pub fn files(&self) -> impl Iterator<Item = &String>

Get all file paths in the index.

Source

pub fn contains(&self, name: &str) -> bool

Check if a function exists by simple name.

Source

pub fn statistics(&self) -> &IndexStats

Get statistics about the index.

Source

pub fn iter(&self) -> impl Iterator<Item = &FunctionDef>

Iterate over all function definitions.

Provides access to full FunctionDef metadata for all indexed functions.

Trait Implementations§

Source§

impl Debug for FunctionIndex

Source§

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

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

impl Default for FunctionIndex

Source§

fn default() -> FunctionIndex

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more