Skip to content

Commit 5a9645a

Browse files
committed
make the DateType benchmark finish!
1 parent 58f1b19 commit 5a9645a

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

crates/ty_python_semantic/src/types/cyclic.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use rustc_hash::FxHashMap;
2+
13
use crate::FxIndexSet;
24
use crate::types::Type;
35
use std::cmp::Eq;
@@ -20,13 +22,15 @@ pub(crate) type PairVisitor<'db> = CycleDetector<(Type<'db>, Type<'db>), bool>;
2022
#[derive(Debug)]
2123
pub(crate) struct CycleDetector<T, R> {
2224
seen: FxIndexSet<T>,
25+
cache: FxHashMap<T, R>,
2326
fallback: R,
2427
}
2528

26-
impl<T: Hash + Eq, R: Copy> CycleDetector<T, R> {
29+
impl<T: Hash + Eq + Copy, R: Copy> CycleDetector<T, R> {
2730
pub(crate) fn new(fallback: R) -> Self {
2831
CycleDetector {
2932
seen: FxIndexSet::default(),
33+
cache: FxHashMap::default(),
3034
fallback,
3135
}
3236
}
@@ -35,7 +39,12 @@ impl<T: Hash + Eq, R: Copy> CycleDetector<T, R> {
3539
if !self.seen.insert(item) {
3640
return self.fallback;
3741
}
42+
if let Some(ty) = self.cache.get(&item) {
43+
self.seen.pop();
44+
return *ty;
45+
}
3846
let ret = func(self);
47+
self.cache.insert(item, ret);
3948
self.seen.pop();
4049
ret
4150
}

crates/ty_python_semantic/src/types/instance.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,14 @@ impl<'db> ProtocolInstanceType<'db> {
270270
///
271271
/// TODO: consider the types of the members as well as their existence
272272
pub(super) fn is_equivalent_to(self, db: &'db dyn Db, other: Self) -> bool {
273-
self.normalized(db) == other.normalized(db)
273+
if self == other {
274+
return true;
275+
}
276+
let self_normalized = self.normalized(db);
277+
if self_normalized == Type::ProtocolInstance(other) {
278+
return true;
279+
}
280+
self_normalized == other.normalized(db)
274281
}
275282

276283
/// Return `true` if this protocol type is disjoint from the protocol `other`.

0 commit comments

Comments
 (0)