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

Side by Side Diff: lib/type_environment.dart

Issue 2465893002: Add strong mode type checking pass. (Closed)
Patch Set: Merge with master and remove visitBlockExpression Created 4 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « lib/type_checker.dart ('k') | test/baseline_spec_mode_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 library kernel.type_environment; 4 library kernel.type_environment;
5 5
6 import 'ast.dart'; 6 import 'ast.dart';
7 import 'class_hierarchy.dart'; 7 import 'class_hierarchy.dart';
8 import 'core_types.dart'; 8 import 'core_types.dart';
9 import 'type_algebra.dart'; 9 import 'type_algebra.dart';
10 10
11 typedef void ErrorHandler(TreeNode node, String message); 11 typedef void ErrorHandler(TreeNode node, String message);
12 12
13 class TypeEnvironment extends SubtypeTester { 13 class TypeEnvironment extends SubtypeTester {
14 final CoreTypes coreTypes; 14 final CoreTypes coreTypes;
15 final ClassHierarchy hierarchy; 15 final ClassHierarchy hierarchy;
16 DartType thisType; 16 InterfaceType thisType;
17
18 DartType returnType;
19 DartType yieldType;
17 20
18 /// An error handler for use in debugging, or `null` if type errors should not 21 /// An error handler for use in debugging, or `null` if type errors should not
19 /// be tolerated. See [typeError]. 22 /// be tolerated. See [typeError].
20 ErrorHandler errorHandler; 23 ErrorHandler errorHandler;
21 24
22 TypeEnvironment(this.coreTypes, this.hierarchy); 25 TypeEnvironment(this.coreTypes, this.hierarchy);
23 26
24 InterfaceType get objectType => coreTypes.objectClass.rawType; 27 InterfaceType get objectType => coreTypes.objectClass.rawType;
25 InterfaceType get nullType => coreTypes.nullClass.rawType; 28 InterfaceType get nullType => coreTypes.nullClass.rawType;
26 InterfaceType get boolType => coreTypes.boolClass.rawType; 29 InterfaceType get boolType => coreTypes.boolClass.rawType;
27 InterfaceType get intType => coreTypes.intClass.rawType; 30 InterfaceType get intType => coreTypes.intClass.rawType;
28 InterfaceType get numType => coreTypes.numClass.rawType; 31 InterfaceType get numType => coreTypes.numClass.rawType;
29 InterfaceType get doubleType => coreTypes.doubleClass.rawType; 32 InterfaceType get doubleType => coreTypes.doubleClass.rawType;
30 InterfaceType get stringType => coreTypes.stringClass.rawType; 33 InterfaceType get stringType => coreTypes.stringClass.rawType;
31 InterfaceType get symbolType => coreTypes.symbolClass.rawType; 34 InterfaceType get symbolType => coreTypes.symbolClass.rawType;
32 InterfaceType get typeType => coreTypes.typeClass.rawType; 35 InterfaceType get typeType => coreTypes.typeClass.rawType;
33 InterfaceType get rawFunctionType => coreTypes.functionClass.rawType; 36 InterfaceType get rawFunctionType => coreTypes.functionClass.rawType;
34 37
35 Class get intClass => coreTypes.intClass; 38 Class get intClass => coreTypes.intClass;
36 Class get numClass => coreTypes.numClass; 39 Class get numClass => coreTypes.numClass;
37 40
38 InterfaceType listType(DartType elementType) { 41 InterfaceType literalListType(DartType elementType) {
39 return new InterfaceType(coreTypes.listClass, <DartType>[elementType]); 42 return new InterfaceType(coreTypes.listClass, <DartType>[elementType]);
40 } 43 }
41 44
42 InterfaceType mapType(DartType key, DartType value) { 45 InterfaceType literalMapType(DartType key, DartType value) {
43 return new InterfaceType(coreTypes.mapClass, <DartType>[key, value]); 46 return new InterfaceType(coreTypes.mapClass, <DartType>[key, value]);
44 } 47 }
45 48
46 InterfaceType iterableType(DartType type) { 49 InterfaceType iterableType(DartType type) {
47 return new InterfaceType(coreTypes.iterableClass, <DartType>[type]); 50 return new InterfaceType(coreTypes.iterableClass, <DartType>[type]);
48 } 51 }
49 52
50 InterfaceType streamType(DartType type) { 53 InterfaceType streamType(DartType type) {
51 return new InterfaceType(coreTypes.streamClass, <DartType>[type]); 54 return new InterfaceType(coreTypes.streamClass, <DartType>[type]);
52 } 55 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 ClassHierarchy get hierarchy; 124 ClassHierarchy get hierarchy;
122 125
123 /// Returns true if [subtype] is a subtype of [supertype]. 126 /// Returns true if [subtype] is a subtype of [supertype].
124 bool isSubtypeOf(DartType subtype, DartType supertype) { 127 bool isSubtypeOf(DartType subtype, DartType supertype) {
125 if (identical(subtype, supertype)) return true; 128 if (identical(subtype, supertype)) return true;
126 if (subtype is BottomType) return true; 129 if (subtype is BottomType) return true;
127 if (supertype is DynamicType || supertype == objectType) { 130 if (supertype is DynamicType || supertype == objectType) {
128 return true; 131 return true;
129 } 132 }
130 if (subtype is InterfaceType && supertype is InterfaceType) { 133 if (subtype is InterfaceType && supertype is InterfaceType) {
131 InterfaceType upcastType = 134 var upcastType =
132 hierarchy.getTypeAsInstanceOf(subtype, supertype.classNode); 135 hierarchy.getTypeAsInstanceOf(subtype, supertype.classNode);
133 if (upcastType == null) return false; 136 if (upcastType == null) return false;
134 for (int i = 0; i < upcastType.typeArguments.length; ++i) { 137 for (int i = 0; i < upcastType.typeArguments.length; ++i) {
135 // Termination: the 'supertype' parameter decreases in size. 138 // Termination: the 'supertype' parameter decreases in size.
136 if (!isSubtypeOf( 139 if (!isSubtypeOf(
137 upcastType.typeArguments[i], supertype.typeArguments[i])) { 140 upcastType.typeArguments[i], supertype.typeArguments[i])) {
138 return false; 141 return false;
139 } 142 }
140 } 143 }
141 return true; 144 return true;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 var subtypeParameter = subtype.namedParameters[name]; 210 var subtypeParameter = subtype.namedParameters[name];
208 if (subtypeParameter == null) return false; 211 if (subtypeParameter == null) return false;
209 // Termination: Both types shrink in size. 212 // Termination: Both types shrink in size.
210 if (!isSubtypeOf(supertypeParameter, subtypeParameter)) { 213 if (!isSubtypeOf(supertypeParameter, subtypeParameter)) {
211 return false; 214 return false;
212 } 215 }
213 } 216 }
214 return true; 217 return true;
215 } 218 }
216 } 219 }
OLDNEW
« no previous file with comments | « lib/type_checker.dart ('k') | test/baseline_spec_mode_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698