Skip to main content

GraphChecker

Struct GraphChecker 

Source
pub struct GraphChecker<'a> { /* private fields */ }
Expand description

Lightweight graph-based checker for pre-mutation validation.

Uses the existing CodeGraphV2 and SymbolRegistry to quickly validate that mutations are likely to succeed, without running the full compiler.

§Performance Target

OperationTargetvs cargo check
Symbol exists< 1msN/A
Trait impl check< 5msN/A
Derive possible< 50ms100x faster
Full pre-check< 100ms50-100x faster

Implementations§

Source§

impl<'a> GraphChecker<'a>

Source

pub fn new( graph: &'a CodeGraphV2, typeflow: &'a TypeFlowGraphV2, registry: &'a SymbolRegistry, ) -> Self

Create a new GraphChecker.

Source

pub fn with_std_impls( graph: &'a CodeGraphV2, typeflow: &'a TypeFlowGraphV2, registry: &'a SymbolRegistry, std_impls: StdImplCache, ) -> Self

Create a checker with a custom std impls cache.

Source

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

Check if a symbol exists in the registry.

Searches both by full path and by short name.

§Examples
let checker = GraphChecker::new(&graph, &registry);

// Full path lookup
assert!(checker.check_symbol_exists("my_crate::MyStruct"));

// Short name lookup (finds my_crate::MyStruct)
assert!(checker.check_symbol_exists("MyStruct"));
Source

pub fn check_symbol_with_suggestions( &self, name: &str, ) -> Result<(), CheckError>

Check if a symbol exists and return suggestions if not.

Source

pub fn check_symbol_unique(&self, name: &str) -> Result<SymbolId, CheckError>

Check if a symbol is unique (exactly one match).

Returns the SymbolId if exactly one symbol matches, error otherwise.

  • If no symbols found: UnresolvedRef error
  • If multiple symbols found: AmbiguousTarget error
§Examples
let checker = GraphChecker::new(&graph, &registry);

// Unique symbol - returns SymbolId
let id = checker.check_symbol_unique("Config")?;

// Multiple Config in different modules - AmbiguousTarget error
// e.g., my_crate::config::Config and my_crate::settings::Config
Source

pub fn check_trait_impl(&self, type_name: &str, trait_name: &str) -> bool

Check if a type implements a trait.

First checks the std impls cache, then searches the CodeGraph for Implements edges.

Source

pub fn check_derive_possible( &self, target: &str, trait_name: &str, ) -> CheckResult

Check if a derive macro can be applied to a type.

Verifies that all fields of the type implement the required trait.

§Returns
  • CheckResult::Ok if derive is possible
  • CheckResult::Error with missing implementations
Source

pub fn check_field_exists( &self, type_name: &str, field_name: &str, ) -> Result<(), CheckError>

Check if a struct/type has a specific field.

Returns Ok if the field exists, Error with available fields if not.

§Examples
let checker = GraphChecker::new(&graph, &registry);

// Check if Payment has a 'created_at' field
match checker.check_field_exists("Payment", "created_at") {
    Ok(()) => { /* field exists */ }
    Err(e) => { /* field not found, e contains suggestions */ }
}
Source

pub fn check_method_exists( &self, type_name: &str, method_name: &str, ) -> Result<(), CheckError>

Check if a type has a specific method.

Searches for methods by looking up TypeName::method_name pattern and checking direct children of the type.

Source

pub fn check_enum_variant_exists( &self, enum_name: &str, variant_name: &str, ) -> Result<(), CheckError>

Check if an enum has a specific variant.

Source

pub fn check_struct_fields_complete( &self, struct_name: &str, provided_fields: &[&str], ) -> Result<(), CheckError>

Check if all required fields are provided for a struct literal.

Returns Ok if all fields are covered, Error with missing fields if not.

Source

pub fn get_function_arg_count(&self, fn_name: &str) -> Option<usize>

Get the expected argument count for a function.

Returns None if the function is not found or count cannot be determined.

Source

pub fn check_function_arg_count( &self, fn_name: &str, actual_count: usize, ) -> Result<(), CheckError>

Check if the argument count matches for a function call.

Source

pub fn check_symbols_exist(&self, names: &[&str]) -> CheckResult

Check multiple symbols exist.

Source

pub fn check_trait_impls(&self, checks: &[(&str, &str)]) -> CheckResult

Check multiple trait implementations.

Source

pub fn graph(&self) -> &CodeGraphV2

Get a reference to the CodeGraphV2.

Source

pub fn registry(&self) -> &SymbolRegistry

Get a reference to the SymbolRegistry.

Source

pub fn std_impls(&self) -> &StdImplCache

Get a reference to the StdImplCache.

Trait Implementations§

Source§

impl LightCheck for GraphChecker<'_>

Source§

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

Check if a symbol exists in the codebase. Read more
Source§

fn check_trait_impl(&self, type_name: &str, trait_name: &str) -> bool

Check if a type implements a trait. Read more
Source§

fn check_derive_possible(&self, target: &str, trait_name: &str) -> CheckResult

Check if a derive macro can be applied to a type. Read more
Source§

fn pre_check(&self, mutation_type: &str, target: &str) -> CheckResult

Pre-check before applying a mutation. Read more
Source§

fn post_check(&self, mutation_type: &str, target: &str) -> CheckResult

Post-check after applying a mutation. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for GraphChecker<'a>

§

impl<'a> RefUnwindSafe for GraphChecker<'a>

§

impl<'a> Send for GraphChecker<'a>

§

impl<'a> Sync for GraphChecker<'a>

§

impl<'a> Unpin for GraphChecker<'a>

§

impl<'a> UnsafeUnpin for GraphChecker<'a>

§

impl<'a> UnwindSafe for GraphChecker<'a>

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

Source§

type Output = T

Should always be Self
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.