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

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

Issue 15299002: Reapply "Enable full type-checks in checked mode." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 7 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 1211 matching lines...) Expand 10 before | Expand all | Expand 10 after
1222 1222
1223 void registerTypeVariableExpression(TreeElements elements) { 1223 void registerTypeVariableExpression(TreeElements elements) {
1224 registerRuntimeType(elements); 1224 registerRuntimeType(elements);
1225 enqueueInResolution(getRuntimeTypeToString(), elements); 1225 enqueueInResolution(getRuntimeTypeToString(), elements);
1226 enqueueInResolution(getCreateRuntimeType(), elements); 1226 enqueueInResolution(getCreateRuntimeType(), elements);
1227 } 1227 }
1228 1228
1229 void registerIsCheck(DartType type, Enqueuer world, TreeElements elements) { 1229 void registerIsCheck(DartType type, Enqueuer world, TreeElements elements) {
1230 world.registerInstantiatedClass(compiler.boolClass, elements); 1230 world.registerInstantiatedClass(compiler.boolClass, elements);
1231 bool isTypeVariable = type.kind == TypeKind.TYPE_VARIABLE; 1231 bool isTypeVariable = type.kind == TypeKind.TYPE_VARIABLE;
1232 bool inCheckedMode = compiler.enableTypeAssertions;
1232 if (!type.isRaw || isTypeVariable) { 1233 if (!type.isRaw || isTypeVariable) {
1233 enqueueInResolution(getSetRuntimeTypeInfo(), elements); 1234 enqueueInResolution(getSetRuntimeTypeInfo(), elements);
1234 enqueueInResolution(getGetRuntimeTypeInfo(), elements); 1235 enqueueInResolution(getGetRuntimeTypeInfo(), elements);
1235 enqueueInResolution(getGetRuntimeTypeArgument(), elements); 1236 enqueueInResolution(getGetRuntimeTypeArgument(), elements);
1237 if (inCheckedMode) {
1238 enqueueInResolution(getAssertSubtype(), elements);
1239 }
1236 enqueueInResolution(getCheckSubtype(), elements); 1240 enqueueInResolution(getCheckSubtype(), elements);
1237 if (isTypeVariable) { 1241 if (isTypeVariable) {
1238 enqueueInResolution(getGetObjectIsSubtype(), elements); 1242 enqueueInResolution(getCheckSubtypeOfRuntimeType(), elements);
1243 if (inCheckedMode) {
1244 enqueueInResolution(getAssertSubtypeOfRuntimeType(), elements);
1245 }
1239 } 1246 }
1240 world.registerInstantiatedClass(compiler.listClass, elements); 1247 world.registerInstantiatedClass(compiler.listClass, elements);
1241 } 1248 }
1242 // [registerIsCheck] is also called for checked mode checks, so we 1249 // [registerIsCheck] is also called for checked mode checks, so we
1243 // need to register checked mode helpers. 1250 // need to register checked mode helpers.
1244 if (compiler.enableTypeAssertions) { 1251 if (inCheckedMode) {
1245 Element e = getCheckedModeHelper(type, typeCast: false); 1252 Element e = getCheckedModeHelper(type, typeCast: false);
1246 if (e != null) world.addToWorkList(e); 1253 if (e != null) world.addToWorkList(e);
1247 // We also need the native variant of the check (for DOM types). 1254 // We also need the native variant of the check (for DOM types).
1248 e = getNativeCheckedModeHelper(type, typeCast: false); 1255 e = getNativeCheckedModeHelper(type, typeCast: false);
1249 if (e != null) world.addToWorkList(e); 1256 if (e != null) world.addToWorkList(e);
1250 } 1257 }
1251 if (type.element.isNative()) { 1258 if (type.element.isNative()) {
1252 // We will neeed to add the "$is" and "$as" properties on the 1259 // We will neeed to add the "$is" and "$as" properties on the
1253 // JavaScript object prototype, so we make sure 1260 // JavaScript object prototype, so we make sure
1254 // [:defineProperty:] is compiled. 1261 // [:defineProperty:] is compiled.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1320 }); 1327 });
1321 } 1328 }
1322 // TODO(ngeoffray): Also handle T a (in checked mode). 1329 // TODO(ngeoffray): Also handle T a (in checked mode).
1323 } 1330 }
1324 1331
1325 void registerClassUsingVariableExpression(ClassElement cls) { 1332 void registerClassUsingVariableExpression(ClassElement cls) {
1326 rti.classesUsingTypeVariableExpression.add(cls); 1333 rti.classesUsingTypeVariableExpression.add(cls);
1327 } 1334 }
1328 1335
1329 bool needsRti(ClassElement cls) { 1336 bool needsRti(ClassElement cls) {
1330 return rti.classesNeedingRti.contains(cls.declaration) 1337 return rti.classesNeedingRti.contains(cls.declaration) ||
1331 || compiler.enabledRuntimeType; 1338 compiler.enabledRuntimeType;
1332 } 1339 }
1333 1340
1334 bool isDefaultNoSuchMethodImplementation(Element element) { 1341 bool isDefaultNoSuchMethodImplementation(Element element) {
1335 assert(element.name == Compiler.NO_SUCH_METHOD); 1342 assert(element.name == Compiler.NO_SUCH_METHOD);
1336 ClassElement classElement = element.getEnclosingClass(); 1343 ClassElement classElement = element.getEnclosingClass();
1337 return classElement == compiler.objectClass 1344 return classElement == compiler.objectClass
1338 || classElement == jsInterceptorClass; 1345 || classElement == jsInterceptorClass;
1339 } 1346 }
1340 1347
1341 bool isDefaultEqualityImplementation(Element element) { 1348 bool isDefaultEqualityImplementation(Element element) {
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
1586 } 1593 }
1587 } 1594 }
1588 1595
1589 /** 1596 /**
1590 * Returns the checked mode helper that will be needed to do a type check/type 1597 * Returns the checked mode helper that will be needed to do a type check/type
1591 * cast on [type] at runtime. Note that this method is being called both by 1598 * cast on [type] at runtime. Note that this method is being called both by
1592 * the resolver with interface types (int, String, ...), and by the SSA 1599 * the resolver with interface types (int, String, ...), and by the SSA
1593 * backend with implementation types (JSInt, JSString, ...). 1600 * backend with implementation types (JSInt, JSString, ...).
1594 */ 1601 */
1595 Element getCheckedModeHelper(DartType type, {bool typeCast}) { 1602 Element getCheckedModeHelper(DartType type, {bool typeCast}) {
1596 return compiler.findHelper(getCheckedModeHelperName( 1603 SourceString name = getCheckedModeHelperName(
1597 type, typeCast: typeCast, nativeCheckOnly: false)); 1604 type, typeCast: typeCast, nativeCheckOnly: false);
1605 return compiler.findHelper(name);
1598 } 1606 }
1599 1607
1600 /** 1608 /**
1601 * Returns the native checked mode helper that will be needed to do a type 1609 * Returns the native checked mode helper that will be needed to do a type
1602 * check/type cast on [type] at runtime. If no native helper exists for 1610 * check/type cast on [type] at runtime. If no native helper exists for
1603 * [type], [:null:] is returned. 1611 * [type], [:null:] is returned.
1604 */ 1612 */
1605 Element getNativeCheckedModeHelper(DartType type, {bool typeCast}) { 1613 Element getNativeCheckedModeHelper(DartType type, {bool typeCast}) {
1606 SourceString sourceName = getCheckedModeHelperName( 1614 SourceString sourceName = getCheckedModeHelperName(
1607 type, typeCast: typeCast, nativeCheckOnly: true); 1615 type, typeCast: typeCast, nativeCheckOnly: true);
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1686 return typeCast 1694 return typeCast
1687 ? const SourceString("listSuperNativeTypeCast") 1695 ? const SourceString("listSuperNativeTypeCast")
1688 : const SourceString('listSuperNativeTypeCheck'); 1696 : const SourceString('listSuperNativeTypeCheck');
1689 } else { 1697 } else {
1690 return typeCast 1698 return typeCast
1691 ? const SourceString("listSuperTypeCast") 1699 ? const SourceString("listSuperTypeCast")
1692 : const SourceString('listSuperTypeCheck'); 1700 : const SourceString('listSuperTypeCheck');
1693 } 1701 }
1694 } else { 1702 } else {
1695 if (nativeCheck) { 1703 if (nativeCheck) {
1704 // TODO(karlklose): can we get rid of this branch when we use
1705 // interceptors?
1696 return typeCast 1706 return typeCast
1697 ? const SourceString("interceptedTypeCast") 1707 ? const SourceString("interceptedTypeCast")
1698 : const SourceString('interceptedTypeCheck'); 1708 : const SourceString('interceptedTypeCheck');
1699 } else { 1709 } else {
1700 return typeCast 1710 if (typeCast) {
1701 ? const SourceString("propertyTypeCast") 1711 return const SourceString("propertyTypeCast");
1702 : const SourceString('propertyTypeCheck'); 1712 }
1713 if (type.kind == TypeKind.INTERFACE && !type.isRaw) {
1714 return const SourceString('assertSubtype');
1715 } else if (type.kind == TypeKind.TYPE_VARIABLE) {
1716 return const SourceString('assertSubtypeOfRuntimeType');
1717 } else {
1718 return const SourceString('propertyTypeCheck');
1719 }
1703 } 1720 }
1704 } 1721 }
1705 } 1722 }
1706 } 1723 }
1707 1724
1708 void dumpInferredTypes() { 1725 void dumpInferredTypes() {
1709 print("Inferred argument types:"); 1726 print("Inferred argument types:");
1710 print("------------------------"); 1727 print("------------------------");
1711 argumentTypes.dump(); 1728 argumentTypes.dump();
1712 print(""); 1729 print("");
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1775 } 1792 }
1776 1793
1777 Element getRuntimeTypeToString() { 1794 Element getRuntimeTypeToString() {
1778 return compiler.findHelper(const SourceString('runtimeTypeToString')); 1795 return compiler.findHelper(const SourceString('runtimeTypeToString'));
1779 } 1796 }
1780 1797
1781 Element getCheckSubtype() { 1798 Element getCheckSubtype() {
1782 return compiler.findHelper(const SourceString('checkSubtype')); 1799 return compiler.findHelper(const SourceString('checkSubtype'));
1783 } 1800 }
1784 1801
1785 Element getGetObjectIsSubtype() { 1802 Element getAssertSubtype() {
1786 return compiler.findHelper(const SourceString('objectIsSubtype')); 1803 return compiler.findHelper(const SourceString('assertSubtype'));
1804 }
1805
1806 Element getCheckSubtypeOfRuntimeType() {
1807 return compiler.findHelper(const SourceString('checkSubtypeOfRuntimeType'));
1808 }
1809
1810 Element getAssertSubtypeOfRuntimeType() {
1811 return compiler.findHelper(
1812 const SourceString('assertSubtypeOfRuntimeType'));
1787 } 1813 }
1788 1814
1789 Element getThrowNoSuchMethod() { 1815 Element getThrowNoSuchMethod() {
1790 return compiler.findHelper(const SourceString('throwNoSuchMethod')); 1816 return compiler.findHelper(const SourceString('throwNoSuchMethod'));
1791 } 1817 }
1792 1818
1793 Element getCreateRuntimeType() { 1819 Element getCreateRuntimeType() {
1794 return compiler.findHelper(const SourceString('createRuntimeType')); 1820 return compiler.findHelper(const SourceString('createRuntimeType'));
1795 } 1821 }
1796 1822
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1830 ClassElement get listImplementation => jsArrayClass; 1856 ClassElement get listImplementation => jsArrayClass;
1831 ClassElement get constListImplementation => jsArrayClass; 1857 ClassElement get constListImplementation => jsArrayClass;
1832 ClassElement get fixedListImplementation => jsFixedArrayClass; 1858 ClassElement get fixedListImplementation => jsFixedArrayClass;
1833 ClassElement get growableListImplementation => jsExtendableArrayClass; 1859 ClassElement get growableListImplementation => jsExtendableArrayClass;
1834 ClassElement get mapImplementation => mapLiteralClass; 1860 ClassElement get mapImplementation => mapLiteralClass;
1835 ClassElement get constMapImplementation => constMapLiteralClass; 1861 ClassElement get constMapImplementation => constMapLiteralClass;
1836 ClassElement get typeImplementation => typeLiteralClass; 1862 ClassElement get typeImplementation => typeLiteralClass;
1837 ClassElement get boolImplementation => jsBoolClass; 1863 ClassElement get boolImplementation => jsBoolClass;
1838 ClassElement get nullImplementation => jsNullClass; 1864 ClassElement get nullImplementation => jsNullClass;
1839 } 1865 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/dart_types.dart ('k') | sdk/lib/_internal/compiler/implementation/lib/js_rti.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698