Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(223)

Unified Diff: pkg/front_end/lib/src/fasta/type_inference/type_inference_engine.dart

Issue 3000353002: Start implementing logic for determining when formal parameters need type checks. (Closed)
Patch Set: Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/front_end/lib/src/fasta/type_inference/type_inference_engine.dart
diff --git a/pkg/front_end/lib/src/fasta/type_inference/type_inference_engine.dart b/pkg/front_end/lib/src/fasta/type_inference/type_inference_engine.dart
index 0ac33b1cfa5778b4dc989b7325e7f8619bb01868..245e2c0d06bbb92aa87b03ce868ac57f411cda02 100644
--- a/pkg/front_end/lib/src/fasta/type_inference/type_inference_engine.dart
+++ b/pkg/front_end/lib/src/fasta/type_inference/type_inference_engine.dart
@@ -4,13 +4,14 @@
import 'package:front_end/src/base/instrumentation.dart';
import 'package:front_end/src/dependency_walker.dart' as dependencyWalker;
-import 'package:front_end/src/fasta/problems.dart' show unhandled;
import 'package:front_end/src/fasta/kernel/kernel_shadow_ast.dart';
ahe 2017/08/23 09:55:58 Please don't use package import for importing from
Paul Berry 2017/08/23 17:09:10 We talked about this before and as I recall we dec
ahe 2017/08/24 09:23:48 No, we didn't decide that. You argued for using pa
+import 'package:front_end/src/fasta/problems.dart' show unhandled;
import 'package:front_end/src/fasta/type_inference/type_inference_listener.dart';
import 'package:front_end/src/fasta/type_inference/type_inferrer.dart';
import 'package:front_end/src/fasta/type_inference/type_schema_environment.dart';
import 'package:kernel/ast.dart'
show
+ BottomType,
Class,
DartType,
DynamicType,
@@ -21,13 +22,13 @@ import 'package:kernel/ast.dart'
Member,
Procedure,
TypeParameter,
- TypeParameterType;
+ TypeParameterType,
+ VariableDeclaration;
import 'package:kernel/class_hierarchy.dart';
import 'package:kernel/core_types.dart';
import 'package:kernel/type_algebra.dart';
import '../deprecated_problems.dart' show Crash;
-
import '../messages.dart' show getLocationFromNode;
/// Data structure for tracking dependencies among fields, getters, and setters
@@ -135,15 +136,19 @@ abstract class TypeInferenceEngine {
CoreTypes get coreTypes;
- /// Creates a type inferrer for use inside of a method body declared in a file
- /// with the given [uri].
- TypeInferrer createLocalTypeInferrer(
- Uri uri, TypeInferenceListener listener, InterfaceType thisType);
+ /// Annotates the formal parameters of any methods in [cls] to indicate the
+ /// circumstances in which they require runtime type checks.
+ void computeFormalSafety(Class cls);
/// Creates a disabled type inferrer (intended for debugging and profiling
/// only).
TypeInferrer createDisabledTypeInferrer();
+ /// Creates a type inferrer for use inside of a method body declared in a file
+ /// with the given [uri].
+ TypeInferrer createLocalTypeInferrer(
+ Uri uri, TypeInferenceListener listener, InterfaceType thisType);
+
/// Creates a [TypeInferrer] object which is ready to perform type inference
/// on the given [field].
TypeInferrer createTopLevelTypeInferrer(TypeInferenceListener listener,
@@ -268,6 +273,28 @@ abstract class TypeInferenceEngineImpl extends TypeInferenceEngine {
}
}
+ @override
+ void computeFormalSafety(Class cls) {
+ if (cls.typeParameters.isEmpty) return;
+ var pessimization = Substitution.fromPairs(cls.typeParameters,
+ new List.filled(cls.typeParameters.length, const BottomType()));
+ for (var procedure in cls.procedures) {
+ if (procedure.isStatic) continue;
+ void compute(VariableDeclaration formal) {
+ KernelVariableDeclaration kernelVariableDeclaration = formal;
+ var pessimisticType = pessimization.substituteType(formal.type);
+ if (!typeSchemaEnvironment.isSubtypeOf(formal.type, pessimisticType)) {
ahe 2017/08/23 09:55:58 I think this needs documentation. As far as I unde
Paul Berry 2017/08/23 17:09:10 I assume you mean: class A<T> { foo(T argument)
ahe 2017/08/24 09:35:26 Yes.
+ kernelVariableDeclaration.isSemiSafe = true;
+ instrumentation?.record(Uri.parse(cls.fileUri), formal.fileOffset,
+ 'checkFormal', new InstrumentationValueLiteral('semiSafe'));
+ }
+ }
+
+ procedure.function.positionalParameters.forEach(compute);
+ procedure.function.namedParameters.forEach(compute);
+ }
+ }
+
/// Creates an [AccessorNode] to track dependencies of the given [member].
AccessorNode createAccessorNode(KernelMember member);

Powered by Google App Engine
This is Rietveld 408576698