Skip to content

Commit

Permalink
Further mitigated perf overhead.
Browse files Browse the repository at this point in the history
  • Loading branch information
msfterictraut committed Oct 5, 2019
1 parent c24a00d commit 8f649e4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 23 deletions.
17 changes: 12 additions & 5 deletions server/src/analyzer/expressionEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ interface FunctionArgument {

interface ValidateArgTypeParams {
paramType: Type;
requiresTypeVarMatching: boolean;
argument: FunctionArgument;
errorNode: ExpressionNode;
paramName?: string;
Expand Down Expand Up @@ -2265,6 +2266,7 @@ export class ExpressionEvaluator {

validateArgTypeParams.push({
paramType,
requiresTypeVarMatching: requiresSpecialization(paramType),
argument: funcArg,
errorNode: argList[argIndex].valueExpression || errorNode
});
Expand All @@ -2273,6 +2275,7 @@ export class ExpressionEvaluator {
} else if (typeParams[paramIndex].category === ParameterCategory.VarArgList) {
validateArgTypeParams.push({
paramType,
requiresTypeVarMatching: requiresSpecialization(paramType),
argument: argList[argIndex],
errorNode: argList[argIndex].valueExpression || errorNode,
paramName: typeParams[paramIndex].name
Expand All @@ -2281,6 +2284,7 @@ export class ExpressionEvaluator {
} else {
validateArgTypeParams.push({
paramType,
requiresTypeVarMatching: requiresSpecialization(paramType),
argument: argList[argIndex],
errorNode: argList[argIndex].valueExpression || errorNode,
paramName: typeParams[paramIndex].name
Expand Down Expand Up @@ -2331,6 +2335,7 @@ export class ExpressionEvaluator {

validateArgTypeParams.push({
paramType,
requiresTypeVarMatching: requiresSpecialization(paramType),
argument: argList[argIndex],
errorNode: argList[argIndex].valueExpression || errorNode,
paramName: paramNameValue
Expand All @@ -2339,6 +2344,7 @@ export class ExpressionEvaluator {
} else if (varArgDictParam) {
validateArgTypeParams.push({
paramType: varArgDictParam.type,
requiresTypeVarMatching: requiresSpecialization(varArgDictParam.type),
argument: argList[argIndex],
errorNode: argList[argIndex].valueExpression || errorNode,
paramName: paramNameValue
Expand Down Expand Up @@ -2376,13 +2382,14 @@ export class ExpressionEvaluator {
}

// Run through all args and validate them against their matched parameter.
// We'll do two passes. The first one will match type arguments. The second
// will perform the actual validation. We can skip the first pass if there
// are no type vars to match.
if (FunctionType.requiresTypeVarMatching(type)) {
// We'll do two passes. The first one will match any type arguments. The second
// will perform the actual validation.
if (validateArgTypeParams.some(arg => arg.requiresTypeVarMatching)) {
this._silenceDiagnostics(() => {
validateArgTypeParams.forEach(argParam => {
this._validateArgType(argParam, typeVarMap, false);
if (argParam.requiresTypeVarMatching) {
this._validateArgType(argParam, typeVarMap, false);
}
});
});
}
Expand Down
19 changes: 1 addition & 18 deletions server/src/analyzer/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -537,8 +537,7 @@ export const enum FunctionTypeFlags {
AbstractMethod = 16,
DisableDefaultChecks = 32,
SynthesizedMethod = 64,
Overloaded = 128,
RequiresTypeVarMatching = 256
Overloaded = 128
}

interface FunctionDetails {
Expand Down Expand Up @@ -705,21 +704,11 @@ export namespace FunctionType {
type.details.flags |= FunctionTypeFlags.DisableDefaultChecks;
}

export function requiresTypeVarMatching(type: FunctionType) {
return (type.details.flags & FunctionTypeFlags.RequiresTypeVarMatching) !== 0;
}

export function setParameterType(type: FunctionType, index: number, paramType: Type): boolean {
assert(index < type.details.parameters.length);
const typeChanged = !isTypeSame(paramType, type.details.parameters[index].type);
type.details.parameters[index].type = paramType;

if ((type.details.flags & FunctionTypeFlags.RequiresTypeVarMatching) === 0) {
if (requiresSpecialization(paramType)) {
type.details.flags |= FunctionTypeFlags.RequiresTypeVarMatching;
}
}

return typeChanged;
}

Expand All @@ -734,12 +723,6 @@ export namespace FunctionType {

export function addParameter(type: FunctionType, param: FunctionParameter) {
type.details.parameters.push(param);

if ((type.details.flags & FunctionTypeFlags.RequiresTypeVarMatching) === 0) {
if (requiresSpecialization(param.type)) {
type.details.flags |= FunctionTypeFlags.RequiresTypeVarMatching;
}
}
}

export function getDeclaredReturnType(type: FunctionType) {
Expand Down

0 comments on commit 8f649e4

Please sign in to comment.