mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 21:04:51 +00:00
salsa cache is_subtype_of, with cycle handling
This commit is contained in:
parent
ab05f3b3ee
commit
3c75a7705d
2 changed files with 21 additions and 1 deletions
|
@ -369,5 +369,5 @@ type Y = X | str | dict[str, Y]
|
|||
|
||||
def _(y: Y):
|
||||
if isinstance(y, dict):
|
||||
reveal_type(y)
|
||||
reveal_type(y) # revealed: dict[str, X] | dict[str, Y]
|
||||
```
|
||||
|
|
|
@ -1423,6 +1423,7 @@ impl<'db> Type<'db> {
|
|||
/// P`, but not `B <: P`. Losing transitivity of subtyping is not tenable (it makes union and
|
||||
/// intersection simplification dependent on the order in which elements are added), so we do
|
||||
/// not use this more general definition of subtyping.
|
||||
#[salsa::tracked(cycle_fn=is_subtype_of_cycle_recover, cycle_initial=is_subtype_of_cycle_initial)]
|
||||
pub(crate) fn is_subtype_of(self, db: &'db dyn Db, target: Type<'db>) -> bool {
|
||||
self.when_subtype_of(db, target).is_always_satisfied()
|
||||
}
|
||||
|
@ -6690,6 +6691,25 @@ impl<'db> VarianceInferable<'db> for Type<'db> {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::trivially_copy_pass_by_ref)]
|
||||
fn is_subtype_of_cycle_recover<'db>(
|
||||
_db: &'db dyn Db,
|
||||
_value: &bool,
|
||||
_count: u32,
|
||||
_subtype: Type<'db>,
|
||||
_supertype: Type<'db>,
|
||||
) -> salsa::CycleRecoveryAction<bool> {
|
||||
salsa::CycleRecoveryAction::Iterate
|
||||
}
|
||||
|
||||
fn is_subtype_of_cycle_initial<'db>(
|
||||
_db: &'db dyn Db,
|
||||
_subtype: Type<'db>,
|
||||
_supertype: Type<'db>,
|
||||
) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn apply_specialization_cycle_recover<'db>(
|
||||
_db: &'db dyn Db,
|
||||
_value: &Type<'db>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue