@@ -469,25 +469,10 @@ namespace ts {
469469 };
470470
471471 const subtypeRelation = createMap<RelationComparisonResult>();
472- const subtypeRelationErrors = createMap<DiagnosticMessageChain>();
473472 const assignableRelation = createMap<RelationComparisonResult>();
474- const assignableRelationErrors = createMap<DiagnosticMessageChain>();
475473 const comparableRelation = createMap<RelationComparisonResult>();
476- const comparableRelationErrors = createMap<DiagnosticMessageChain>();
477474 const identityRelation = createMap<RelationComparisonResult>();
478- const identityRelationErrors = createMap<DiagnosticMessageChain>();
479475 const enumRelation = createMap<boolean>();
480- const enumRelationErrors = createMap<DiagnosticMessageChain>();
481-
482- function getErrorCache(relation: Map<RelationComparisonResult> | Map<boolean>) {
483- switch (true) {
484- case relation === subtypeRelation: return subtypeRelationErrors;
485- case relation === assignableRelation: return assignableRelationErrors;
486- case relation === comparableRelation: return comparableRelationErrors;
487- case relation === identityRelation: return identityRelationErrors;
488- case relation === enumRelation: return enumRelationErrors;
489- }
490- }
491476
492477 // This is for caching the result of getSymbolDisplayBuilder. Do not access directly.
493478 let _displayBuilder: SymbolDisplayBuilder;
@@ -8933,17 +8918,6 @@ namespace ts {
89338918 * * Ternary.False if they are not related.
89348919 */
89358920 function isRelatedTo(source: Type, target: Type, reportErrors?: boolean, headMessage?: DiagnosticMessage): Ternary {
8936- const comparisonId = comparisonTypeId(source, target);
8937- const cachedResult = fetchRelationResult(comparisonId);
8938- if (cachedResult !== undefined) {
8939- if (reportErrors && cachedResult === Ternary.False) {
8940- const cachedChain = getErrorCache(relation).get(comparisonId);
8941- if (cachedChain) {
8942- errorInfo = concatenateDiagnosticMessageChains(errorInfo, cachedChain);
8943- }
8944- }
8945- return cachedResult;
8946- }
89478921 if (source.flags & TypeFlags.StringOrNumberLiteral && source.flags & TypeFlags.FreshLiteral) {
89488922 source = (<LiteralType>source).regularType;
89498923 }
@@ -9054,14 +9028,6 @@ namespace ts {
90549028 }
90559029 reportRelationError(headMessage, source, target);
90569030 }
9057-
9058- if (fetchRelationResult(comparisonId) === undefined) {
9059- relation.set(comparisonId, result ? RelationComparisonResult.Succeeded : reportErrors ? RelationComparisonResult.FailedAndReported : RelationComparisonResult.Failed);
9060- if (reportErrors && errorInfo) {
9061- getErrorCache(relation).set(comparisonId, errorInfo);
9062- }
9063- }
9064-
90659031 return result;
90669032 }
90679033
@@ -9224,24 +9190,6 @@ namespace ts {
92249190 return result;
92259191 }
92269192
9227- function comparisonTypeId(source: Type, target: Type) {
9228- return relation !== identityRelation || source.id < target.id ? source.id + "," + target.id : target.id + "," + source.id;
9229- }
9230-
9231- function fetchRelationResult(id: string, reportErrors?: boolean): Ternary | undefined {
9232- const related = relation.get(id);
9233- if (related !== undefined) {
9234- if (reportErrors && related === RelationComparisonResult.Failed) {
9235- // We are elaborating errors and the cached result is an unreported failure. Record the result as a reported
9236- // failure and continue computing the relation such that errors get reported.
9237- relation.set(id, RelationComparisonResult.FailedAndReported);
9238- }
9239- else {
9240- return related === RelationComparisonResult.Succeeded ? Ternary.True : Ternary.False;
9241- }
9242- }
9243- }
9244-
92459193 // Determine if possibly recursive types are related. First, check if the result is already available in the global cache.
92469194 // Second, check if we have already started a comparison of the given two types in which case we assume the result to be true.
92479195 // Third, check if both types are part of deeply nested chains of generic type instantiations and if so assume the types are
@@ -9260,7 +9208,7 @@ namespace ts {
92609208 // this is a copy of the normal code! It can probably be merged somehow.
92619209 const src = (source as TypeReference).target;
92629210 const trg = (target as TypeReference).target;
9263- const id = comparisonTypeId( src, trg) ;
9211+ const id = relation !== identityRelation || src.id < trg.id ? src.id + "," + trg.id : trg.id + "," + src.id ;
92649212 if (!maybeReferenceKeys) {
92659213 maybeReferenceKeys = [];
92669214 }
@@ -9275,11 +9223,19 @@ namespace ts {
92759223 maybeReferenceCount++;
92769224 }
92779225
9278- const id = comparisonTypeId(source, target);
9279- const cachedResult = fetchRelationResult(id);
9280- if (cachedResult !== undefined) {
9281- return cachedResult;
9226+ const id = relation !== identityRelation || source.id < target.id ? source.id + "," + target.id : target.id + "," + source.id;
9227+ const related = relation.get(id);
9228+ if (related !== undefined) {
9229+ if (reportErrors && related === RelationComparisonResult.Failed) {
9230+ // We are elaborating errors and the cached result is an unreported failure. Record the result as a reported
9231+ // failure and continue computing the relation such that errors get reported.
9232+ relation.set(id, RelationComparisonResult.FailedAndReported);
9233+ }
9234+ else {
9235+ return related === RelationComparisonResult.Succeeded ? Ternary.True : Ternary.False;
9236+ }
92829237 }
9238+
92839239 if (!maybeKeys) {
92849240 maybeKeys = [];
92859241 sourceStack = [];
0 commit comments