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 '../common/codegen.dart' show CodegenWorkItem; | 5 import '../common/codegen.dart' show CodegenWorkItem; |
6 import '../common/tasks.dart' show CompilerTask; | 6 import '../common/tasks.dart' show CompilerTask; |
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 '../core_types.dart' show CoreClasses; | 10 import '../core_types.dart' show CoreClasses; |
(...skipping 1039 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1050 HInstruction replacement = new HTypeInfoExpression( | 1050 HInstruction replacement = new HTypeInfoExpression( |
1051 TypeInfoExpressionKind.COMPLETE, | 1051 TypeInfoExpressionKind.COMPLETE, |
1052 typeArgument, | 1052 typeArgument, |
1053 const <HInstruction>[], | 1053 const <HInstruction>[], |
1054 backend.dynamicType); | 1054 backend.dynamicType); |
1055 return replacement; | 1055 return replacement; |
1056 } | 1056 } |
1057 return node; | 1057 return node; |
1058 } | 1058 } |
1059 | 1059 |
| 1060 /// Read the type variable from an allocation of type [createdClass], where |
| 1061 /// [selectTypeArgumentFromObjectCreation] extracts the type argument from |
| 1062 /// the allocation for factory constructor call. |
| 1063 HInstruction finishSubstituted(ClassElement createdClass, |
| 1064 HInstruction selectTypeArgumentFromObjectCreation(int index)) { |
| 1065 HInstruction instructionForTypeVariable(TypeVariableType tv) { |
| 1066 return selectTypeArgumentFromObjectCreation( |
| 1067 createdClass.thisType.typeArguments.indexOf(tv)); |
| 1068 } |
| 1069 |
| 1070 DartType type = createdClass.thisType |
| 1071 .asInstanceOf(variable.element.enclosingClass) |
| 1072 .typeArguments[variable.element.index]; |
| 1073 if (type is TypeVariableType) { |
| 1074 return instructionForTypeVariable(type); |
| 1075 } |
| 1076 List<HInstruction> arguments = <HInstruction>[]; |
| 1077 type.forEachTypeVariable((v) { |
| 1078 arguments.add(instructionForTypeVariable(v)); |
| 1079 }); |
| 1080 HInstruction replacement = new HTypeInfoExpression( |
| 1081 TypeInfoExpressionKind.COMPLETE, |
| 1082 type, |
| 1083 arguments, |
| 1084 backend.dynamicType); |
| 1085 return replacement; |
| 1086 } |
| 1087 |
1060 // Type variable evaluated in the context of a constant can be replaced with | 1088 // Type variable evaluated in the context of a constant can be replaced with |
1061 // a ground term type. | 1089 // a ground term type. |
1062 if (object is HConstant) { | 1090 if (object is HConstant) { |
1063 ConstantValue value = object.constant; | 1091 ConstantValue value = object.constant; |
1064 if (value is ConstructedConstantValue) { | 1092 if (value is ConstructedConstantValue) { |
1065 return finishGroundType(value.type); | 1093 return finishGroundType(value.type); |
1066 } | 1094 } |
1067 return node; | 1095 return node; |
1068 } | 1096 } |
1069 | 1097 |
1070 // TODO(sra): HTypeInfoReadVariable on an instance creation can be replaced | 1098 // Look for an allocation with type information and re-write type variable |
1071 // with an input of the instance creation's HTypeInfoExpression (or a | 1099 // as a function of the type parameters of the allocation. This effectively |
1072 // HTypeInfoExpression of an input). This would in effect store-forward the | 1100 // store-forwards a type variable read through an allocation. |
1073 // type parameters. | 1101 |
| 1102 // Match: |
| 1103 // |
| 1104 // setRuntimeTypeInfo( |
| 1105 // HForeignNew(ClassElement), |
| 1106 // HTypeInfoExpression(t_0, t_1, t_2, ...)); |
| 1107 // |
| 1108 // The `t_i` are the values of the type parameters of ClassElement. |
| 1109 if (object is HInvokeStatic) { |
| 1110 if (object.element == helpers.setRuntimeTypeInfo) { |
| 1111 HInstruction allocation = object.inputs[0]; |
| 1112 if (allocation is HForeignNew) { |
| 1113 HInstruction typeInfo = object.inputs[1]; |
| 1114 if (typeInfo is HTypeInfoExpression) { |
| 1115 return finishSubstituted( |
| 1116 allocation.element, (int index) => typeInfo.inputs[index]); |
| 1117 } |
| 1118 } |
| 1119 return node; |
| 1120 } |
| 1121 // TODO(sra): Factory constructors pass type arguments after the value |
| 1122 // arguments. The [select] argument indexes into these type arguments. |
| 1123 } |
| 1124 |
| 1125 // Non-generic type (which extends or mixes in a generic type, for example |
| 1126 // CodeUnits extends UnmodifiableListBase<int>). |
| 1127 // Also used for raw-type when the type parameters are elided. |
| 1128 if (object is HForeignNew) { |
| 1129 return finishSubstituted( |
| 1130 object.element, |
| 1131 // If there are type arguments, all type arguments are 'dynamic'. |
| 1132 (int i) => graph.addConstantNull(compiler)); |
| 1133 } |
1074 | 1134 |
1075 return node; | 1135 return node; |
1076 } | 1136 } |
1077 } | 1137 } |
1078 | 1138 |
1079 class SsaCheckInserter extends HBaseVisitor implements OptimizationPhase { | 1139 class SsaCheckInserter extends HBaseVisitor implements OptimizationPhase { |
1080 final Set<HInstruction> boundsChecked; | 1140 final Set<HInstruction> boundsChecked; |
1081 final CodegenWorkItem work; | 1141 final CodegenWorkItem work; |
1082 final bool trustPrimitives; | 1142 final bool trustPrimitives; |
1083 final JavaScriptBackend backend; | 1143 final JavaScriptBackend backend; |
(...skipping 1381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2465 | 2525 |
2466 keyedValues.forEach((receiver, values) { | 2526 keyedValues.forEach((receiver, values) { |
2467 result.keyedValues[receiver] = | 2527 result.keyedValues[receiver] = |
2468 new Map<HInstruction, HInstruction>.from(values); | 2528 new Map<HInstruction, HInstruction>.from(values); |
2469 }); | 2529 }); |
2470 | 2530 |
2471 result.nonEscapingReceivers.addAll(nonEscapingReceivers); | 2531 result.nonEscapingReceivers.addAll(nonEscapingReceivers); |
2472 return result; | 2532 return result; |
2473 } | 2533 } |
2474 } | 2534 } |
OLD | NEW |