Skip to content

Commit 051c8bd

Browse files
committed
replace voidMap with emptyMap
1 parent 22520da commit 051c8bd

2 files changed

Lines changed: 16 additions & 15 deletions

File tree

src/compiler/checker.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ import {
164164
EmitResolver,
165165
EmitTextWriter,
166166
emptyArray,
167+
emptyMap,
167168
EntityName,
168169
EntityNameExpression,
169170
EntityNameOrEntityNameExpression,
@@ -1124,7 +1125,6 @@ import {
11241125
Visitor,
11251126
VisitResult,
11261127
VoidExpression,
1127-
voidMap,
11281128
walkUpBindingElementsAndPatterns,
11291129
walkUpOuterExpressions,
11301130
walkUpParenthesizedExpressions,
@@ -2111,14 +2111,14 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
21112111
}
21122112
return t;
21132113
}, () => "(unmeasurable reporter)");
2114-
reportUnreliableMapper.instantiations = voidMap;
2114+
reportUnreliableMapper.instantiations = emptyMap;
21152115
var reportUnmeasurableMapper = makeFunctionTypeMapper(t => {
21162116
if (outofbandVarianceMarkerHandler && (t === markerSuperType || t === markerSubType || t === markerOtherType)) {
21172117
outofbandVarianceMarkerHandler(/*onlyUnreliable*/ false);
21182118
}
21192119
return t;
21202120
}, () => "(unreliable reporter)");
2121-
reportUnmeasurableMapper.instantiations = voidMap;
2121+
reportUnmeasurableMapper.instantiations = emptyMap;
21222122

21232123
var emptyObjectType = createAnonymousType(/*symbol*/ undefined, emptySymbols, emptyArray, emptyArray, emptyArray);
21242124
var emptyJsxObjectType = createAnonymousType(/*symbol*/ undefined, emptySymbols, emptyArray, emptyArray, emptyArray);
@@ -20374,16 +20374,23 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2037420374
error(currentNode, Diagnostics.Type_instantiation_is_excessively_deep_and_possibly_infinite);
2037520375
return errorType;
2037620376
}
20377-
const key = type.id + getAliasId(aliasSymbol, aliasTypeArguments);
20378-
const cached = (mapper.instantiations ??= new Map()).get(key);
20379-
if (cached) {
20380-
return cached;
20377+
let key: string
20378+
if (mapper.instantiations !== emptyMap) {
20379+
key = type.id + getAliasId(aliasSymbol, aliasTypeArguments);
20380+
const cached = (mapper.instantiations ??= new Map()).get(key);
20381+
if (cached) {
20382+
return cached;
20383+
}
2038120384
}
2038220385
totalInstantiationCount++;
2038320386
instantiationCount++;
2038420387
instantiationDepth++;
2038520388
const result = instantiateTypeWorker(type, mapper, aliasSymbol, aliasTypeArguments);
20386-
mapper.instantiations?.set(key, result);
20389+
if (mapper.instantiations !== emptyMap) {
20390+
// volatile caches (like on `nonFixingMapper`) could have been cleared by the above `instantiateTypeWorker`
20391+
// if so, we don't want to cache the result as it likely won't be valid anymore anyway
20392+
mapper.instantiations?.set(key!, result);
20393+
}
2038720394
instantiationDepth--;
2038820395
return result;
2038920396
}

src/compiler/core.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,7 @@ import {
1616
/** @internal */
1717
export const emptyArray: never[] = [] as never[];
1818
/** @internal */
19-
export const emptyMap: ReadonlyMap<never, never> = new Map<never, never>();
20-
21-
/** @internal */
22-
export const voidMap: Map<never, never> = new Map<never, never>();
23-
voidMap.set = function () {
24-
return this;
25-
};
19+
export const emptyMap: Map<never, never> = new Map<never, never>();
2620

2721
/** @internal */
2822
export function length(array: readonly any[] | undefined): number {

0 commit comments

Comments
 (0)