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

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

Issue 1129693006: Fix field initialization order for forwarding constructors. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 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 | « no previous file | pkg/compiler/lib/src/ssa/builder.dart » ('j') | tests/language/language.status » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 3177 matching lines...) Expand 10 before | Expand all | Expand 10 after
3188 element); 3188 element);
3189 } 3189 }
3190 3190
3191 /// Builds the IR for a given constructor. 3191 /// Builds the IR for a given constructor.
3192 /// 3192 ///
3193 /// 1. Evaluates all own or inherited field initializers. 3193 /// 1. Evaluates all own or inherited field initializers.
3194 /// 2. Creates the object and assigns its fields. 3194 /// 2. Creates the object and assigns its fields.
3195 /// 3. Calls constructor body and super constructor bodies. 3195 /// 3. Calls constructor body and super constructor bodies.
3196 /// 4. Returns the created object. 3196 /// 4. Returns the created object.
3197 ir.FunctionDefinition buildConstructor(ConstructorElement constructor) { 3197 ir.FunctionDefinition buildConstructor(ConstructorElement constructor) {
3198 // TODO(asgerf): Optimization: If constructor is redirecting, then just
3199 // evaluate arguments and call the target constructor.
3198 constructor = constructor.implementation; 3200 constructor = constructor.implementation;
3199 ClassElement classElement = constructor.enclosingClass.implementation; 3201 ClassElement classElement = constructor.enclosingClass.implementation;
3200 3202
3201 JsIrBuilder builder = getBuilderFor(constructor); 3203 JsIrBuilder builder = getBuilderFor(constructor);
3202 3204
3203 final bool requiresTypeInformation = 3205 final bool requiresTypeInformation =
3204 builder.program.requiresRuntimeTypesFor(classElement); 3206 builder.program.requiresRuntimeTypesFor(classElement);
3205 3207
3206 return withBuilder(builder, () { 3208 return withBuilder(builder, () {
3207 // Setup parameters and create a box if anything is captured. 3209 // Setup parameters and create a box if anything is captured.
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
3288 /// 3290 ///
3289 /// This procedure assumes that the parameters to [constructor] are available 3291 /// This procedure assumes that the parameters to [constructor] are available
3290 /// in the IR builder's environment. 3292 /// in the IR builder's environment.
3291 /// 3293 ///
3292 /// The parameters to superconstructors are, however, assumed *not* to be in 3294 /// The parameters to superconstructors are, however, assumed *not* to be in
3293 /// the environment, but will be put there by this procedure. 3295 /// the environment, but will be put there by this procedure.
3294 /// 3296 ///
3295 /// All constructors will be added to [supers], with superconstructors first. 3297 /// All constructors will be added to [supers], with superconstructors first.
3296 void evaluateConstructorFieldInitializers(ConstructorElement constructor, 3298 void evaluateConstructorFieldInitializers(ConstructorElement constructor,
3297 List<ConstructorElement> supers) { 3299 List<ConstructorElement> supers) {
3298 // Evaluate declaration-site field initializers.
3299 ClassElement enclosingClass = constructor.enclosingClass.implementation; 3300 ClassElement enclosingClass = constructor.enclosingClass.implementation;
3300 enclosingClass.forEachInstanceField((ClassElement c, FieldElement field) { 3301 // Evaluate declaration-site field initializers, unless this constructor
3301 if (field.initializer != null) { 3302 // redirects to another using a `this()` initializer. In that case, these
3302 fieldValues[field] = inlineExpression(field, field.initializer); 3303 // will be initialized by the effective target constructor.
3303 } else { 3304 if (!constructor.isRedirectingGenerative) {
3304 if (Elements.isNativeOrExtendsNative(c)) { 3305 enclosingClass.forEachInstanceField((ClassElement c, FieldElement field) {
3305 // Native field is initialized elsewhere. 3306 if (field.initializer != null) {
3307 fieldValues[field] = inlineExpression(field, field.initializer);
3306 } else { 3308 } else {
3307 // Fields without an initializer default to null. 3309 if (Elements.isNativeOrExtendsNative(c)) {
3308 // This value will be overwritten below if an initializer is found. 3310 // Native field is initialized elsewhere.
3309 fieldValues[field] = irBuilder.buildNullConstant(); 3311 } else {
3312 // Fields without an initializer default to null.
3313 // This value will be overwritten below if an initializer is found.
3314 fieldValues[field] = irBuilder.buildNullConstant();
3315 }
3310 } 3316 }
3311 } 3317 });
3312 }); 3318 }
3313 // Evaluate initializing parameters, e.g. `Foo(this.x)`. 3319 // Evaluate initializing parameters, e.g. `Foo(this.x)`.
3314 constructor.functionSignature.orderedForEachParameter( 3320 constructor.functionSignature.orderedForEachParameter(
3315 (ParameterElement parameter) { 3321 (ParameterElement parameter) {
3316 if (parameter.isInitializingFormal) { 3322 if (parameter.isInitializingFormal) {
3317 InitializingFormalElement fieldParameter = parameter; 3323 InitializingFormalElement fieldParameter = parameter;
3318 fieldValues[fieldParameter.fieldElement] = 3324 fieldValues[fieldParameter.fieldElement] =
3319 irBuilder.buildLocalVariableGet(parameter); 3325 irBuilder.buildLocalVariableGet(parameter);
3320 } 3326 }
3321 }); 3327 });
3322 // Evaluate constructor initializers, e.g. `Foo() : x = 50`. 3328 // Evaluate constructor initializers, e.g. `Foo() : x = 50`.
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
3757 node.body = replacementFor(node.body); 3763 node.body = replacementFor(node.body);
3758 } 3764 }
3759 } 3765 }
3760 3766
3761 /// Visit a just-deleted subterm and unlink all [Reference]s in it. 3767 /// Visit a just-deleted subterm and unlink all [Reference]s in it.
3762 class RemovalVisitor extends ir.RecursiveVisitor { 3768 class RemovalVisitor extends ir.RecursiveVisitor {
3763 processReference(ir.Reference reference) { 3769 processReference(ir.Reference reference) {
3764 reference.unlink(); 3770 reference.unlink();
3765 } 3771 }
3766 } 3772 }
OLDNEW
« no previous file with comments | « no previous file | pkg/compiler/lib/src/ssa/builder.dart » ('j') | tests/language/language.status » ('J')

Powered by Google App Engine
This is Rietveld 408576698