| OLD | NEW |
| 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 1067 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1078 } | 1078 } |
| 1079 | 1079 |
| 1080 void registerSetRuntimeType(TreeElements elements) { | 1080 void registerSetRuntimeType(TreeElements elements) { |
| 1081 enqueueInResolution(getSetRuntimeTypeInfo(), elements); | 1081 enqueueInResolution(getSetRuntimeTypeInfo(), elements); |
| 1082 } | 1082 } |
| 1083 | 1083 |
| 1084 void registerGetRuntimeTypeArgument(TreeElements elements) { | 1084 void registerGetRuntimeTypeArgument(TreeElements elements) { |
| 1085 enqueueInResolution(getGetRuntimeTypeArgument(), elements); | 1085 enqueueInResolution(getGetRuntimeTypeArgument(), elements); |
| 1086 } | 1086 } |
| 1087 | 1087 |
| 1088 void registerRuntimeType(TreeElements elements) { | 1088 void registerGenericCallMethod(Element callMethod, |
| 1089 Enqueuer enqueuer, TreeElements elements) { |
| 1090 if (enqueuer.isResolutionQueue || methodNeedsRti(callMethod)) { |
| 1091 registerApplySignature(enqueuer, elements); |
| 1092 } |
| 1093 } |
| 1094 |
| 1095 void registerGenericClosure(Element closure, |
| 1096 Enqueuer enqueuer, TreeElements elements) { |
| 1097 if (enqueuer.isResolutionQueue || methodNeedsRti(closure)) { |
| 1098 registerApplySignature(enqueuer, elements); |
| 1099 } |
| 1100 } |
| 1101 |
| 1102 void registerApplySignature(Enqueuer enqueuer, TreeElements elements) { |
| 1103 // Calls to [:applySignature:] are generated by the emitter and we therefore |
| 1104 // need to enqueue the used elements in the codegen enqueuer as well as in |
| 1105 // the resolution enqueuer. |
| 1106 enqueue(enqueuer, getSetRuntimeTypeInfo(), elements); |
| 1107 enqueue(enqueuer, getGetRuntimeTypeInfo(), elements); |
| 1108 enqueue(enqueuer, getApplySignature(), elements); |
| 1109 enqueue(enqueuer, getGetRuntimeTypeArguments(), elements); |
| 1110 enqueuer.registerInstantiatedClass(compiler.listClass, elements); |
| 1111 } |
| 1112 |
| 1113 void registerRuntimeType(Enqueuer enqueuer, TreeElements elements) { |
| 1114 registerApplySignature(enqueuer, elements); |
| 1089 enqueueInResolution(getSetRuntimeTypeInfo(), elements); | 1115 enqueueInResolution(getSetRuntimeTypeInfo(), elements); |
| 1090 enqueueInResolution(getGetRuntimeTypeInfo(), elements); | 1116 enqueueInResolution(getGetRuntimeTypeInfo(), elements); |
| 1091 enqueueInResolution(getGetRuntimeTypeArgument(), elements); | 1117 registerGetRuntimeTypeArgument(elements); |
| 1092 compiler.enqueuer.resolution.registerInstantiatedClass( | 1118 compiler.enqueuer.resolution.registerInstantiatedClass( |
| 1093 compiler.listClass, elements); | 1119 compiler.listClass, elements); |
| 1094 } | 1120 } |
| 1095 | 1121 |
| 1096 void registerTypeVariableExpression(TreeElements elements) { | 1122 void registerTypeVariableExpression(TreeElements elements) { |
| 1097 registerRuntimeType(elements); | 1123 enqueueInResolution(getSetRuntimeTypeInfo(), elements); |
| 1124 enqueueInResolution(getGetRuntimeTypeInfo(), elements); |
| 1125 registerGetRuntimeTypeArgument(elements); |
| 1126 compiler.enqueuer.resolution.registerInstantiatedClass( |
| 1127 compiler.listClass, elements); |
| 1098 enqueueInResolution(getRuntimeTypeToString(), elements); | 1128 enqueueInResolution(getRuntimeTypeToString(), elements); |
| 1099 enqueueInResolution(getCreateRuntimeType(), elements); | 1129 enqueueInResolution(getCreateRuntimeType(), elements); |
| 1100 } | 1130 } |
| 1101 | 1131 |
| 1102 void registerIsCheck(DartType type, Enqueuer world, TreeElements elements) { | 1132 void registerIsCheck(DartType type, Enqueuer world, TreeElements elements) { |
| 1103 world.registerInstantiatedClass(compiler.boolClass, elements); | |
| 1104 bool isTypeVariable = type.kind == TypeKind.TYPE_VARIABLE; | |
| 1105 if (!type.isRaw || isTypeVariable) { | |
| 1106 enqueueInResolution(getSetRuntimeTypeInfo(), elements); | |
| 1107 enqueueInResolution(getGetRuntimeTypeInfo(), elements); | |
| 1108 enqueueInResolution(getGetRuntimeTypeArgument(), elements); | |
| 1109 enqueueInResolution(getCheckSubtype(), elements); | |
| 1110 if (isTypeVariable) { | |
| 1111 enqueueInResolution(getGetObjectIsSubtype(), elements); | |
| 1112 } | |
| 1113 world.registerInstantiatedClass(compiler.listClass, elements); | |
| 1114 } | |
| 1115 // [registerIsCheck] is also called for checked mode checks, so we | 1133 // [registerIsCheck] is also called for checked mode checks, so we |
| 1116 // need to register checked mode helpers. | 1134 // need to register checked mode helpers. |
| 1117 if (compiler.enableTypeAssertions) { | 1135 if (compiler.enableTypeAssertions) { |
| 1118 Element e = getCheckedModeHelper(type, typeCast: false); | 1136 Element e = getCheckedModeHelper(type, typeCast: false); |
| 1119 if (e != null) world.addToWorkList(e); | 1137 if (e != null) world.addToWorkList(e); |
| 1120 // We also need the native variant of the check (for DOM types). | 1138 // We also need the native variant of the check (for DOM types). |
| 1121 e = getNativeCheckedModeHelper(type, typeCast: false); | 1139 e = getNativeCheckedModeHelper(type, typeCast: false); |
| 1122 if (e != null) world.addToWorkList(e); | 1140 if (e != null) world.addToWorkList(e); |
| 1141 } else { |
| 1142 if (type.isMalformed) { |
| 1143 registerThrowRuntimeError(elements); |
| 1144 return; |
| 1145 } |
| 1123 } | 1146 } |
| 1124 if (type.element.isNative()) { | 1147 if (type.element.isNative()) { |
| 1125 // We will neeed to add the "$is" and "$as" properties on the | 1148 // We will neeed to add the "$is" and "$as" properties on the |
| 1126 // JavaScript object prototype, so we make sure | 1149 // JavaScript object prototype, so we make sure |
| 1127 // [:defineProperty:] is compiled. | 1150 // [:defineProperty:] is compiled. |
| 1128 world.addToWorkList( | 1151 world.addToWorkList( |
| 1129 compiler.findHelper(const SourceString('defineProperty'))); | 1152 compiler.findHelper(const SourceString('defineProperty'))); |
| 1130 } | 1153 } |
| 1154 world.registerInstantiatedClass(compiler.boolClass, elements); |
| 1155 bool isTypeVariable = type.kind == TypeKind.TYPE_VARIABLE; |
| 1156 if (!type.isRaw || type.containsTypeVariables) { |
| 1157 enqueueInResolution(getSetRuntimeTypeInfo(), elements); |
| 1158 enqueueInResolution(getGetRuntimeTypeInfo(), elements); |
| 1159 enqueueInResolution(getGetRuntimeTypeArgument(), elements); |
| 1160 enqueueInResolution(getCheckSubtype(), elements); |
| 1161 if (isTypeVariable) { |
| 1162 enqueueInResolution(getGetObjectIsSubtype(), elements); |
| 1163 } |
| 1164 world.registerInstantiatedClass(compiler.listClass, elements); |
| 1165 } |
| 1166 if (type is FunctionType) { |
| 1167 enqueueInResolution(getCheckFunctionSubtype(), elements); |
| 1168 } |
| 1131 } | 1169 } |
| 1132 | 1170 |
| 1133 void registerAsCheck(DartType type, TreeElements elements) { | 1171 void registerAsCheck(DartType type, TreeElements elements) { |
| 1134 Element e = getCheckedModeHelper(type, typeCast: true); | 1172 Element e = getCheckedModeHelper(type, typeCast: true); |
| 1135 enqueueInResolution(e, elements); | 1173 enqueueInResolution(e, elements); |
| 1136 // We also need the native variant of the check (for DOM types). | 1174 // We also need the native variant of the check (for DOM types). |
| 1137 e = getNativeCheckedModeHelper(type, typeCast: true); | 1175 e = getNativeCheckedModeHelper(type, typeCast: true); |
| 1138 enqueueInResolution(e, elements); | 1176 enqueueInResolution(e, elements); |
| 1139 } | 1177 } |
| 1140 | 1178 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1196 } | 1234 } |
| 1197 | 1235 |
| 1198 void registerClassUsingVariableExpression(ClassElement cls) { | 1236 void registerClassUsingVariableExpression(ClassElement cls) { |
| 1199 rti.classesUsingTypeVariableExpression.add(cls); | 1237 rti.classesUsingTypeVariableExpression.add(cls); |
| 1200 } | 1238 } |
| 1201 | 1239 |
| 1202 bool needsRti(ClassElement cls) { | 1240 bool needsRti(ClassElement cls) { |
| 1203 return rti.classesNeedingRti.contains(cls) || compiler.enabledRuntimeType; | 1241 return rti.classesNeedingRti.contains(cls) || compiler.enabledRuntimeType; |
| 1204 } | 1242 } |
| 1205 | 1243 |
| 1244 bool methodNeedsRti(Element cls) { |
| 1245 return rti.methodsNeedingRti.contains(cls) || compiler.enabledRuntimeType; |
| 1246 } |
| 1247 |
| 1248 void enqueue(Enqueuer enqueuer, Element e, TreeElements elements) { |
| 1249 enqueuer.addToWorkList(e); |
| 1250 elements.registerDependency(e); |
| 1251 } |
| 1252 |
| 1206 void enqueueInResolution(Element e, TreeElements elements) { | 1253 void enqueueInResolution(Element e, TreeElements elements) { |
| 1207 if (e == null) return; | 1254 if (e == null) return; |
| 1208 ResolutionEnqueuer enqueuer = compiler.enqueuer.resolution; | 1255 ResolutionEnqueuer enqueuer = compiler.enqueuer.resolution; |
| 1209 enqueuer.addToWorkList(e); | 1256 enqueue(enqueuer, e, elements); |
| 1210 elements.registerDependency(e); | |
| 1211 } | 1257 } |
| 1212 | 1258 |
| 1213 void registerConstantMap(TreeElements elements) { | 1259 void registerConstantMap(TreeElements elements) { |
| 1214 Element e = compiler.findHelper(const SourceString('ConstantMap')); | 1260 Element e = compiler.findHelper(const SourceString('ConstantMap')); |
| 1215 if (e != null) { | 1261 if (e != null) { |
| 1216 compiler.enqueuer.resolution.registerInstantiatedClass(e, elements); | 1262 compiler.enqueuer.resolution.registerInstantiatedClass(e, elements); |
| 1217 } | 1263 } |
| 1218 e = compiler.findHelper(const SourceString('ConstantProtoMap')); | 1264 e = compiler.findHelper(const SourceString('ConstantProtoMap')); |
| 1219 if (e != null) { | 1265 if (e != null) { |
| 1220 compiler.enqueuer.resolution.registerInstantiatedClass(e, elements); | 1266 compiler.enqueuer.resolution.registerInstantiatedClass(e, elements); |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1599 } | 1645 } |
| 1600 | 1646 |
| 1601 Element getSetRuntimeTypeInfo() { | 1647 Element getSetRuntimeTypeInfo() { |
| 1602 return compiler.findHelper(const SourceString('setRuntimeTypeInfo')); | 1648 return compiler.findHelper(const SourceString('setRuntimeTypeInfo')); |
| 1603 } | 1649 } |
| 1604 | 1650 |
| 1605 Element getGetRuntimeTypeInfo() { | 1651 Element getGetRuntimeTypeInfo() { |
| 1606 return compiler.findHelper(const SourceString('getRuntimeTypeInfo')); | 1652 return compiler.findHelper(const SourceString('getRuntimeTypeInfo')); |
| 1607 } | 1653 } |
| 1608 | 1654 |
| 1655 Element getApplySignature() { |
| 1656 return compiler.findHelper(const SourceString('applySignature')); |
| 1657 } |
| 1658 |
| 1659 Element getGetRuntimeTypeArguments() { |
| 1660 return compiler.findHelper(const SourceString('getRuntimeTypeArguments')); |
| 1661 } |
| 1662 |
| 1609 Element getGetRuntimeTypeArgument() { | 1663 Element getGetRuntimeTypeArgument() { |
| 1610 return compiler.findHelper(const SourceString('getRuntimeTypeArgument')); | 1664 return compiler.findHelper(const SourceString('getRuntimeTypeArgument')); |
| 1611 } | 1665 } |
| 1612 | 1666 |
| 1613 Element getRuntimeTypeToString() { | 1667 Element getRuntimeTypeToString() { |
| 1614 return compiler.findHelper(const SourceString('runtimeTypeToString')); | 1668 return compiler.findHelper(const SourceString('runtimeTypeToString')); |
| 1615 } | 1669 } |
| 1616 | 1670 |
| 1617 Element getCheckSubtype() { | 1671 Element getCheckSubtype() { |
| 1618 return compiler.findHelper(const SourceString('checkSubtype')); | 1672 return compiler.findHelper(const SourceString('checkSubtype')); |
| 1619 } | 1673 } |
| 1620 | 1674 |
| 1621 Element getGetObjectIsSubtype() { | 1675 Element getGetObjectIsSubtype() { |
| 1622 return compiler.findHelper(const SourceString('objectIsSubtype')); | 1676 return compiler.findHelper(const SourceString('objectIsSubtype')); |
| 1623 } | 1677 } |
| 1624 | 1678 |
| 1679 Element getCheckFunctionSubtype() { |
| 1680 return compiler.findHelper(const SourceString('checkFunctionSubtype')); |
| 1681 } |
| 1682 |
| 1625 Element getThrowNoSuchMethod() { | 1683 Element getThrowNoSuchMethod() { |
| 1626 return compiler.findHelper(const SourceString('throwNoSuchMethod')); | 1684 return compiler.findHelper(const SourceString('throwNoSuchMethod')); |
| 1627 } | 1685 } |
| 1628 | 1686 |
| 1629 Element getCreateRuntimeType() { | 1687 Element getCreateRuntimeType() { |
| 1630 return compiler.findHelper(const SourceString('createRuntimeType')); | 1688 return compiler.findHelper(const SourceString('createRuntimeType')); |
| 1631 } | 1689 } |
| 1632 | 1690 |
| 1633 Element getFallThroughError() { | 1691 Element getFallThroughError() { |
| 1634 return compiler.findHelper(const SourceString("getFallThroughError")); | 1692 return compiler.findHelper(const SourceString("getFallThroughError")); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1667 ClassElement get constListImplementation => jsArrayClass; | 1725 ClassElement get constListImplementation => jsArrayClass; |
| 1668 ClassElement get fixedListImplementation => jsFixedArrayClass; | 1726 ClassElement get fixedListImplementation => jsFixedArrayClass; |
| 1669 ClassElement get growableListImplementation => jsExtendableArrayClass; | 1727 ClassElement get growableListImplementation => jsExtendableArrayClass; |
| 1670 ClassElement get mapImplementation => mapLiteralClass; | 1728 ClassElement get mapImplementation => mapLiteralClass; |
| 1671 ClassElement get constMapImplementation => constMapLiteralClass; | 1729 ClassElement get constMapImplementation => constMapLiteralClass; |
| 1672 ClassElement get functionImplementation => jsFunctionClass; | 1730 ClassElement get functionImplementation => jsFunctionClass; |
| 1673 ClassElement get typeImplementation => typeLiteralClass; | 1731 ClassElement get typeImplementation => typeLiteralClass; |
| 1674 ClassElement get boolImplementation => jsBoolClass; | 1732 ClassElement get boolImplementation => jsBoolClass; |
| 1675 ClassElement get nullImplementation => jsNullClass; | 1733 ClassElement get nullImplementation => jsNullClass; |
| 1676 } | 1734 } |
| OLD | NEW |