mirror of https://github.com/astral-sh/ruff
build up constraint sets
This commit is contained in:
parent
83466ed774
commit
dc802d31f2
|
|
@ -1330,6 +1330,7 @@ pub(crate) struct SpecializationBuilder<'db> {
|
||||||
db: &'db dyn Db,
|
db: &'db dyn Db,
|
||||||
inferable: InferableTypeVars<'db, 'db>,
|
inferable: InferableTypeVars<'db, 'db>,
|
||||||
types: FxHashMap<BoundTypeVarIdentity<'db>, Type<'db>>,
|
types: FxHashMap<BoundTypeVarIdentity<'db>, Type<'db>>,
|
||||||
|
constraints: ConstraintSet<'db>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An assignment from a bound type variable to a given type, along with the variance of the outermost
|
/// An assignment from a bound type variable to a given type, along with the variance of the outermost
|
||||||
|
|
@ -1342,6 +1343,7 @@ impl<'db> SpecializationBuilder<'db> {
|
||||||
db,
|
db,
|
||||||
inferable,
|
inferable,
|
||||||
types: FxHashMap::default(),
|
types: FxHashMap::default(),
|
||||||
|
constraints: ConstraintSet::from(true),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1385,6 +1387,32 @@ impl<'db> SpecializationBuilder<'db> {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let constraint = match variance {
|
||||||
|
TypeVarVariance::Covariant => ConstraintSet::constrain_typevar(
|
||||||
|
self.db,
|
||||||
|
bound_typevar,
|
||||||
|
Type::Never,
|
||||||
|
ty,
|
||||||
|
TypeRelation::Assignability,
|
||||||
|
),
|
||||||
|
TypeVarVariance::Contravariant => ConstraintSet::constrain_typevar(
|
||||||
|
self.db,
|
||||||
|
bound_typevar,
|
||||||
|
ty,
|
||||||
|
Type::object(),
|
||||||
|
TypeRelation::Assignability,
|
||||||
|
),
|
||||||
|
TypeVarVariance::Invariant => ConstraintSet::constrain_typevar(
|
||||||
|
self.db,
|
||||||
|
bound_typevar,
|
||||||
|
ty,
|
||||||
|
ty,
|
||||||
|
TypeRelation::Assignability,
|
||||||
|
),
|
||||||
|
TypeVarVariance::Bivariant => ConstraintSet::from(true),
|
||||||
|
};
|
||||||
|
self.constraints.intersect(self.db, constraint);
|
||||||
|
|
||||||
match self.types.entry(identity) {
|
match self.types.entry(identity) {
|
||||||
Entry::Occupied(mut entry) => {
|
Entry::Occupied(mut entry) => {
|
||||||
*entry.get_mut() = UnionType::from_elements(self.db, [*entry.get(), ty]);
|
*entry.get_mut() = UnionType::from_elements(self.db, [*entry.get(), ty]);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue