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

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

Issue 1919143002: Store constant variable initializers in elements. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Updated cf. comments. Created 4 years, 7 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
« no previous file with comments | « pkg/compiler/lib/src/serialization/modelz.dart ('k') | pkg/compiler/lib/src/typechecker.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 HGraph graph = builder.build(); 116 HGraph graph = builder.build();
117 117
118 // Default arguments are handled elsewhere, but we must ensure 118 // Default arguments are handled elsewhere, but we must ensure
119 // that the default values are computed during codegen. 119 // that the default values are computed during codegen.
120 if (!identical(element.kind, ElementKind.FIELD)) { 120 if (!identical(element.kind, ElementKind.FIELD)) {
121 FunctionElement function = element; 121 FunctionElement function = element;
122 FunctionSignature signature = function.functionSignature; 122 FunctionSignature signature = function.functionSignature;
123 signature.forEachOptionalParameter((ParameterElement parameter) { 123 signature.forEachOptionalParameter((ParameterElement parameter) {
124 // This ensures the default value will be computed. 124 // This ensures the default value will be computed.
125 ConstantValue constant = 125 ConstantValue constant =
126 backend.constants.getConstantValueForVariable(parameter); 126 backend.constants.getConstantValue(parameter.constant);
127 work.registry.registerCompileTimeConstant(constant); 127 work.registry.registerCompileTimeConstant(constant);
128 }); 128 });
129 } 129 }
130 if (compiler.tracer.isEnabled) { 130 if (compiler.tracer.isEnabled) {
131 String name; 131 String name;
132 if (element.isClassMember) { 132 if (element.isClassMember) {
133 String className = element.enclosingClass.name; 133 String className = element.enclosingClass.name;
134 String memberName = element.name; 134 String memberName = element.name;
135 name = "$className.$memberName"; 135 name = "$className.$memberName";
136 if (element.isGenerativeConstructorBody) { 136 if (element.isGenerativeConstructorBody) {
(...skipping 1451 matching lines...) Expand 10 before | Expand all | Expand 10 after
1588 }); 1588 });
1589 } 1589 }
1590 1590
1591 /** 1591 /**
1592 * Return null so it is simple to remove the optional parameters completely 1592 * Return null so it is simple to remove the optional parameters completely
1593 * from interop methods to match JavaScript semantics for ommitted arguments. 1593 * from interop methods to match JavaScript semantics for ommitted arguments.
1594 */ 1594 */
1595 HInstruction handleConstantForOptionalParameterJsInterop(Element parameter) => 1595 HInstruction handleConstantForOptionalParameterJsInterop(Element parameter) =>
1596 null; 1596 null;
1597 1597
1598 HInstruction handleConstantForOptionalParameter(Element parameter) { 1598 HInstruction handleConstantForOptionalParameter(ParameterElement parameter) {
1599 ConstantValue constantValue = 1599 ConstantValue constantValue =
1600 backend.constants.getConstantValueForVariable(parameter); 1600 backend.constants.getConstantValue(parameter.constant);
1601 assert(invariant(parameter, constantValue != null, 1601 assert(invariant(parameter, constantValue != null,
1602 message: 'No constant computed for $parameter')); 1602 message: 'No constant computed for $parameter'));
1603 return graph.addConstant(constantValue, compiler); 1603 return graph.addConstant(constantValue, compiler);
1604 } 1604 }
1605 1605
1606 Element get currentNonClosureClass { 1606 Element get currentNonClosureClass {
1607 ClassElement cls = sourceElement.enclosingClass; 1607 ClassElement cls = sourceElement.enclosingClass;
1608 if (cls != null && cls.isClosure) { 1608 if (cls != null && cls.isClosure) {
1609 var closureClass = cls; 1609 var closureClass = cls;
1610 return closureClass.methodElement.enclosingClass; 1610 return closureClass.methodElement.enclosingClass;
(...skipping 1887 matching lines...) Expand 10 before | Expand all | Expand 10 after
3498 } 3498 }
3499 } 3499 }
3500 3500
3501 @override 3501 @override
3502 void previsitDeferredAccess(ast.Send node, PrefixElement prefix, _) { 3502 void previsitDeferredAccess(ast.Send node, PrefixElement prefix, _) {
3503 generateIsDeferredLoadedCheckIfNeeded(prefix, node); 3503 generateIsDeferredLoadedCheckIfNeeded(prefix, node);
3504 } 3504 }
3505 3505
3506 /// Read a static or top level [field]. 3506 /// Read a static or top level [field].
3507 void generateStaticFieldGet(ast.Send node, FieldElement field) { 3507 void generateStaticFieldGet(ast.Send node, FieldElement field) {
3508 ConstantExpression constant = 3508 ConstantExpression constant = field.constant;
3509 backend.constants.getConstantForVariable(field);
3510 SourceInformation sourceInformation = 3509 SourceInformation sourceInformation =
3511 sourceInformationBuilder.buildGet(node); 3510 sourceInformationBuilder.buildGet(node);
3512 if (constant != null) { 3511 if (constant != null) {
3513 if (!field.isAssignable) { 3512 if (!field.isAssignable) {
3514 // A static final or const. Get its constant value and inline it if 3513 // A static final or const. Get its constant value and inline it if
3515 // the value can be compiled eagerly. 3514 // the value can be compiled eagerly.
3516 generateStaticConstGet(node, field, constant, sourceInformation); 3515 generateStaticConstGet(node, field, constant, sourceInformation);
3517 } else { 3516 } else {
3518 // TODO(5346): Try to avoid the need for calling [declaration] before 3517 // TODO(5346): Try to avoid the need for calling [declaration] before
3519 // creating an [HStatic]. 3518 // creating an [HStatic].
(...skipping 5056 matching lines...) Expand 10 before | Expand all | Expand 10 after
8576 const _LoopTypeVisitor(); 8575 const _LoopTypeVisitor();
8577 int visitNode(ast.Node node) => HLoopBlockInformation.NOT_A_LOOP; 8576 int visitNode(ast.Node node) => HLoopBlockInformation.NOT_A_LOOP;
8578 int visitWhile(ast.While node) => HLoopBlockInformation.WHILE_LOOP; 8577 int visitWhile(ast.While node) => HLoopBlockInformation.WHILE_LOOP;
8579 int visitFor(ast.For node) => HLoopBlockInformation.FOR_LOOP; 8578 int visitFor(ast.For node) => HLoopBlockInformation.FOR_LOOP;
8580 int visitDoWhile(ast.DoWhile node) => HLoopBlockInformation.DO_WHILE_LOOP; 8579 int visitDoWhile(ast.DoWhile node) => HLoopBlockInformation.DO_WHILE_LOOP;
8581 int visitAsyncForIn(ast.AsyncForIn node) => HLoopBlockInformation.FOR_IN_LOOP; 8580 int visitAsyncForIn(ast.AsyncForIn node) => HLoopBlockInformation.FOR_IN_LOOP;
8582 int visitSyncForIn(ast.SyncForIn node) => HLoopBlockInformation.FOR_IN_LOOP; 8581 int visitSyncForIn(ast.SyncForIn node) => HLoopBlockInformation.FOR_IN_LOOP;
8583 int visitSwitchStatement(ast.SwitchStatement node) => 8582 int visitSwitchStatement(ast.SwitchStatement node) =>
8584 HLoopBlockInformation.SWITCH_CONTINUE_LOOP; 8583 HLoopBlockInformation.SWITCH_CONTINUE_LOOP;
8585 } 8584 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/serialization/modelz.dart ('k') | pkg/compiler/lib/src/typechecker.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698