From d25bceaf8705d9ffc527332191c80d08d174500b Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Wed, 8 Jul 2015 16:37:18 -0700 Subject: [PATCH] Don't bother doing inference from the function parameter if you are about to fix the type parameter --- src/compiler/checker.ts | 28 ++++++---------------------- src/compiler/types.ts | 2 -- 2 files changed, 6 insertions(+), 24 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 05174a43155..35d9abe2fb2 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4239,17 +4239,6 @@ namespace ts { return mapper; } - function fixTypeParametersAfterInferringFromContextualParameterTypes(context: InferenceContext): void { - for (let i = 0; i < context.typeParameters.length; i++) { - let typeParameterInfo = context.inferences[i]; - if (typeParameterInfo.fixAfterInferringFromContextualParameterType) { - typeParameterInfo.fixAfterInferringFromContextualParameterType = false; - typeParameterInfo.isFixed = true; - getInferredType(context, i); - } - } - } - function identityMapper(type: Type): Type { return type; } @@ -5412,8 +5401,7 @@ namespace ts { let inferences: TypeInferences[] = []; for (let unused of typeParameters) { inferences.push({ - primary: undefined, secondary: undefined, - isFixed: false, fixAfterInferringFromContextualParameterType: false + primary: undefined, secondary: undefined, isFixed: false }); } return { @@ -5424,7 +5412,7 @@ namespace ts { }; } - function inferTypes(context: InferenceContext, source: Type, target: Type, inferringFromContextuallyTypedParameter: boolean) { + function inferTypes(context: InferenceContext, source: Type, target: Type) { let sourceStack: Type[]; let targetStack: Type[]; let depth = 0; @@ -5463,9 +5451,6 @@ namespace ts { if (!contains(candidates, source)) { candidates.push(source); } - if (inferringFromContextuallyTypedParameter) { - inferences.fixAfterInferringFromContextualParameterType = true; - } } return; } @@ -7854,7 +7839,7 @@ namespace ts { let context = createInferenceContext(signature.typeParameters, /*inferUnionTypes*/ true); forEachMatchingParameterType(contextualSignature, signature, (source, target) => { // Type parameters from outer context referenced by source type are fixed by instantiation of the source type - inferTypes(context, instantiateType(source, contextualMapper), target, false); + inferTypes(context, instantiateType(source, contextualMapper), target); }); return getSignatureInstantiation(signature, getInferredTypes(context)); } @@ -7904,7 +7889,7 @@ namespace ts { argType = checkExpressionWithContextualType(arg, paramType, mapper); } - inferTypes(context, argType, paramType, false); + inferTypes(context, argType, paramType); } } @@ -7919,7 +7904,7 @@ namespace ts { if (excludeArgument[i] === false) { let arg = args[i]; let paramType = getTypeAtPosition(signature, i); - inferTypes(context, checkExpressionWithContextualType(arg, paramType, inferenceMapper), paramType, false); + inferTypes(context, checkExpressionWithContextualType(arg, paramType, inferenceMapper), paramType); } } } @@ -8823,8 +8808,7 @@ namespace ts { parameterLinks.type = instantiateType(contextualType, mapper); } else if (isInferentialContext(mapper)) { - inferTypes(mapper.context, parameterLinks.type, contextualType, true); - fixTypeParametersAfterInferringFromContextualParameterTypes(mapper.context); + inferTypes(mapper.context, parameterLinks.type, instantiateType(contextualType, mapper)); } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 22dcc89b5e3..7c893da9a6f 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1902,8 +1902,6 @@ namespace ts { secondary: Type[]; // Inferences made to a type parameter in a union type isFixed: boolean; // Whether the type parameter is fixed, as defined in section 4.12.2 of the TypeScript spec // If a type parameter is fixed, no more inferences can be made for the type parameter - - fixAfterInferringFromContextualParameterType: boolean; } /* @internal */