Skip to content

Commit f81ba79

Browse files
committed
add doc-comment
1 parent 33a9889 commit f81ba79

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

crates/ty_python_semantic/src/types/cyclic.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,19 @@ pub(crate) type PairVisitor<'db> = CycleDetector<(Type<'db>, Type<'db>), bool>;
2121

2222
#[derive(Debug)]
2323
pub(crate) struct CycleDetector<T, R> {
24+
/// If the type we're visiting is present in `seen`,
25+
/// it indicates that we've hit a cycle (due to a recursive type);
26+
/// we need to immediately short circuit the whole operation and return the fallback value.
27+
/// That's why we pop items off the end of `seen` after we've visited them.
2428
seen: FxIndexSet<T>,
29+
30+
/// Unlike `seen`, this field is a pure performance optimisation (and an essential one).
31+
/// If the type we're trying to normalize is present in `cache`, it doesn't necessarily mean we've hit a cycle:
32+
/// it just means that we've already visited this inner type as part of a bigger call chain we're currently in.
33+
/// Since this cache is just a performance optimisation, it doesn't make sense to pop items off the end of the
34+
/// cache after they've been visited (it would sort-of defeat the point of a cache if we did!)
2535
cache: FxHashMap<T, R>,
36+
2637
fallback: R,
2738
}
2839

0 commit comments

Comments
 (0)