Use factories for instantiating TypeInferrer
Change-Id: Id34b7767b7333dc66a970906f934ad81d2a276a6
Reviewed-on: https://dart-review.googlesource.com/c/84400
Commit-Queue: Peter von der Ahé <ahe@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
Auto-Submit: Peter von der Ahé <ahe@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
diff --git a/pkg/front_end/lib/src/fasta/kernel/kernel_shadow_ast.dart b/pkg/front_end/lib/src/fasta/kernel/kernel_shadow_ast.dart
index 80afd41..259cf74 100644
--- a/pkg/front_end/lib/src/fasta/kernel/kernel_shadow_ast.dart
+++ b/pkg/front_end/lib/src/fasta/kernel/kernel_shadow_ast.dart
@@ -63,11 +63,7 @@
TypeInferenceEngine;
import '../type_inference/type_inferrer.dart'
- show
- ExpressionInferenceResult,
- TypeInferrer,
- TypeInferrerDisabled,
- TypeInferrerImpl;
+ show ExpressionInferenceResult, TypeInferrer, TypeInferrerImpl;
import '../type_inference/type_promotion.dart'
show TypePromoter, TypePromoterImpl, TypePromotionFact, TypePromotionScope;
@@ -1567,19 +1563,19 @@
@override
TypeInferrer createDisabledTypeInferrer() =>
- new TypeInferrerDisabled(typeSchemaEnvironment);
+ new TypeInferrer.disabled(typeSchemaEnvironment);
@override
ShadowTypeInferrer createLocalTypeInferrer(
Uri uri, InterfaceType thisType, KernelLibraryBuilder library) {
- return new ShadowTypeInferrer._(this, uri, false, thisType, library);
+ return new TypeInferrer(this, uri, false, thisType, library);
}
@override
ShadowTypeInferrer createTopLevelTypeInferrer(
InterfaceType thisType, ShadowField field, KernelLibraryBuilder library) {
return field._typeInferrer =
- new ShadowTypeInferrer._(this, field.fileUri, true, thisType, library);
+ new TypeInferrer(this, field.fileUri, true, thisType, library);
}
@override
@@ -1594,10 +1590,10 @@
@override
final typePromoter;
- ShadowTypeInferrer._(ShadowTypeInferenceEngine engine, Uri uri, bool topLevel,
- InterfaceType thisType, KernelLibraryBuilder library)
- : typePromoter = new ShadowTypePromoter(engine.typeSchemaEnvironment),
- super(engine, uri, topLevel, thisType, library);
+ ShadowTypeInferrer.private(ShadowTypeInferenceEngine engine, Uri uri,
+ bool topLevel, InterfaceType thisType, KernelLibraryBuilder library)
+ : typePromoter = new TypePromoter(engine.typeSchemaEnvironment),
+ super.private(engine, uri, topLevel, thisType, library);
@override
Expression getFieldInitializer(ShadowField field) {
@@ -1700,8 +1696,8 @@
/// Concrete implementation of [TypePromoter] specialized to work with kernel
/// objects.
class ShadowTypePromoter extends TypePromoterImpl {
- ShadowTypePromoter(TypeSchemaEnvironment typeSchemaEnvironment)
- : super(typeSchemaEnvironment);
+ ShadowTypePromoter.private(TypeSchemaEnvironment typeSchemaEnvironment)
+ : super.private(typeSchemaEnvironment);
@override
int getVariableFunctionNestingLevel(VariableDeclaration variable) {
diff --git a/pkg/front_end/lib/src/fasta/type_inference/type_inferrer.dart b/pkg/front_end/lib/src/fasta/type_inference/type_inferrer.dart
index 6c4a2c6..c11d8b5 100644
--- a/pkg/front_end/lib/src/fasta/type_inference/type_inferrer.dart
+++ b/pkg/front_end/lib/src/fasta/type_inference/type_inferrer.dart
@@ -101,6 +101,8 @@
ShadowClass,
ShadowField,
ShadowMember,
+ ShadowTypeInferenceEngine,
+ ShadowTypeInferrer,
VariableDeclarationJudgment,
getExplicitTypeArguments,
getInferredType;
@@ -122,7 +124,7 @@
import 'type_inference_engine.dart'
show IncludesTypeParametersCovariantly, TypeInferenceEngine;
-import 'type_promotion.dart' show TypePromoter, TypePromoterDisabled;
+import 'type_promotion.dart' show TypePromoter;
import 'type_schema.dart' show isKnown, UnknownType;
@@ -444,7 +446,17 @@
abstract class TypeInferrer {
final CoreTypes coreTypes;
- TypeInferrer(this.coreTypes);
+ TypeInferrer.private(this.coreTypes);
+
+ factory TypeInferrer(
+ ShadowTypeInferenceEngine engine,
+ Uri uri,
+ bool topLevel,
+ InterfaceType thisType,
+ KernelLibraryBuilder library) = ShadowTypeInferrer.private;
+
+ factory TypeInferrer.disabled(TypeSchemaEnvironment typeSchemaEnvironment) =
+ TypeInferrerDisabled.private;
KernelLibraryBuilder get library;
@@ -490,12 +502,13 @@
/// promotion do not slow down compilation too much.
class TypeInferrerDisabled extends TypeInferrer {
@override
- final typePromoter = new TypePromoterDisabled();
+ final typePromoter = new TypePromoter.disabled();
@override
final TypeSchemaEnvironment typeSchemaEnvironment;
- TypeInferrerDisabled(this.typeSchemaEnvironment) : super(null);
+ TypeInferrerDisabled.private(this.typeSchemaEnvironment)
+ : super.private(null);
@override
KernelLibraryBuilder get library => null;
@@ -577,14 +590,14 @@
/// if the last invocation didn't require any inference.
FunctionType lastCalleeType;
- TypeInferrerImpl(
+ TypeInferrerImpl.private(
this.engine, this.uri, bool topLevel, this.thisType, this.library)
: strongMode = engine.strongMode,
classHierarchy = engine.classHierarchy,
instrumentation = topLevel ? null : engine.instrumentation,
typeSchemaEnvironment = engine.typeSchemaEnvironment,
isTopLevel = topLevel,
- super(engine.coreTypes);
+ super.private(engine.coreTypes);
DartType storeInferredType(TreeNode node, DartType type) {
if (node is ExpressionJudgment) {
diff --git a/pkg/front_end/lib/src/fasta/type_inference/type_promotion.dart b/pkg/front_end/lib/src/fasta/type_inference/type_promotion.dart
index 791a584..80c10e5 100644
--- a/pkg/front_end/lib/src/fasta/type_inference/type_promotion.dart
+++ b/pkg/front_end/lib/src/fasta/type_inference/type_promotion.dart
@@ -9,6 +9,8 @@
import '../problems.dart' show internalProblem;
+import '../kernel/kernel_shadow_ast.dart' show ShadowTypePromoter;
+
import 'type_schema_environment.dart' show TypeSchemaEnvironment;
/// Keeps track of the state necessary to perform type promotion.
@@ -31,6 +33,13 @@
/// generic parameters. Derived classes should set E and V to the class they
/// use to represent expressions and variable declarations, respectively.
abstract class TypePromoter {
+ TypePromoter.private();
+
+ factory TypePromoter(TypeSchemaEnvironment typeSchemaEnvironment) =
+ ShadowTypePromoter.private;
+
+ factory TypePromoter.disabled() = TypePromoterDisabled.private;
+
/// Returns the current type promotion scope.
TypePromotionScope get currentScope;
@@ -90,6 +99,8 @@
/// This is intended for profiling, to ensure that type inference and type
/// promotion do not slow down compilation too much.
class TypePromoterDisabled extends TypePromoter {
+ TypePromoterDisabled.private() : super.private();
+
@override
TypePromotionScope get currentScope => null;
@@ -177,12 +188,13 @@
/// created.
int _lastFactSequenceNumber = 0;
- TypePromoterImpl(TypeSchemaEnvironment typeSchemaEnvironment)
+ TypePromoterImpl.private(TypeSchemaEnvironment typeSchemaEnvironment)
: this._(typeSchemaEnvironment, new _NullFact());
TypePromoterImpl._(this.typeSchemaEnvironment, _NullFact this._nullFacts)
: _factCacheState = _nullFacts,
- _currentFacts = _nullFacts {
+ _currentFacts = _nullFacts,
+ super.private() {
_factCache[null] = _nullFacts;
}