| 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 import '../closure.dart'; | 5 import '../closure.dart'; |
| 6 import '../common.dart'; | 6 import '../common.dart'; |
| 7 import '../compiler.dart' show Compiler; | 7 import '../compiler.dart' show Compiler; |
| 8 import '../constants/constant_system.dart'; | 8 import '../constants/constant_system.dart'; |
| 9 import '../constants/values.dart'; | 9 import '../constants/values.dart'; |
| 10 import '../dart_types.dart'; | 10 import '../dart_types.dart'; |
| (...skipping 933 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 944 | 944 |
| 945 bool canBePrimitive(Compiler compiler) { | 945 bool canBePrimitive(Compiler compiler) { |
| 946 return canBePrimitiveNumber(compiler) || | 946 return canBePrimitiveNumber(compiler) || |
| 947 canBePrimitiveArray(compiler) || | 947 canBePrimitiveArray(compiler) || |
| 948 canBePrimitiveBoolean(compiler) || | 948 canBePrimitiveBoolean(compiler) || |
| 949 canBePrimitiveString(compiler) || | 949 canBePrimitiveString(compiler) || |
| 950 isNull(); | 950 isNull(); |
| 951 } | 951 } |
| 952 | 952 |
| 953 bool canBePrimitiveNumber(Compiler compiler) { | 953 bool canBePrimitiveNumber(Compiler compiler) { |
| 954 ClassWorld classWorld = compiler.world; | 954 ClassWorld classWorld = compiler.closedWorld; |
| 955 JavaScriptBackend backend = compiler.backend; | 955 JavaScriptBackend backend = compiler.backend; |
| 956 BackendHelpers helpers = backend.helpers; | 956 BackendHelpers helpers = backend.helpers; |
| 957 // TODO(sra): It should be possible to test only jsDoubleClass and | 957 // TODO(sra): It should be possible to test only jsDoubleClass and |
| 958 // jsUInt31Class, since all others are superclasses of these two. | 958 // jsUInt31Class, since all others are superclasses of these two. |
| 959 return containsType(instructionType, helpers.jsNumberClass, classWorld) || | 959 return containsType(instructionType, helpers.jsNumberClass, classWorld) || |
| 960 containsType(instructionType, helpers.jsIntClass, classWorld) || | 960 containsType(instructionType, helpers.jsIntClass, classWorld) || |
| 961 containsType(instructionType, helpers.jsPositiveIntClass, classWorld) || | 961 containsType(instructionType, helpers.jsPositiveIntClass, classWorld) || |
| 962 containsType(instructionType, helpers.jsUInt32Class, classWorld) || | 962 containsType(instructionType, helpers.jsUInt32Class, classWorld) || |
| 963 containsType(instructionType, helpers.jsUInt31Class, classWorld) || | 963 containsType(instructionType, helpers.jsUInt31Class, classWorld) || |
| 964 containsType(instructionType, helpers.jsDoubleClass, classWorld); | 964 containsType(instructionType, helpers.jsDoubleClass, classWorld); |
| 965 } | 965 } |
| 966 | 966 |
| 967 bool canBePrimitiveBoolean(Compiler compiler) { | 967 bool canBePrimitiveBoolean(Compiler compiler) { |
| 968 ClassWorld classWorld = compiler.world; | 968 ClassWorld classWorld = compiler.closedWorld; |
| 969 JavaScriptBackend backend = compiler.backend; | 969 JavaScriptBackend backend = compiler.backend; |
| 970 BackendHelpers helpers = backend.helpers; | 970 BackendHelpers helpers = backend.helpers; |
| 971 return containsType(instructionType, helpers.jsBoolClass, classWorld); | 971 return containsType(instructionType, helpers.jsBoolClass, classWorld); |
| 972 } | 972 } |
| 973 | 973 |
| 974 bool canBePrimitiveArray(Compiler compiler) { | 974 bool canBePrimitiveArray(Compiler compiler) { |
| 975 ClassWorld classWorld = compiler.world; | 975 ClassWorld classWorld = compiler.closedWorld; |
| 976 JavaScriptBackend backend = compiler.backend; | 976 JavaScriptBackend backend = compiler.backend; |
| 977 BackendHelpers helpers = backend.helpers; | 977 BackendHelpers helpers = backend.helpers; |
| 978 return containsType(instructionType, helpers.jsArrayClass, classWorld) || | 978 return containsType(instructionType, helpers.jsArrayClass, classWorld) || |
| 979 containsType(instructionType, helpers.jsFixedArrayClass, classWorld) || | 979 containsType(instructionType, helpers.jsFixedArrayClass, classWorld) || |
| 980 containsType( | 980 containsType( |
| 981 instructionType, helpers.jsExtendableArrayClass, classWorld) || | 981 instructionType, helpers.jsExtendableArrayClass, classWorld) || |
| 982 containsType( | 982 containsType( |
| 983 instructionType, helpers.jsUnmodifiableArrayClass, classWorld); | 983 instructionType, helpers.jsUnmodifiableArrayClass, classWorld); |
| 984 } | 984 } |
| 985 | 985 |
| 986 bool isIndexablePrimitive(Compiler compiler) { | 986 bool isIndexablePrimitive(Compiler compiler) { |
| 987 ClassWorld classWorld = compiler.world; | 987 ClassWorld classWorld = compiler.closedWorld; |
| 988 JavaScriptBackend backend = compiler.backend; | 988 JavaScriptBackend backend = compiler.backend; |
| 989 BackendHelpers helpers = backend.helpers; | 989 BackendHelpers helpers = backend.helpers; |
| 990 return instructionType.containsOnlyString(classWorld) || | 990 return instructionType.containsOnlyString(classWorld) || |
| 991 isInstanceOf(instructionType, helpers.jsIndexableClass, classWorld); | 991 isInstanceOf(instructionType, helpers.jsIndexableClass, classWorld); |
| 992 } | 992 } |
| 993 | 993 |
| 994 bool isFixedArray(Compiler compiler) { | 994 bool isFixedArray(Compiler compiler) { |
| 995 ClassWorld classWorld = compiler.world; | 995 ClassWorld classWorld = compiler.closedWorld; |
| 996 JavaScriptBackend backend = compiler.backend; | 996 JavaScriptBackend backend = compiler.backend; |
| 997 BackendHelpers helpers = backend.helpers; | 997 BackendHelpers helpers = backend.helpers; |
| 998 // TODO(sra): Recognize the union of these types as well. | 998 // TODO(sra): Recognize the union of these types as well. |
| 999 return containsOnlyType( | 999 return containsOnlyType( |
| 1000 instructionType, helpers.jsFixedArrayClass, classWorld) || | 1000 instructionType, helpers.jsFixedArrayClass, classWorld) || |
| 1001 containsOnlyType( | 1001 containsOnlyType( |
| 1002 instructionType, helpers.jsUnmodifiableArrayClass, classWorld); | 1002 instructionType, helpers.jsUnmodifiableArrayClass, classWorld); |
| 1003 } | 1003 } |
| 1004 | 1004 |
| 1005 bool isExtendableArray(Compiler compiler) { | 1005 bool isExtendableArray(Compiler compiler) { |
| 1006 ClassWorld classWorld = compiler.world; | 1006 ClassWorld classWorld = compiler.closedWorld; |
| 1007 JavaScriptBackend backend = compiler.backend; | 1007 JavaScriptBackend backend = compiler.backend; |
| 1008 BackendHelpers helpers = backend.helpers; | 1008 BackendHelpers helpers = backend.helpers; |
| 1009 return containsOnlyType( | 1009 return containsOnlyType( |
| 1010 instructionType, helpers.jsExtendableArrayClass, classWorld); | 1010 instructionType, helpers.jsExtendableArrayClass, classWorld); |
| 1011 } | 1011 } |
| 1012 | 1012 |
| 1013 bool isMutableArray(Compiler compiler) { | 1013 bool isMutableArray(Compiler compiler) { |
| 1014 ClassWorld classWorld = compiler.world; | 1014 ClassWorld classWorld = compiler.closedWorld; |
| 1015 JavaScriptBackend backend = compiler.backend; | 1015 JavaScriptBackend backend = compiler.backend; |
| 1016 BackendHelpers helpers = backend.helpers; | 1016 BackendHelpers helpers = backend.helpers; |
| 1017 return isInstanceOf( | 1017 return isInstanceOf( |
| 1018 instructionType, helpers.jsMutableArrayClass, classWorld); | 1018 instructionType, helpers.jsMutableArrayClass, classWorld); |
| 1019 } | 1019 } |
| 1020 | 1020 |
| 1021 bool isReadableArray(Compiler compiler) { | 1021 bool isReadableArray(Compiler compiler) { |
| 1022 ClassWorld classWorld = compiler.world; | 1022 ClassWorld classWorld = compiler.closedWorld; |
| 1023 JavaScriptBackend backend = compiler.backend; | 1023 JavaScriptBackend backend = compiler.backend; |
| 1024 BackendHelpers helpers = backend.helpers; | 1024 BackendHelpers helpers = backend.helpers; |
| 1025 return isInstanceOf(instructionType, helpers.jsArrayClass, classWorld); | 1025 return isInstanceOf(instructionType, helpers.jsArrayClass, classWorld); |
| 1026 } | 1026 } |
| 1027 | 1027 |
| 1028 bool isMutableIndexable(Compiler compiler) { | 1028 bool isMutableIndexable(Compiler compiler) { |
| 1029 ClassWorld classWorld = compiler.world; | 1029 ClassWorld classWorld = compiler.closedWorld; |
| 1030 JavaScriptBackend backend = compiler.backend; | 1030 JavaScriptBackend backend = compiler.backend; |
| 1031 BackendHelpers helpers = backend.helpers; | 1031 BackendHelpers helpers = backend.helpers; |
| 1032 return isInstanceOf( | 1032 return isInstanceOf( |
| 1033 instructionType, helpers.jsMutableIndexableClass, classWorld); | 1033 instructionType, helpers.jsMutableIndexableClass, classWorld); |
| 1034 } | 1034 } |
| 1035 | 1035 |
| 1036 bool isArray(Compiler compiler) => isReadableArray(compiler); | 1036 bool isArray(Compiler compiler) => isReadableArray(compiler); |
| 1037 | 1037 |
| 1038 bool canBePrimitiveString(Compiler compiler) { | 1038 bool canBePrimitiveString(Compiler compiler) { |
| 1039 ClassWorld classWorld = compiler.world; | 1039 ClassWorld classWorld = compiler.closedWorld; |
| 1040 JavaScriptBackend backend = compiler.backend; | 1040 JavaScriptBackend backend = compiler.backend; |
| 1041 BackendHelpers helpers = backend.helpers; | 1041 BackendHelpers helpers = backend.helpers; |
| 1042 return containsType(instructionType, helpers.jsStringClass, classWorld); | 1042 return containsType(instructionType, helpers.jsStringClass, classWorld); |
| 1043 } | 1043 } |
| 1044 | 1044 |
| 1045 bool isInteger(Compiler compiler) { | 1045 bool isInteger(Compiler compiler) { |
| 1046 ClassWorld classWorld = compiler.world; | 1046 ClassWorld classWorld = compiler.closedWorld; |
| 1047 return instructionType.containsOnlyInt(classWorld) && | 1047 return instructionType.containsOnlyInt(classWorld) && |
| 1048 !instructionType.isNullable; | 1048 !instructionType.isNullable; |
| 1049 } | 1049 } |
| 1050 | 1050 |
| 1051 bool isUInt32(Compiler compiler) { | 1051 bool isUInt32(Compiler compiler) { |
| 1052 ClassWorld classWorld = compiler.world; | 1052 ClassWorld classWorld = compiler.closedWorld; |
| 1053 JavaScriptBackend backend = compiler.backend; | 1053 JavaScriptBackend backend = compiler.backend; |
| 1054 BackendHelpers helpers = backend.helpers; | 1054 BackendHelpers helpers = backend.helpers; |
| 1055 return !instructionType.isNullable && | 1055 return !instructionType.isNullable && |
| 1056 isInstanceOf(instructionType, helpers.jsUInt32Class, classWorld); | 1056 isInstanceOf(instructionType, helpers.jsUInt32Class, classWorld); |
| 1057 } | 1057 } |
| 1058 | 1058 |
| 1059 bool isUInt31(Compiler compiler) { | 1059 bool isUInt31(Compiler compiler) { |
| 1060 ClassWorld classWorld = compiler.world; | 1060 ClassWorld classWorld = compiler.closedWorld; |
| 1061 JavaScriptBackend backend = compiler.backend; | 1061 JavaScriptBackend backend = compiler.backend; |
| 1062 BackendHelpers helpers = backend.helpers; | 1062 BackendHelpers helpers = backend.helpers; |
| 1063 return !instructionType.isNullable && | 1063 return !instructionType.isNullable && |
| 1064 isInstanceOf(instructionType, helpers.jsUInt31Class, classWorld); | 1064 isInstanceOf(instructionType, helpers.jsUInt31Class, classWorld); |
| 1065 } | 1065 } |
| 1066 | 1066 |
| 1067 bool isPositiveInteger(Compiler compiler) { | 1067 bool isPositiveInteger(Compiler compiler) { |
| 1068 ClassWorld classWorld = compiler.world; | 1068 ClassWorld classWorld = compiler.closedWorld; |
| 1069 JavaScriptBackend backend = compiler.backend; | 1069 JavaScriptBackend backend = compiler.backend; |
| 1070 BackendHelpers helpers = backend.helpers; | 1070 BackendHelpers helpers = backend.helpers; |
| 1071 return !instructionType.isNullable && | 1071 return !instructionType.isNullable && |
| 1072 isInstanceOf(instructionType, helpers.jsPositiveIntClass, classWorld); | 1072 isInstanceOf(instructionType, helpers.jsPositiveIntClass, classWorld); |
| 1073 } | 1073 } |
| 1074 | 1074 |
| 1075 bool isPositiveIntegerOrNull(Compiler compiler) { | 1075 bool isPositiveIntegerOrNull(Compiler compiler) { |
| 1076 ClassWorld classWorld = compiler.world; | 1076 ClassWorld classWorld = compiler.closedWorld; |
| 1077 JavaScriptBackend backend = compiler.backend; | 1077 JavaScriptBackend backend = compiler.backend; |
| 1078 BackendHelpers helpers = backend.helpers; | 1078 BackendHelpers helpers = backend.helpers; |
| 1079 return isInstanceOf( | 1079 return isInstanceOf( |
| 1080 instructionType, helpers.jsPositiveIntClass, classWorld); | 1080 instructionType, helpers.jsPositiveIntClass, classWorld); |
| 1081 } | 1081 } |
| 1082 | 1082 |
| 1083 bool isIntegerOrNull(Compiler compiler) { | 1083 bool isIntegerOrNull(Compiler compiler) { |
| 1084 ClassWorld classWorld = compiler.world; | 1084 ClassWorld classWorld = compiler.closedWorld; |
| 1085 return instructionType.containsOnlyInt(classWorld); | 1085 return instructionType.containsOnlyInt(classWorld); |
| 1086 } | 1086 } |
| 1087 | 1087 |
| 1088 bool isNumber(Compiler compiler) { | 1088 bool isNumber(Compiler compiler) { |
| 1089 ClassWorld classWorld = compiler.world; | 1089 ClassWorld classWorld = compiler.closedWorld; |
| 1090 return instructionType.containsOnlyNum(classWorld) && | 1090 return instructionType.containsOnlyNum(classWorld) && |
| 1091 !instructionType.isNullable; | 1091 !instructionType.isNullable; |
| 1092 } | 1092 } |
| 1093 | 1093 |
| 1094 bool isNumberOrNull(Compiler compiler) { | 1094 bool isNumberOrNull(Compiler compiler) { |
| 1095 ClassWorld classWorld = compiler.world; | 1095 ClassWorld classWorld = compiler.closedWorld; |
| 1096 return instructionType.containsOnlyNum(classWorld); | 1096 return instructionType.containsOnlyNum(classWorld); |
| 1097 } | 1097 } |
| 1098 | 1098 |
| 1099 bool isDouble(Compiler compiler) { | 1099 bool isDouble(Compiler compiler) { |
| 1100 ClassWorld classWorld = compiler.world; | 1100 ClassWorld classWorld = compiler.closedWorld; |
| 1101 return instructionType.containsOnlyDouble(classWorld) && | 1101 return instructionType.containsOnlyDouble(classWorld) && |
| 1102 !instructionType.isNullable; | 1102 !instructionType.isNullable; |
| 1103 } | 1103 } |
| 1104 | 1104 |
| 1105 bool isDoubleOrNull(Compiler compiler) { | 1105 bool isDoubleOrNull(Compiler compiler) { |
| 1106 ClassWorld classWorld = compiler.world; | 1106 ClassWorld classWorld = compiler.closedWorld; |
| 1107 return instructionType.containsOnlyDouble(classWorld); | 1107 return instructionType.containsOnlyDouble(classWorld); |
| 1108 } | 1108 } |
| 1109 | 1109 |
| 1110 bool isBoolean(Compiler compiler) { | 1110 bool isBoolean(Compiler compiler) { |
| 1111 ClassWorld classWorld = compiler.world; | 1111 ClassWorld classWorld = compiler.closedWorld; |
| 1112 return instructionType.containsOnlyBool(classWorld) && | 1112 return instructionType.containsOnlyBool(classWorld) && |
| 1113 !instructionType.isNullable; | 1113 !instructionType.isNullable; |
| 1114 } | 1114 } |
| 1115 | 1115 |
| 1116 bool isBooleanOrNull(Compiler compiler) { | 1116 bool isBooleanOrNull(Compiler compiler) { |
| 1117 ClassWorld classWorld = compiler.world; | 1117 ClassWorld classWorld = compiler.closedWorld; |
| 1118 return instructionType.containsOnlyBool(classWorld); | 1118 return instructionType.containsOnlyBool(classWorld); |
| 1119 } | 1119 } |
| 1120 | 1120 |
| 1121 bool isString(Compiler compiler) { | 1121 bool isString(Compiler compiler) { |
| 1122 ClassWorld classWorld = compiler.world; | 1122 ClassWorld classWorld = compiler.closedWorld; |
| 1123 return instructionType.containsOnlyString(classWorld) && | 1123 return instructionType.containsOnlyString(classWorld) && |
| 1124 !instructionType.isNullable; | 1124 !instructionType.isNullable; |
| 1125 } | 1125 } |
| 1126 | 1126 |
| 1127 bool isStringOrNull(Compiler compiler) { | 1127 bool isStringOrNull(Compiler compiler) { |
| 1128 ClassWorld classWorld = compiler.world; | 1128 ClassWorld classWorld = compiler.closedWorld; |
| 1129 return instructionType.containsOnlyString(classWorld); | 1129 return instructionType.containsOnlyString(classWorld); |
| 1130 } | 1130 } |
| 1131 | 1131 |
| 1132 bool isPrimitive(Compiler compiler) { | 1132 bool isPrimitive(Compiler compiler) { |
| 1133 return (isPrimitiveOrNull(compiler) && !instructionType.isNullable) || | 1133 return (isPrimitiveOrNull(compiler) && !instructionType.isNullable) || |
| 1134 isNull(); | 1134 isNull(); |
| 1135 } | 1135 } |
| 1136 | 1136 |
| 1137 bool isPrimitiveOrNull(Compiler compiler) { | 1137 bool isPrimitiveOrNull(Compiler compiler) { |
| 1138 return isIndexablePrimitive(compiler) || | 1138 return isIndexablePrimitive(compiler) || |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1371 JavaScriptBackend backend = compiler.backend; | 1371 JavaScriptBackend backend = compiler.backend; |
| 1372 if (type.kind != TypeKind.INTERFACE) { | 1372 if (type.kind != TypeKind.INTERFACE) { |
| 1373 return new HTypeConversion(type, kind, backend.dynamicType, this); | 1373 return new HTypeConversion(type, kind, backend.dynamicType, this); |
| 1374 } else if (kind == HTypeConversion.BOOLEAN_CONVERSION_CHECK) { | 1374 } else if (kind == HTypeConversion.BOOLEAN_CONVERSION_CHECK) { |
| 1375 // Boolean conversion checks work on non-nullable booleans. | 1375 // Boolean conversion checks work on non-nullable booleans. |
| 1376 return new HTypeConversion(type, kind, backend.boolType, this); | 1376 return new HTypeConversion(type, kind, backend.boolType, this); |
| 1377 } else if (kind == HTypeConversion.CHECKED_MODE_CHECK && !type.treatAsRaw) { | 1377 } else if (kind == HTypeConversion.CHECKED_MODE_CHECK && !type.treatAsRaw) { |
| 1378 throw 'creating compound check to $type (this = ${this})'; | 1378 throw 'creating compound check to $type (this = ${this})'; |
| 1379 } else { | 1379 } else { |
| 1380 TypeMask subtype = | 1380 TypeMask subtype = |
| 1381 new TypeMask.subtype(element.declaration, compiler.world); | 1381 new TypeMask.subtype(element.declaration, compiler.closedWorld); |
| 1382 return new HTypeConversion(type, kind, subtype, this); | 1382 return new HTypeConversion(type, kind, subtype, this); |
| 1383 } | 1383 } |
| 1384 } | 1384 } |
| 1385 | 1385 |
| 1386 /** | 1386 /** |
| 1387 * Return whether the instructions do not belong to a loop or | 1387 * Return whether the instructions do not belong to a loop or |
| 1388 * belong to the same loop. | 1388 * belong to the same loop. |
| 1389 */ | 1389 */ |
| 1390 bool hasSameLoopHeaderAs(HInstruction other) { | 1390 bool hasSameLoopHeaderAs(HInstruction other) { |
| 1391 return block.enclosingLoopHeader == other.block.enclosingLoopHeader; | 1391 return block.enclosingLoopHeader == other.block.enclosingLoopHeader; |
| (...skipping 2037 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3429 class HDynamicType extends HRuntimeType { | 3429 class HDynamicType extends HRuntimeType { |
| 3430 HDynamicType(DynamicType dartType, TypeMask instructionType) | 3430 HDynamicType(DynamicType dartType, TypeMask instructionType) |
| 3431 : super(const <HInstruction>[], dartType, instructionType); | 3431 : super(const <HInstruction>[], dartType, instructionType); |
| 3432 | 3432 |
| 3433 accept(HVisitor visitor) => visitor.visitDynamicType(this); | 3433 accept(HVisitor visitor) => visitor.visitDynamicType(this); |
| 3434 | 3434 |
| 3435 int typeCode() => HInstruction.DYNAMIC_TYPE_TYPECODE; | 3435 int typeCode() => HInstruction.DYNAMIC_TYPE_TYPECODE; |
| 3436 | 3436 |
| 3437 bool typeEquals(HInstruction other) => other is HDynamicType; | 3437 bool typeEquals(HInstruction other) => other is HDynamicType; |
| 3438 } | 3438 } |
| OLD | NEW |