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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/js_backend/backend.dart

Issue 13019003: Enable full type-checks in checked mode. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix a bug. Created 7 years, 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 4
5 part of js_backend; 5 part of js_backend;
6 6
7 typedef void Recompile(Element element); 7 typedef void Recompile(Element element);
8 8
9 class ReturnInfo { 9 class ReturnInfo {
10 HType returnType; 10 HType returnType;
(...skipping 1158 matching lines...) Expand 10 before | Expand all | Expand 10 after
1169 1169
1170 void registerTypeVariableExpression(TreeElements elements) { 1170 void registerTypeVariableExpression(TreeElements elements) {
1171 registerRuntimeType(elements); 1171 registerRuntimeType(elements);
1172 enqueueInResolution(getRuntimeTypeToString(), elements); 1172 enqueueInResolution(getRuntimeTypeToString(), elements);
1173 enqueueInResolution(getCreateRuntimeType(), elements); 1173 enqueueInResolution(getCreateRuntimeType(), elements);
1174 } 1174 }
1175 1175
1176 void registerIsCheck(DartType type, Enqueuer world, TreeElements elements) { 1176 void registerIsCheck(DartType type, Enqueuer world, TreeElements elements) {
1177 world.registerInstantiatedClass(compiler.boolClass, elements); 1177 world.registerInstantiatedClass(compiler.boolClass, elements);
1178 bool isTypeVariable = type.kind == TypeKind.TYPE_VARIABLE; 1178 bool isTypeVariable = type.kind == TypeKind.TYPE_VARIABLE;
1179 bool isCheckedMode = compiler.enableTypeAssertions;
1179 if (!type.isRaw || isTypeVariable) { 1180 if (!type.isRaw || isTypeVariable) {
1180 enqueueInResolution(getSetRuntimeTypeInfo(), elements); 1181 enqueueInResolution(getSetRuntimeTypeInfo(), elements);
1181 enqueueInResolution(getGetRuntimeTypeInfo(), elements); 1182 enqueueInResolution(getGetRuntimeTypeInfo(), elements);
1182 enqueueInResolution(getGetRuntimeTypeArgument(), elements); 1183 enqueueInResolution(getGetRuntimeTypeArgument(), elements);
1184 if (isCheckedMode) {
1185 enqueueInResolution(getAssertSubtype(), elements);
1186 }
1183 enqueueInResolution(getCheckSubtype(), elements); 1187 enqueueInResolution(getCheckSubtype(), elements);
1184 if (isTypeVariable) { 1188 if (isTypeVariable) {
1185 enqueueInResolution(getGetObjectIsSubtype(), elements); 1189 enqueueInResolution(getObjectIsSubtype(), elements);
1190 if (isCheckedMode) {
1191 enqueueInResolution(getAssertObjectIsSubtype(), elements);
1192 }
1186 } 1193 }
1187 world.registerInstantiatedClass(compiler.listClass, elements); 1194 world.registerInstantiatedClass(compiler.listClass, elements);
1188 } 1195 }
1189 // [registerIsCheck] is also called for checked mode checks, so we 1196 // [registerIsCheck] is also called for checked mode checks, so we
1190 // need to register checked mode helpers. 1197 // need to register checked mode helpers.
1191 if (compiler.enableTypeAssertions) { 1198 if (isCheckedMode) {
1192 Element e = getCheckedModeHelper(type, typeCast: false); 1199 Element e = getCheckedModeHelper(type, typeCast: false);
1193 if (e != null) world.addToWorkList(e); 1200 if (e != null) world.addToWorkList(e);
1194 // We also need the native variant of the check (for DOM types). 1201 // We also need the native variant of the check (for DOM types).
1195 e = getNativeCheckedModeHelper(type, typeCast: false); 1202 e = getNativeCheckedModeHelper(type, typeCast: false);
1196 if (e != null) world.addToWorkList(e); 1203 if (e != null) world.addToWorkList(e);
1197 } 1204 }
1198 if (type.element.isNative()) { 1205 if (type.element.isNative()) {
1199 // We will neeed to add the "$is" and "$as" properties on the 1206 // We will neeed to add the "$is" and "$as" properties on the
1200 // JavaScript object prototype, so we make sure 1207 // JavaScript object prototype, so we make sure
1201 // [:defineProperty:] is compiled. 1208 // [:defineProperty:] is compiled.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1267 }); 1274 });
1268 } 1275 }
1269 // TODO(ngeoffray): Also handle T a (in checked mode). 1276 // TODO(ngeoffray): Also handle T a (in checked mode).
1270 } 1277 }
1271 1278
1272 void registerClassUsingVariableExpression(ClassElement cls) { 1279 void registerClassUsingVariableExpression(ClassElement cls) {
1273 rti.classesUsingTypeVariableExpression.add(cls); 1280 rti.classesUsingTypeVariableExpression.add(cls);
1274 } 1281 }
1275 1282
1276 bool needsRti(ClassElement cls) { 1283 bool needsRti(ClassElement cls) {
1277 return rti.classesNeedingRti.contains(cls.declaration) 1284 return rti.classesNeedingRti.contains(cls.declaration) ||
1278 || compiler.enabledRuntimeType; 1285 compiler.enabledRuntimeType ||
1286 (compiler.enableTypeAssertions && !cls.typeVariables.isEmpty);
ngeoffray 2013/04/15 10:59:14 Is that because we never know if there will be a t
1279 } 1287 }
1280 1288
1281 bool isDefaultNoSuchMethodImplementation(Element element) { 1289 bool isDefaultNoSuchMethodImplementation(Element element) {
1282 assert(element.name == Compiler.NO_SUCH_METHOD); 1290 assert(element.name == Compiler.NO_SUCH_METHOD);
1283 ClassElement classElement = element.getEnclosingClass(); 1291 ClassElement classElement = element.getEnclosingClass();
1284 return classElement == compiler.objectClass 1292 return classElement == compiler.objectClass
1285 || classElement == jsInterceptorClass; 1293 || classElement == jsInterceptorClass;
1286 } 1294 }
1287 1295
1288 bool isDefaultEqualityImplementation(Element element) { 1296 bool isDefaultEqualityImplementation(Element element) {
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
1701 } 1709 }
1702 1710
1703 Element getRuntimeTypeToString() { 1711 Element getRuntimeTypeToString() {
1704 return compiler.findHelper(const SourceString('runtimeTypeToString')); 1712 return compiler.findHelper(const SourceString('runtimeTypeToString'));
1705 } 1713 }
1706 1714
1707 Element getCheckSubtype() { 1715 Element getCheckSubtype() {
1708 return compiler.findHelper(const SourceString('checkSubtype')); 1716 return compiler.findHelper(const SourceString('checkSubtype'));
1709 } 1717 }
1710 1718
1711 Element getGetObjectIsSubtype() { 1719 Element getAssertSubtype() {
1720 return compiler.findHelper(const SourceString('assertSubtype'));
1721 }
1722
1723 Element getObjectIsSubtype() {
1712 return compiler.findHelper(const SourceString('objectIsSubtype')); 1724 return compiler.findHelper(const SourceString('objectIsSubtype'));
1713 } 1725 }
1714 1726
1727 Element getAssertObjectIsSubtype() {
1728 return compiler.findHelper(const SourceString('assertObjectIsSubtype'));
1729 }
1730
1715 Element getThrowNoSuchMethod() { 1731 Element getThrowNoSuchMethod() {
1716 return compiler.findHelper(const SourceString('throwNoSuchMethod')); 1732 return compiler.findHelper(const SourceString('throwNoSuchMethod'));
1717 } 1733 }
1718 1734
1719 Element getCreateRuntimeType() { 1735 Element getCreateRuntimeType() {
1720 return compiler.findHelper(const SourceString('createRuntimeType')); 1736 return compiler.findHelper(const SourceString('createRuntimeType'));
1721 } 1737 }
1722 1738
1723 Element getFallThroughError() { 1739 Element getFallThroughError() {
1724 return compiler.findHelper(const SourceString("getFallThroughError")); 1740 return compiler.findHelper(const SourceString("getFallThroughError"));
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1757 ClassElement get constListImplementation => jsArrayClass; 1773 ClassElement get constListImplementation => jsArrayClass;
1758 ClassElement get fixedListImplementation => jsFixedArrayClass; 1774 ClassElement get fixedListImplementation => jsFixedArrayClass;
1759 ClassElement get growableListImplementation => jsExtendableArrayClass; 1775 ClassElement get growableListImplementation => jsExtendableArrayClass;
1760 ClassElement get mapImplementation => mapLiteralClass; 1776 ClassElement get mapImplementation => mapLiteralClass;
1761 ClassElement get constMapImplementation => constMapLiteralClass; 1777 ClassElement get constMapImplementation => constMapLiteralClass;
1762 ClassElement get functionImplementation => jsFunctionClass; 1778 ClassElement get functionImplementation => jsFunctionClass;
1763 ClassElement get typeImplementation => typeLiteralClass; 1779 ClassElement get typeImplementation => typeLiteralClass;
1764 ClassElement get boolImplementation => jsBoolClass; 1780 ClassElement get boolImplementation => jsBoolClass;
1765 ClassElement get nullImplementation => jsNullClass; 1781 ClassElement get nullImplementation => jsNullClass;
1766 } 1782 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698