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

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

Issue 2310573002: dart2js: Pass type information to constructor rather than add later. (Closed)
Patch Set: Filter out type info pseudofield when parsing fieldspec for mirrors Created 4 years, 3 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 'dart:collection'; 5 import 'dart:collection';
6 6
7 import 'package:js_runtime/shared/embedded_names.dart'; 7 import 'package:js_runtime/shared/embedded_names.dart';
8 8
9 import '../closure.dart'; 9 import '../closure.dart';
10 import '../common.dart'; 10 import '../common.dart';
(...skipping 1476 matching lines...) Expand 10 before | Expand all | Expand 10 after
1487 TypeMask ssaType = 1487 TypeMask ssaType =
1488 new TypeMask.nonNullExact(classElement.declaration, compiler.world); 1488 new TypeMask.nonNullExact(classElement.declaration, compiler.world);
1489 List<DartType> instantiatedTypes; 1489 List<DartType> instantiatedTypes;
1490 addInlinedInstantiation(type); 1490 addInlinedInstantiation(type);
1491 if (!currentInlinedInstantiations.isEmpty) { 1491 if (!currentInlinedInstantiations.isEmpty) {
1492 instantiatedTypes = new List<DartType>.from(currentInlinedInstantiations); 1492 instantiatedTypes = new List<DartType>.from(currentInlinedInstantiations);
1493 } 1493 }
1494 1494
1495 HInstruction newObject; 1495 HInstruction newObject;
1496 if (!isNativeUpgradeFactory) { 1496 if (!isNativeUpgradeFactory) {
1497 newObject = new HCreate( 1497 // Create the runtime type information, if needed.
1498 classElement, constructorArguments, ssaType, instantiatedTypes); 1498 bool hasRtiInput = false;
1499 if (backend.classNeedsRtiField(classElement)) {
1500 // Read the values of the type arguments and create a
1501 // HTypeInfoExpression to set on the newly create object.
1502 hasRtiInput = true;
1503 List<HInstruction> typeArguments = <HInstruction>[];
1504 classElement.typeVariables.forEach((TypeVariableType typeVariable) {
1505 HInstruction argument = localsHandler
1506 .readLocal(localsHandler.getTypeVariableAsLocal(typeVariable));
1507 typeArguments.add(argument);
1508 });
1509
1510 HInstruction typeInfo = new HTypeInfoExpression(
1511 TypeInfoExpressionKind.INSTANCE,
1512 classElement.thisType,
1513 typeArguments,
1514 backend.dynamicType);
1515 add(typeInfo);
1516 constructorArguments.add(typeInfo);
1517 }
1518
1519 newObject = new HCreate(classElement, constructorArguments, ssaType,
1520 instantiatedTypes: instantiatedTypes, hasRtiInput: hasRtiInput);
1499 if (function != null) { 1521 if (function != null) {
1500 // TODO(johnniwinther): Provide source information for creation 1522 // TODO(johnniwinther): Provide source information for creation through
1501 // through synthetic constructors. 1523 // synthetic constructors.
1502 newObject.sourceInformation = 1524 newObject.sourceInformation =
1503 sourceInformationBuilder.buildCreate(function); 1525 sourceInformationBuilder.buildCreate(function);
1504 } 1526 }
1505 add(newObject); 1527 add(newObject);
1506 } else { 1528 } else {
1507 // Bulk assign to the initialized fields. 1529 // Bulk assign to the initialized fields.
1508 newObject = graph.explicitReceiverParameter; 1530 newObject = graph.explicitReceiverParameter;
1509 // Null guard ensures an error if we are being called from an explicit 1531 // Null guard ensures an error if we are being called from an explicit
1510 // 'new' of the constructor instead of via an upgrade. It is optimized out 1532 // 'new' of the constructor instead of via an upgrade. It is optimized out
1511 // if there are field initializers. 1533 // if there are field initializers.
1512 add(new HFieldGet(null, newObject, backend.dynamicType, 1534 add(new HFieldGet(null, newObject, backend.dynamicType,
1513 isAssignable: false)); 1535 isAssignable: false));
1514 for (int i = 0; i < fields.length; i++) { 1536 for (int i = 0; i < fields.length; i++) {
1515 add(new HFieldSet(fields[i], newObject, constructorArguments[i])); 1537 add(new HFieldSet(fields[i], newObject, constructorArguments[i]));
1516 } 1538 }
1517 } 1539 }
1518 removeInlinedInstantiation(type); 1540 removeInlinedInstantiation(type);
1519 // Create the runtime type information, if needed.
1520 if (classElement.typeVariables.isNotEmpty &&
1521 backend.classNeedsRti(classElement)) {
1522 // Read the values of the type arguments and create a HTypeInfoExpression
1523 // to set on the newly create object.
1524 List<HInstruction> typeArguments = <HInstruction>[];
1525 classElement.typeVariables.forEach((TypeVariableType typeVariable) {
1526 HInstruction argument = localsHandler
1527 .readLocal(localsHandler.getTypeVariableAsLocal(typeVariable));
1528 typeArguments.add(argument);
1529 });
1530
1531 HInstruction typeInfo = new HTypeInfoExpression(
1532 TypeInfoExpressionKind.INSTANCE,
1533 classElement.thisType,
1534 typeArguments,
1535 backend.dynamicType);
1536 add(typeInfo);
1537 newObject = callSetRuntimeTypeInfo(typeInfo, newObject);
1538 }
1539 1541
1540 // Generate calls to the constructor bodies. 1542 // Generate calls to the constructor bodies.
1541 HInstruction interceptor = null; 1543 HInstruction interceptor = null;
1542 for (int index = constructorResolvedAsts.length - 1; index >= 0; index--) { 1544 for (int index = constructorResolvedAsts.length - 1; index >= 0; index--) {
1543 ResolvedAst constructorResolvedAst = constructorResolvedAsts[index]; 1545 ResolvedAst constructorResolvedAst = constructorResolvedAsts[index];
1544 ConstructorBodyElement body = getConstructorBody(constructorResolvedAst); 1546 ConstructorBodyElement body = getConstructorBody(constructorResolvedAst);
1545 if (body == null) continue; 1547 if (body == null) continue;
1546 1548
1547 List bodyCallInputs = <HInstruction>[]; 1549 List bodyCallInputs = <HInstruction>[];
1548 if (isNativeUpgradeFactory) { 1550 if (isNativeUpgradeFactory) {
(...skipping 6005 matching lines...) Expand 10 before | Expand all | Expand 10 after
7554 const _LoopTypeVisitor(); 7556 const _LoopTypeVisitor();
7555 int visitNode(ast.Node node) => HLoopBlockInformation.NOT_A_LOOP; 7557 int visitNode(ast.Node node) => HLoopBlockInformation.NOT_A_LOOP;
7556 int visitWhile(ast.While node) => HLoopBlockInformation.WHILE_LOOP; 7558 int visitWhile(ast.While node) => HLoopBlockInformation.WHILE_LOOP;
7557 int visitFor(ast.For node) => HLoopBlockInformation.FOR_LOOP; 7559 int visitFor(ast.For node) => HLoopBlockInformation.FOR_LOOP;
7558 int visitDoWhile(ast.DoWhile node) => HLoopBlockInformation.DO_WHILE_LOOP; 7560 int visitDoWhile(ast.DoWhile node) => HLoopBlockInformation.DO_WHILE_LOOP;
7559 int visitAsyncForIn(ast.AsyncForIn node) => HLoopBlockInformation.FOR_IN_LOOP; 7561 int visitAsyncForIn(ast.AsyncForIn node) => HLoopBlockInformation.FOR_IN_LOOP;
7560 int visitSyncForIn(ast.SyncForIn node) => HLoopBlockInformation.FOR_IN_LOOP; 7562 int visitSyncForIn(ast.SyncForIn node) => HLoopBlockInformation.FOR_IN_LOOP;
7561 int visitSwitchStatement(ast.SwitchStatement node) => 7563 int visitSwitchStatement(ast.SwitchStatement node) =>
7562 HLoopBlockInformation.SWITCH_CONTINUE_LOOP; 7564 HLoopBlockInformation.SWITCH_CONTINUE_LOOP;
7563 } 7565 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js_emitter/startup_emitter/fragment_emitter.dart ('k') | pkg/compiler/lib/src/ssa/codegen.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698