pub struct InstanceResolver { /* private fields */ }Expand description
Instance resolution engine.
Maintains a registry of type-class instances organised by class name. Supports priority-based selection, caching, and backtracking search.
Implementations§
Source§impl InstanceResolver
impl InstanceResolver
Sourcepub fn with_max_depth(max_depth: usize) -> Self
pub fn with_max_depth(max_depth: usize) -> Self
Create a resolver with a custom search depth.
Sourcepub fn register(&mut self, instance: InstanceDecl)
pub fn register(&mut self, instance: InstanceDecl)
Register an instance.
Sourcepub fn register_many(
&mut self,
instances: impl IntoIterator<Item = InstanceDecl>,
)
pub fn register_many( &mut self, instances: impl IntoIterator<Item = InstanceDecl>, )
Register multiple instances at once.
Sourcepub fn clear_class(&mut self, class: &Name)
pub fn clear_class(&mut self, class: &Name)
Remove all instances for a given class (useful in testing).
Sourcepub fn find_instance(
&mut self,
class: &Name,
ty: &Expr,
) -> Option<&InstanceDecl>
pub fn find_instance( &mut self, class: &Name, ty: &Expr, ) -> Option<&InstanceDecl>
Find an instance for a type class and type.
Returns the highest-priority matching instance, or None.
If the cache is enabled, previously found instances are returned immediately.
Sourcepub fn resolve(&mut self, class: &Name, ty: &Expr) -> ResolutionResult
pub fn resolve(&mut self, class: &Name, ty: &Expr) -> ResolutionResult
Resolve an instance and return the full ResolutionResult.
Unlike find_instance, this method detects ambiguity.
Sourcepub fn resolve_or_error(
&mut self,
class: &Name,
ty: &Expr,
) -> Result<Name, InstanceError>
pub fn resolve_or_error( &mut self, class: &Name, ty: &Expr, ) -> Result<Name, InstanceError>
Try to resolve, returning Err with a detailed error on failure.
Sourcepub fn get_instances(&self, class: &Name) -> Vec<&InstanceDecl>
pub fn get_instances(&self, class: &Name) -> Vec<&InstanceDecl>
Get all instances for a class.
Sourcepub fn class_count(&self) -> usize
pub fn class_count(&self) -> usize
Return the number of classes registered.
Sourcepub fn total_registered(&self) -> usize
pub fn total_registered(&self) -> usize
Return the total number of instances registered.
Sourcepub fn set_max_depth(&mut self, depth: usize)
pub fn set_max_depth(&mut self, depth: usize)
Set the maximum search depth.
Sourcepub fn set_cache_enabled(&mut self, enabled: bool)
pub fn set_cache_enabled(&mut self, enabled: bool)
Enable or disable the resolution cache.
Sourcepub fn cache_enabled(&self) -> bool
pub fn cache_enabled(&self) -> bool
Return whether caching is enabled.
Sourcepub fn cache(&self) -> &InstanceCache
pub fn cache(&self) -> &InstanceCache
Obtain a reference to the resolution cache for diagnostics.
Sourcepub fn clear_cache(&mut self)
pub fn clear_cache(&mut self)
Clear the resolution cache.
Sourcepub fn has_instances_for(&self, class: &Name) -> bool
pub fn has_instances_for(&self, class: &Name) -> bool
Check whether any instance is registered for a given class.
Sourcepub fn registered_classes(&self) -> Vec<&Name>
pub fn registered_classes(&self) -> Vec<&Name>
Return all class names that have at least one instance.