pub struct ConstraintSet {
pub lower_bounds: Vec<TypeId>,
pub upper_bounds: Vec<TypeId>,
}Expand description
Constraint set for an inference variable. Tracks both lower bounds (L <: α) and upper bounds (α <: U).
Fields§
§lower_bounds: Vec<TypeId>Lower bounds: types that must be subtypes of this variable e.g., from argument types being assigned to a parameter
upper_bounds: Vec<TypeId>Upper bounds: types that this variable must be a subtype of
e.g., from extends constraints on type parameters
Implementations§
Source§impl ConstraintSet
impl ConstraintSet
pub const fn new() -> Self
pub fn from_info(info: &InferenceInfo) -> Self
Sourcepub fn add_lower_bound(&mut self, ty: TypeId)
pub fn add_lower_bound(&mut self, ty: TypeId)
Add a lower bound constraint: L <: α
Sourcepub fn add_upper_bound(&mut self, ty: TypeId)
pub fn add_upper_bound(&mut self, ty: TypeId)
Add an upper bound constraint: α <: U
pub fn merge_from(&mut self, other: Self)
Sourcepub fn transitive_reduction(&mut self, interner: &dyn TypeDatabase)
pub fn transitive_reduction(&mut self, interner: &dyn TypeDatabase)
Perform transitive reduction on upper bounds to remove redundant constraints.
If we have constraints (T <: A) and (T <: B) and we know (A <: B), then (T <: B) is redundant and can be removed.
This reduces N² pairwise checks in detect_conflicts to O(N * reduced_N).
Sourcepub fn detect_conflicts(
&self,
interner: &dyn TypeDatabase,
) -> Option<ConstraintConflict>
pub fn detect_conflicts( &self, interner: &dyn TypeDatabase, ) -> Option<ConstraintConflict>
Detect early conflicts between collected constraints. This allows failing fast before full resolution.
Trait Implementations§
Source§impl Clone for ConstraintSet
impl Clone for ConstraintSet
Source§fn clone(&self) -> ConstraintSet
fn clone(&self) -> ConstraintSet
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more