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

Side by Side Diff: pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart

Issue 1011403003: cps-ir: Set runtime type information for new objects that require it. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 library dart2js.ir_builder_task; 5 library dart2js.ir_builder_task;
6 6
7 import '../closure.dart' as closurelib; 7 import '../closure.dart' as closurelib;
8 import '../closure.dart' hide ClosureScope; 8 import '../closure.dart' hide ClosureScope;
9 import '../constants/expressions.dart'; 9 import '../constants/expressions.dart';
10 import '../dart_types.dart'; 10 import '../dart_types.dart';
(...skipping 1265 matching lines...) Expand 10 before | Expand all | Expand 10 after
1276 @override 1276 @override
1277 ir.Primitive buildReifyTypeVariable(ir.Primitive target, 1277 ir.Primitive buildReifyTypeVariable(ir.Primitive target,
1278 TypeVariableType variable) { 1278 TypeVariableType variable) {
1279 assert(target is ir.This); 1279 assert(target is ir.This);
1280 ir.Primitive prim = new ir.ReifyTypeVar(variable.element); 1280 ir.Primitive prim = new ir.ReifyTypeVar(variable.element);
1281 irBuilder.add(new ir.LetPrim(prim)); 1281 irBuilder.add(new ir.LetPrim(prim));
1282 return prim; 1282 return prim;
1283 } 1283 }
1284 } 1284 }
1285 1285
1286 /// The [IrBuilder]s view on the information about the program that has been
1287 /// computed in resolution and and type interence.
1288 class GlobalProgramInformation {
1289 final Compiler _compiler;
1290 JavaScriptBackend get _backend => _compiler.backend;
1291
1292 GlobalProgramInformation(this._compiler);
1293
1294 /// Returns [true], if the analysis could not determine that the type
1295 /// arguments for the class [cls] are never used in the program.
1296 bool requiresRuntimeTypesFor(ClassElement cls) => _backend.classNeedsRti(cls);
1297 }
1298
1286 /// IR builder specific to the JavaScript backend, coupled to the [JsIrBuilder]. 1299 /// IR builder specific to the JavaScript backend, coupled to the [JsIrBuilder].
1287 class JsIrBuilderVisitor extends IrBuilderVisitor { 1300 class JsIrBuilderVisitor extends IrBuilderVisitor {
1288 /// Promote the type of [irBuilder] to [JsIrBuilder]. 1301 /// Promote the type of [irBuilder] to [JsIrBuilder].
1289 JsIrBuilder get irBuilder => super.irBuilder; 1302 JsIrBuilder get irBuilder => super.irBuilder;
1290 1303
1291 /// Result of closure conversion for the current body of code. 1304 /// Result of closure conversion for the current body of code.
1292 /// 1305 ///
1293 /// Will be initialized upon entering the body of a function. 1306 /// Will be initialized upon entering the body of a function.
1294 /// It is computed by the [ClosureTranslator]. 1307 /// It is computed by the [ClosureTranslator].
1295 ClosureClassMap closureMap; 1308 ClosureClassMap closureMap;
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
1421 /// Such constants need to be compiled with a different [sourceFile] and 1434 /// Such constants need to be compiled with a different [sourceFile] and
1422 /// [elements] mapping. 1435 /// [elements] mapping.
1423 ir.Primitive inlineConstant(AstElement context, ast.Expression exp) { 1436 ir.Primitive inlineConstant(AstElement context, ast.Expression exp) {
1424 JsIrBuilderVisitor visitor = new JsIrBuilderVisitor( 1437 JsIrBuilderVisitor visitor = new JsIrBuilderVisitor(
1425 context.resolvedAst.elements, 1438 context.resolvedAst.elements,
1426 compiler, 1439 compiler,
1427 sourceInformationBuilder.forContext(context)); 1440 sourceInformationBuilder.forContext(context));
1428 return visitor.withBuilder(irBuilder, () => visitor.translateConstant(exp)); 1441 return visitor.withBuilder(irBuilder, () => visitor.translateConstant(exp));
1429 } 1442 }
1430 1443
1444 JsIrBuilder getBuilderFor(Element element) {
1445 return new JsIrBuilder(
1446 new GlobalProgramInformation(compiler),
1447 compiler.backend.constantSystem,
1448 element);
1449 }
1450
1431 /// Builds the IR for a given constructor. 1451 /// Builds the IR for a given constructor.
1432 /// 1452 ///
1433 /// 1. Evaluates all own or inherited field initializers. 1453 /// 1. Evaluates all own or inherited field initializers.
1434 /// 2. Creates the object and assigns its fields. 1454 /// 2. Creates the object and assigns its fields.
1435 /// 3. Calls constructor body and super constructor bodies. 1455 /// 3. Calls constructor body and super constructor bodies.
1436 /// 4. Returns the created object. 1456 /// 4. Returns the created object.
1437 ir.FunctionDefinition buildConstructor(ConstructorElement constructor) { 1457 ir.FunctionDefinition buildConstructor(ConstructorElement constructor) {
1438 constructor = constructor.implementation; 1458 constructor = constructor.implementation;
1439 ClassElement classElement = constructor.enclosingClass.implementation; 1459 ClassElement classElement = constructor.enclosingClass.implementation;
1440 1460
1441 JsIrBuilder builder = 1461 JsIrBuilder builder = getBuilderFor(constructor);
1442 new JsIrBuilder(compiler.backend.constantSystem, constructor);
1443 1462
1444 return withBuilder(builder, () { 1463 return withBuilder(builder, () {
1445 // Setup parameters and create a box if anything is captured. 1464 // Setup parameters and create a box if anything is captured.
1446 List<ParameterElement> parameters = []; 1465 List<ParameterElement> parameters = [];
1447 constructor.functionSignature.orderedForEachParameter(parameters.add); 1466 constructor.functionSignature.orderedForEachParameter(parameters.add);
1448 builder.buildFunctionHeader(parameters, 1467 builder.buildFunctionHeader(parameters,
1449 closureScope: getClosureScopeForFunction(constructor)); 1468 closureScope: getClosureScopeForFunction(constructor));
1450 1469
1451 // -- Step 1: evaluate field initializers --- 1470 // -- Step 1: evaluate field initializers ---
1452 // Evaluate field initializers in constructor and super constructors. 1471 // Evaluate field initializers in constructor and super constructors.
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
1697 /// This function is invoked from one or more "factory" constructors built by 1716 /// This function is invoked from one or more "factory" constructors built by
1698 /// [buildConstructor]. 1717 /// [buildConstructor].
1699 ir.FunctionDefinition buildConstructorBody(ConstructorBodyElement body) { 1718 ir.FunctionDefinition buildConstructorBody(ConstructorBodyElement body) {
1700 ConstructorElement constructor = body.constructor; 1719 ConstructorElement constructor = body.constructor;
1701 ast.FunctionExpression node = constructor.node; 1720 ast.FunctionExpression node = constructor.node;
1702 closureMap = compiler.closureToClassMapper.computeClosureToClassMapping( 1721 closureMap = compiler.closureToClassMapper.computeClosureToClassMapping(
1703 constructor, 1722 constructor,
1704 node, 1723 node,
1705 elements); 1724 elements);
1706 1725
1707 JsIrBuilder builder = 1726 JsIrBuilder builder = getBuilderFor(body);
1708 new JsIrBuilder(compiler.backend.constantSystem, body);
1709 1727
1710 return withBuilder(builder, () { 1728 return withBuilder(builder, () {
1711 irBuilder.buildConstructorBodyHeader(getConstructorBodyParameters(body), 1729 irBuilder.buildConstructorBodyHeader(getConstructorBodyParameters(body),
1712 getClosureScopeForNode(node)); 1730 getClosureScopeForNode(node));
1713 visit(node.body); 1731 visit(node.body);
1714 return irBuilder.makeFunctionDefinition([]); 1732 return irBuilder.makeFunctionDefinition([]);
1715 }); 1733 });
1716 } 1734 }
1717 1735
1718 ir.FunctionDefinition buildFunction(FunctionElement element) { 1736 ir.FunctionDefinition buildFunction(FunctionElement element) {
1719 assert(invariant(element, element.isImplementation)); 1737 assert(invariant(element, element.isImplementation));
1720 ast.FunctionExpression node = element.node; 1738 ast.FunctionExpression node = element.node;
1721 1739
1722 assert(!element.isSynthesized); 1740 assert(!element.isSynthesized);
1723 assert(node != null); 1741 assert(node != null);
1724 assert(elements[node] != null); 1742 assert(elements[node] != null);
1725 1743
1726 closureMap = compiler.closureToClassMapper.computeClosureToClassMapping( 1744 closureMap = compiler.closureToClassMapper.computeClosureToClassMapping(
1727 element, 1745 element,
1728 node, 1746 node,
1729 elements); 1747 elements);
1730 IrBuilder builder = 1748 IrBuilder builder = getBuilderFor(element);
1731 new JsIrBuilder(compiler.backend.constantSystem, element);
1732 return withBuilder(builder, () => _makeFunctionBody(element, node)); 1749 return withBuilder(builder, () => _makeFunctionBody(element, node));
1733 } 1750 }
1734 1751
1735 /// Creates a primitive for the default value of [parameter]. 1752 /// Creates a primitive for the default value of [parameter].
1736 ir.Primitive translateDefaultValue(ParameterElement parameter) { 1753 ir.Primitive translateDefaultValue(ParameterElement parameter) {
1737 if (parameter.initializer == null) { 1754 if (parameter.initializer == null) {
1738 return irBuilder.buildNullLiteral(); 1755 return irBuilder.buildNullLiteral();
1739 } else { 1756 } else {
1740 return inlineConstant(parameter.executableContext, parameter.initializer); 1757 return inlineConstant(parameter.executableContext, parameter.initializer);
1741 } 1758 }
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
1851 SourceInformation buildCall(ast.Node node) { 1868 SourceInformation buildCall(ast.Node node) {
1852 return new PositionSourceInformation( 1869 return new PositionSourceInformation(
1853 new TokenSourceLocation(sourceFile, node.getBeginToken(), name)); 1870 new TokenSourceLocation(sourceFile, node.getBeginToken(), name));
1854 } 1871 }
1855 1872
1856 @override 1873 @override
1857 SourceInformationBuilder forContext(AstElement element) { 1874 SourceInformationBuilder forContext(AstElement element) {
1858 return new PositionSourceInformationBuilder(element); 1875 return new PositionSourceInformationBuilder(element);
1859 } 1876 }
1860 } 1877 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698