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

Side by Side Diff: pkg/compiler/lib/src/ssa/optimize.dart

Issue 2981543002: Handle type variable test and typed list literal. (Closed)
Patch Set: Created 3 years, 5 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
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 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem; 5 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem;
6 import '../common/names.dart' show Selectors; 6 import '../common/names.dart' show Selectors;
7 import '../common/tasks.dart' show CompilerTask; 7 import '../common/tasks.dart' show CompilerTask;
8 import '../compiler.dart' show Compiler; 8 import '../compiler.dart' show Compiler;
9 import '../constants/constant_system.dart'; 9 import '../constants/constant_system.dart';
10 import '../constants/values.dart'; 10 import '../constants/values.dart';
(...skipping 1239 matching lines...) Expand 10 before | Expand all | Expand 10 after
1250 return new HTypeInfoReadRaw(source, _closedWorld.commonMasks.dynamicType); 1250 return new HTypeInfoReadRaw(source, _closedWorld.commonMasks.dynamicType);
1251 } 1251 }
1252 1252
1253 // TODO(sra): Consider fusing type expression trees with no type variables, 1253 // TODO(sra): Consider fusing type expression trees with no type variables,
1254 // as these could be represented like constants. 1254 // as these could be represented like constants.
1255 1255
1256 return tryCopyInfo() ?? node; 1256 return tryCopyInfo() ?? node;
1257 } 1257 }
1258 1258
1259 HInstruction visitTypeInfoReadVariable(HTypeInfoReadVariable node) { 1259 HInstruction visitTypeInfoReadVariable(HTypeInfoReadVariable node) {
1260 ResolutionTypeVariableType variable = node.variable; 1260 TypeVariableType variable = node.variable;
1261 ClassEntity contextClass = variable.element.typeDeclaration;
1261 HInstruction object = node.object; 1262 HInstruction object = node.object;
1262 1263
1263 HInstruction finishGroundType(ResolutionInterfaceType groundType) { 1264 HInstruction finishGroundType(InterfaceType groundType) {
1264 ResolutionInterfaceType typeAtVariable = 1265 InterfaceType typeAtVariable =
1265 groundType.asInstanceOf(variable.element.enclosingClass); 1266 _closedWorld.dartTypes.asInstanceOf(groundType, contextClass);
1266 if (typeAtVariable != null) { 1267 if (typeAtVariable != null) {
1267 int index = variable.element.index; 1268 int index = variable.element.index;
1268 ResolutionDartType typeArgument = typeAtVariable.typeArguments[index]; 1269 DartType typeArgument = typeAtVariable.typeArguments[index];
1269 HInstruction replacement = new HTypeInfoExpression( 1270 HInstruction replacement = new HTypeInfoExpression(
1270 TypeInfoExpressionKind.COMPLETE, 1271 TypeInfoExpressionKind.COMPLETE,
1271 typeArgument, 1272 typeArgument,
1272 const <HInstruction>[], 1273 const <HInstruction>[],
1273 _closedWorld.commonMasks.dynamicType); 1274 _closedWorld.commonMasks.dynamicType);
1274 return replacement; 1275 return replacement;
1275 } 1276 }
1276 return node; 1277 return node;
1277 } 1278 }
1278 1279
1279 /// Read the type variable from an allocation of type [createdClass], where 1280 /// Read the type variable from an allocation of type [createdClass], where
1280 /// [selectTypeArgumentFromObjectCreation] extracts the type argument from 1281 /// [selectTypeArgumentFromObjectCreation] extracts the type argument from
1281 /// the allocation for factory constructor call. 1282 /// the allocation for factory constructor call.
1282 HInstruction finishSubstituted(ClassElement createdClass, 1283 HInstruction finishSubstituted(ClassEntity createdClass,
1283 HInstruction selectTypeArgumentFromObjectCreation(int index)) { 1284 HInstruction selectTypeArgumentFromObjectCreation(int index)) {
1285 InterfaceType thisType = _closedWorld.dartTypes.getThisType(createdClass);
1286
1284 HInstruction instructionForTypeVariable(ResolutionTypeVariableType tv) { 1287 HInstruction instructionForTypeVariable(ResolutionTypeVariableType tv) {
1285 return selectTypeArgumentFromObjectCreation( 1288 return selectTypeArgumentFromObjectCreation(
1286 createdClass.thisType.typeArguments.indexOf(tv)); 1289 thisType.typeArguments.indexOf(tv));
1287 } 1290 }
1288 1291
1289 ResolutionDartType type = createdClass.thisType 1292 DartType type = _closedWorld.dartTypes
1290 .asInstanceOf(variable.element.enclosingClass) 1293 .asInstanceOf(thisType, contextClass)
1291 .typeArguments[variable.element.index]; 1294 .typeArguments[variable.element.index];
1292 if (type is ResolutionTypeVariableType) { 1295 if (type is TypeVariableType) {
1293 return instructionForTypeVariable(type); 1296 return instructionForTypeVariable(type);
1294 } 1297 }
1295 List<HInstruction> arguments = <HInstruction>[]; 1298 List<HInstruction> arguments = <HInstruction>[];
1296 type.forEachTypeVariable((v) { 1299 type.forEachTypeVariable((v) {
1297 arguments.add(instructionForTypeVariable(v)); 1300 arguments.add(instructionForTypeVariable(v));
1298 }); 1301 });
1299 HInstruction replacement = new HTypeInfoExpression( 1302 HInstruction replacement = new HTypeInfoExpression(
1300 TypeInfoExpressionKind.COMPLETE, 1303 TypeInfoExpressionKind.COMPLETE,
1301 type, 1304 type,
1302 arguments, 1305 arguments,
(...skipping 1685 matching lines...) Expand 10 before | Expand all | Expand 10 after
2988 2991
2989 keyedValues.forEach((receiver, values) { 2992 keyedValues.forEach((receiver, values) {
2990 result.keyedValues[receiver] = 2993 result.keyedValues[receiver] =
2991 new Map<HInstruction, HInstruction>.from(values); 2994 new Map<HInstruction, HInstruction>.from(values);
2992 }); 2995 });
2993 2996
2994 result.nonEscapingReceivers.addAll(nonEscapingReceivers); 2997 result.nonEscapingReceivers.addAll(nonEscapingReceivers);
2995 return result; 2998 return result;
2996 } 2999 }
2997 } 3000 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698