mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 18:49:37 +00:00
[CFE] Don't create new 'unknown' FunctionTypes for each TypeInferrerImpl
When compiling "compile.dart" this creates ~17% fewer FunctionTypes (from almost 263k to a little over 217k). Change-Id: I0090c287ce427b298897846de03679f562223e63 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/298581 Commit-Queue: Jens Johansen <jensj@google.com> Reviewed-by: Johnni Winther <johnniwinther@google.com>
This commit is contained in:
parent
ea2d6a7659
commit
f72b7ae86f
|
@ -329,6 +329,10 @@ abstract class TypeInferenceEngine {
|
|||
/// kernel objects.
|
||||
class TypeInferenceEngineImpl extends TypeInferenceEngine {
|
||||
final Benchmarker? benchmarker;
|
||||
final FunctionType unknownFunctionNonNullable =
|
||||
new FunctionType(const [], const DynamicType(), Nullability.nonNullable);
|
||||
final FunctionType unknownFunctionLegacy =
|
||||
new FunctionType(const [], const DynamicType(), Nullability.legacy);
|
||||
|
||||
TypeInferenceEngineImpl(Instrumentation? instrumentation, this.benchmarker)
|
||||
: super(instrumentation);
|
||||
|
@ -345,11 +349,28 @@ class TypeInferenceEngineImpl extends TypeInferenceEngine {
|
|||
new AssignedVariables<TreeNode, VariableDeclaration>();
|
||||
}
|
||||
if (benchmarker == null) {
|
||||
return new TypeInferrerImpl(this, uri, false, thisType, library,
|
||||
assignedVariables, dataForTesting);
|
||||
return new TypeInferrerImpl(
|
||||
this,
|
||||
uri,
|
||||
false,
|
||||
thisType,
|
||||
library,
|
||||
assignedVariables,
|
||||
dataForTesting,
|
||||
unknownFunctionNonNullable,
|
||||
unknownFunctionLegacy);
|
||||
}
|
||||
return new TypeInferrerImplBenchmarked(this, uri, false, thisType, library,
|
||||
assignedVariables, dataForTesting, benchmarker!);
|
||||
return new TypeInferrerImplBenchmarked(
|
||||
this,
|
||||
uri,
|
||||
false,
|
||||
thisType,
|
||||
library,
|
||||
assignedVariables,
|
||||
dataForTesting,
|
||||
benchmarker!,
|
||||
unknownFunctionNonNullable,
|
||||
unknownFunctionLegacy);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -364,11 +385,28 @@ class TypeInferenceEngineImpl extends TypeInferenceEngine {
|
|||
new AssignedVariables<TreeNode, VariableDeclaration>();
|
||||
}
|
||||
if (benchmarker == null) {
|
||||
return new TypeInferrerImpl(this, uri, true, thisType, library,
|
||||
assignedVariables, dataForTesting);
|
||||
return new TypeInferrerImpl(
|
||||
this,
|
||||
uri,
|
||||
true,
|
||||
thisType,
|
||||
library,
|
||||
assignedVariables,
|
||||
dataForTesting,
|
||||
unknownFunctionNonNullable,
|
||||
unknownFunctionLegacy);
|
||||
}
|
||||
return new TypeInferrerImplBenchmarked(this, uri, true, thisType, library,
|
||||
assignedVariables, dataForTesting, benchmarker!);
|
||||
return new TypeInferrerImplBenchmarked(
|
||||
this,
|
||||
uri,
|
||||
true,
|
||||
thisType,
|
||||
library,
|
||||
assignedVariables,
|
||||
dataForTesting,
|
||||
benchmarker!,
|
||||
unknownFunctionNonNullable,
|
||||
unknownFunctionLegacy);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -139,11 +139,14 @@ class TypeInferrerImpl implements TypeInferrer {
|
|||
this.thisType,
|
||||
this.libraryBuilder,
|
||||
this.assignedVariables,
|
||||
this.dataForTesting)
|
||||
this.dataForTesting,
|
||||
FunctionType unknownFunctionNonNullable,
|
||||
FunctionType unknownFunctionLegacy)
|
||||
// ignore: unnecessary_null_comparison
|
||||
: assert(libraryBuilder != null),
|
||||
unknownFunction = new FunctionType(
|
||||
const [], const DynamicType(), libraryBuilder.nonNullable),
|
||||
unknownFunction = libraryBuilder.isNonNullableByDefault
|
||||
? unknownFunctionNonNullable
|
||||
: unknownFunctionLegacy,
|
||||
instrumentation = isTopLevel ? null : engine.instrumentation,
|
||||
typeSchemaEnvironment = engine.typeSchemaEnvironment,
|
||||
operations = new OperationsCfe(engine.typeSchemaEnvironment,
|
||||
|
@ -312,9 +315,20 @@ class TypeInferrerImplBenchmarked implements TypeInferrer {
|
|||
SourceLibraryBuilder library,
|
||||
AssignedVariables<TreeNode, VariableDeclaration> assignedVariables,
|
||||
InferenceDataForTesting? dataForTesting,
|
||||
this.benchmarker)
|
||||
: impl = new TypeInferrerImpl(engine, uriForInstrumentation, topLevel,
|
||||
thisType, library, assignedVariables, dataForTesting);
|
||||
this.benchmarker,
|
||||
FunctionType unknownFunctionNonNullable,
|
||||
FunctionType unknownFunctionLegacy,
|
||||
) : impl = new TypeInferrerImpl(
|
||||
engine,
|
||||
uriForInstrumentation,
|
||||
topLevel,
|
||||
thisType,
|
||||
library,
|
||||
assignedVariables,
|
||||
dataForTesting,
|
||||
unknownFunctionNonNullable,
|
||||
unknownFunctionLegacy,
|
||||
);
|
||||
|
||||
@override
|
||||
bool get isTopLevel => impl.isTopLevel;
|
||||
|
|
Loading…
Reference in a new issue