Skip to content

Commit e65cf19

Browse files
committed
Rename class, add assert
1 parent 3448841 commit e65cf19

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

src/compiler/checker.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,18 +1042,23 @@ namespace ts {
10421042
let _jsxNamespace: __String;
10431043
let _jsxFactoryEntity: EntityName | undefined;
10441044

1045-
class InfiniMap<K, V> {
1046-
private next?: InfiniMap<K, V>;
1045+
class ExpandableRelationshipCache<K, V> {
1046+
private next?: ExpandableRelationshipCache<K, V>;
10471047
private inner: ESMap<K, V>;
10481048
constructor() {
10491049
this.inner = new Map();
10501050
}
10511051
get(key: K): V | undefined {
10521052
return this.inner.has(key) ? this.inner.get(key) : this.next?.get(key);
10531053
}
1054+
/**
1055+
* Unlike a normal map, this expects `set` to be called exactly once for a given key, and then never again
1056+
* - the caller should always be checking if the cache `.has` the member it would set.
1057+
*/
10541058
set(key: K, value: V): this {
1059+
Debug.assert(!this.inner.has(key));
10551060
if (this.inner.size > ((2 ** 24) - 1)) {
1056-
this.next ||= new InfiniMap();
1061+
this.next ||= new ExpandableRelationshipCache();
10571062
this.next.set(key, value);
10581063
}
10591064
else {
@@ -1072,7 +1077,7 @@ namespace ts {
10721077
delete(key: K): boolean {
10731078
return this.inner.delete(key) || !!this.next?.delete(key);
10741079
}
1075-
forEach(callbackfn: (value: V, key: K, map: InfiniMap<K, V>) => void): void {
1080+
forEach(callbackfn: (value: V, key: K, map: ExpandableRelationshipCache<K, V>) => void): void {
10761081
this.inner.forEach((v, k) => callbackfn(v, k, this));
10771082
this.next?.forEach((v, k) => callbackfn(v, k, this));
10781083
}
@@ -1081,13 +1086,13 @@ namespace ts {
10811086
}
10821087
}
10831088

1084-
type RelationCache = InfiniMap<string, RelationComparisonResult>;
1085-
const subtypeRelation = new InfiniMap<string, RelationComparisonResult>();
1086-
const strictSubtypeRelation = new InfiniMap<string, RelationComparisonResult>();
1087-
const assignableRelation = new InfiniMap<string, RelationComparisonResult>();
1088-
const comparableRelation = new InfiniMap<string, RelationComparisonResult>();
1089-
const identityRelation = new InfiniMap<string, RelationComparisonResult>();
1090-
const enumRelation = new InfiniMap<string, RelationComparisonResult>();
1089+
type RelationCache = ExpandableRelationshipCache<string, RelationComparisonResult>;
1090+
const subtypeRelation = new ExpandableRelationshipCache<string, RelationComparisonResult>();
1091+
const strictSubtypeRelation = new ExpandableRelationshipCache<string, RelationComparisonResult>();
1092+
const assignableRelation = new ExpandableRelationshipCache<string, RelationComparisonResult>();
1093+
const comparableRelation = new ExpandableRelationshipCache<string, RelationComparisonResult>();
1094+
const identityRelation = new ExpandableRelationshipCache<string, RelationComparisonResult>();
1095+
const enumRelation = new ExpandableRelationshipCache<string, RelationComparisonResult>();
10911096

10921097
const builtinGlobals = createSymbolTable();
10931098
builtinGlobals.set(undefinedSymbol.escapedName, undefinedSymbol);

0 commit comments

Comments
 (0)