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
| Operation | Target | vs cargo check |
|---|---|---|
| Symbol exists | < 1ms | N/A |
| Trait impl check | < 5ms | N/A |
| Derive possible | < 50ms | 100x faster |
| Full pre-check | < 100ms | 50-100x faster |
Implementations§
Source§impl<'a> GraphChecker<'a>
impl<'a> GraphChecker<'a>
Sourcepub fn new(
graph: &'a CodeGraphV2,
typeflow: &'a TypeFlowGraphV2,
registry: &'a SymbolRegistry,
) -> Self
pub fn new( graph: &'a CodeGraphV2, typeflow: &'a TypeFlowGraphV2, registry: &'a SymbolRegistry, ) -> Self
Create a new GraphChecker.
Sourcepub fn with_std_impls(
graph: &'a CodeGraphV2,
typeflow: &'a TypeFlowGraphV2,
registry: &'a SymbolRegistry,
std_impls: StdImplCache,
) -> Self
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.
Sourcepub fn check_symbol_exists(&self, name: &str) -> bool
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, ®istry);
// Full path lookup
assert!(checker.check_symbol_exists("my_crate::MyStruct"));
// Short name lookup (finds my_crate::MyStruct)
assert!(checker.check_symbol_exists("MyStruct"));Sourcepub fn check_symbol_with_suggestions(
&self,
name: &str,
) -> Result<(), CheckError>
pub fn check_symbol_with_suggestions( &self, name: &str, ) -> Result<(), CheckError>
Check if a symbol exists and return suggestions if not.
Sourcepub fn check_symbol_unique(&self, name: &str) -> Result<SymbolId, CheckError>
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, ®istry);
// 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::ConfigSourcepub fn check_trait_impl(&self, type_name: &str, trait_name: &str) -> bool
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.
Sourcepub fn check_derive_possible(
&self,
target: &str,
trait_name: &str,
) -> CheckResult
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::Okif derive is possibleCheckResult::Errorwith missing implementations
Sourcepub fn check_field_exists(
&self,
type_name: &str,
field_name: &str,
) -> Result<(), CheckError>
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, ®istry);
// 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 */ }
}Sourcepub fn check_method_exists(
&self,
type_name: &str,
method_name: &str,
) -> Result<(), CheckError>
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.
Sourcepub fn check_enum_variant_exists(
&self,
enum_name: &str,
variant_name: &str,
) -> Result<(), CheckError>
pub fn check_enum_variant_exists( &self, enum_name: &str, variant_name: &str, ) -> Result<(), CheckError>
Check if an enum has a specific variant.
Sourcepub fn check_struct_fields_complete(
&self,
struct_name: &str,
provided_fields: &[&str],
) -> Result<(), CheckError>
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.
Sourcepub fn get_function_arg_count(&self, fn_name: &str) -> Option<usize>
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.
Sourcepub fn check_function_arg_count(
&self,
fn_name: &str,
actual_count: usize,
) -> Result<(), CheckError>
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.
Sourcepub fn check_symbols_exist(&self, names: &[&str]) -> CheckResult
pub fn check_symbols_exist(&self, names: &[&str]) -> CheckResult
Check multiple symbols exist.
Sourcepub fn check_trait_impls(&self, checks: &[(&str, &str)]) -> CheckResult
pub fn check_trait_impls(&self, checks: &[(&str, &str)]) -> CheckResult
Check multiple trait implementations.
Sourcepub fn graph(&self) -> &CodeGraphV2
pub fn graph(&self) -> &CodeGraphV2
Get a reference to the CodeGraphV2.
Sourcepub fn registry(&self) -> &SymbolRegistry
pub fn registry(&self) -> &SymbolRegistry
Get a reference to the SymbolRegistry.
Sourcepub fn std_impls(&self) -> &StdImplCache
pub fn std_impls(&self) -> &StdImplCache
Get a reference to the StdImplCache.
Trait Implementations§
Source§impl LightCheck for GraphChecker<'_>
impl LightCheck for GraphChecker<'_>
Source§fn check_symbol_exists(&self, name: &str) -> bool
fn check_symbol_exists(&self, name: &str) -> bool
Source§fn check_trait_impl(&self, type_name: &str, trait_name: &str) -> bool
fn check_trait_impl(&self, type_name: &str, trait_name: &str) -> bool
Source§fn check_derive_possible(&self, target: &str, trait_name: &str) -> CheckResult
fn check_derive_possible(&self, target: &str, trait_name: &str) -> CheckResult
Source§fn pre_check(&self, mutation_type: &str, target: &str) -> CheckResult
fn pre_check(&self, mutation_type: &str, target: &str) -> CheckResult
Source§fn post_check(&self, mutation_type: &str, target: &str) -> CheckResult
fn post_check(&self, mutation_type: &str, target: &str) -> CheckResult
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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