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

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

Issue 1129693006: Fix field initialization order for forwarding constructors. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Status 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 | « pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart ('k') | tests/language/language.status » ('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 part of ssa; 5 part of ssa;
6 6
7 class SsaFunctionCompiler implements FunctionCompiler { 7 class SsaFunctionCompiler implements FunctionCompiler {
8 SsaCodeGeneratorTask generator; 8 SsaCodeGeneratorTask generator;
9 SsaBuilderTask builder; 9 SsaBuilderTask builder;
10 SsaOptimizerTask optimizer; 10 SsaOptimizerTask optimizer;
(...skipping 1809 matching lines...) Expand 10 before | Expand all | Expand 10 after
1820 HInstruction argument = localsHandler.readLocal(parameter); 1820 HInstruction argument = localsHandler.readLocal(parameter);
1821 potentiallyCheckOrTrustType(argument, parameter.type); 1821 potentiallyCheckOrTrustType(argument, parameter.type);
1822 }); 1822 });
1823 } 1823 }
1824 1824
1825 /** 1825 /**
1826 * Documentation wanted -- johnniwinther 1826 * Documentation wanted -- johnniwinther
1827 * 1827 *
1828 * Invariant: [constructors] must contain only implementation elements. 1828 * Invariant: [constructors] must contain only implementation elements.
1829 */ 1829 */
1830 void inlineSuperOrRedirect(FunctionElement callee, 1830 void inlineSuperOrRedirect(ConstructorElement callee,
1831 List<HInstruction> compiledArguments, 1831 List<HInstruction> compiledArguments,
1832 List<FunctionElement> constructors, 1832 List<FunctionElement> constructors,
1833 Map<Element, HInstruction> fieldValues, 1833 Map<Element, HInstruction> fieldValues,
1834 FunctionElement caller) { 1834 FunctionElement caller) {
1835 callee = callee.implementation; 1835 callee = callee.implementation;
1836 compiler.withCurrentElement(callee, () { 1836 compiler.withCurrentElement(callee, () {
1837 constructors.add(callee); 1837 constructors.add(callee);
1838 ClassElement enclosingClass = callee.enclosingClass; 1838 ClassElement enclosingClass = callee.enclosingClass;
1839 if (backend.classNeedsRti(enclosingClass)) { 1839 if (backend.classNeedsRti(enclosingClass)) {
1840 // If [enclosingClass] needs RTI, we have to give a value to its 1840 // If [enclosingClass] needs RTI, we have to give a value to its
(...skipping 21 matching lines...) Expand all
1862 // If the supertype is a raw type, we need to set to null the 1862 // If the supertype is a raw type, we need to set to null the
1863 // type variables. 1863 // type variables.
1864 for (TypeVariableType variable in typeVariables) { 1864 for (TypeVariableType variable in typeVariables) {
1865 localsHandler.updateLocal( 1865 localsHandler.updateLocal(
1866 localsHandler.getTypeVariableAsLocal(variable), 1866 localsHandler.getTypeVariableAsLocal(variable),
1867 graph.addConstantNull(compiler)); 1867 graph.addConstantNull(compiler));
1868 } 1868 }
1869 } 1869 }
1870 } 1870 }
1871 1871
1872 // For redirecting constructors, the fields have already been 1872 // For redirecting constructors, the fields will be initialized later
1873 // initialized by the caller. 1873 // by the effective target.
1874 if (callee.enclosingClass != caller.enclosingClass) { 1874 if (!callee.isRedirectingGenerative) {
1875 inlinedFrom(callee, () { 1875 inlinedFrom(callee, () {
1876 buildFieldInitializers(callee.enclosingElement.implementation, 1876 buildFieldInitializers(callee.enclosingElement.implementation,
1877 fieldValues); 1877 fieldValues);
1878 }); 1878 });
1879 } 1879 }
1880 1880
1881 int index = 0; 1881 int index = 0;
1882 FunctionSignature params = callee.functionSignature; 1882 FunctionSignature params = callee.functionSignature;
1883 params.orderedForEachParameter((ParameterElement parameter) { 1883 params.orderedForEachParameter((ParameterElement parameter) {
1884 HInstruction argument = compiledArguments[index++]; 1884 HInstruction argument = compiledArguments[index++];
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
2067 2067
2068 /** 2068 /**
2069 * Build the factory function corresponding to the constructor 2069 * Build the factory function corresponding to the constructor
2070 * [functionElement]: 2070 * [functionElement]:
2071 * - Initialize fields with the values of the field initializers of the 2071 * - Initialize fields with the values of the field initializers of the
2072 * current constructor and super constructors or constructors redirected 2072 * current constructor and super constructors or constructors redirected
2073 * to, starting from the current constructor. 2073 * to, starting from the current constructor.
2074 * - Call the constructor bodies, starting from the constructor(s) in the 2074 * - Call the constructor bodies, starting from the constructor(s) in the
2075 * super class(es). 2075 * super class(es).
2076 */ 2076 */
2077 HGraph buildFactory(FunctionElement functionElement) { 2077 HGraph buildFactory(ConstructorElement functionElement) {
2078 functionElement = functionElement.implementation; 2078 functionElement = functionElement.implementation;
2079 ClassElement classElement = 2079 ClassElement classElement =
2080 functionElement.enclosingClass.implementation; 2080 functionElement.enclosingClass.implementation;
2081 bool isNativeUpgradeFactory = 2081 bool isNativeUpgradeFactory =
2082 Elements.isNativeOrExtendsNative(classElement); 2082 Elements.isNativeOrExtendsNative(classElement);
2083 ast.FunctionExpression function = functionElement.node; 2083 ast.FunctionExpression function = functionElement.node;
2084 // Note that constructors (like any other static function) do not need 2084 // Note that constructors (like any other static function) do not need
2085 // to deal with optional arguments. It is the callers job to provide all 2085 // to deal with optional arguments. It is the callers job to provide all
2086 // arguments as if they were positional. 2086 // arguments as if they were positional.
2087 2087
2088 if (inliningStack.isEmpty) { 2088 if (inliningStack.isEmpty) {
2089 // The initializer list could contain closures. 2089 // The initializer list could contain closures.
2090 openFunction(functionElement, function); 2090 openFunction(functionElement, function);
2091 } 2091 }
2092 2092
2093 Map<Element, HInstruction> fieldValues = new Map<Element, HInstruction>(); 2093 Map<Element, HInstruction> fieldValues = new Map<Element, HInstruction>();
2094 2094
2095 // Compile the possible initialization code for local fields and 2095 // Compile the possible initialization code for local fields and
2096 // super fields. 2096 // super fields, unless this is a redirecting constructor, in which case
2097 buildFieldInitializers(classElement, fieldValues); 2097 // the effective target will initialize these.
2098 if (!functionElement.isRedirectingGenerative) {
2099 buildFieldInitializers(classElement, fieldValues);
2100 }
2098 2101
2099 // Compile field-parameters such as [:this.x:]. 2102 // Compile field-parameters such as [:this.x:].
2100 FunctionSignature params = functionElement.functionSignature; 2103 FunctionSignature params = functionElement.functionSignature;
2101 params.orderedForEachParameter((ParameterElement parameter) { 2104 params.orderedForEachParameter((ParameterElement parameter) {
2102 if (parameter.isInitializingFormal) { 2105 if (parameter.isInitializingFormal) {
2103 // If the [element] is a field-parameter then 2106 // If the [element] is a field-parameter then
2104 // initialize the field element with its value. 2107 // initialize the field element with its value.
2105 InitializingFormalElement fieldParameter = parameter; 2108 InitializingFormalElement fieldParameter = parameter;
2106 HInstruction parameterValue = 2109 HInstruction parameterValue =
2107 localsHandler.readLocal(fieldParameter); 2110 localsHandler.readLocal(fieldParameter);
(...skipping 5552 matching lines...) Expand 10 before | Expand all | Expand 10 after
7660 if (unaliased is TypedefType) throw 'unable to unalias $type'; 7663 if (unaliased is TypedefType) throw 'unable to unalias $type';
7661 unaliased.accept(this, builder); 7664 unaliased.accept(this, builder);
7662 } 7665 }
7663 7666
7664 void visitDynamicType(DynamicType type, SsaBuilder builder) { 7667 void visitDynamicType(DynamicType type, SsaBuilder builder) {
7665 JavaScriptBackend backend = builder.compiler.backend; 7668 JavaScriptBackend backend = builder.compiler.backend;
7666 ClassElement cls = backend.findHelper('DynamicRuntimeType'); 7669 ClassElement cls = backend.findHelper('DynamicRuntimeType');
7667 builder.push(new HDynamicType(type, new TypeMask.exact(cls, classWorld))); 7670 builder.push(new HDynamicType(type, new TypeMask.exact(cls, classWorld)));
7668 } 7671 }
7669 } 7672 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart ('k') | tests/language/language.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698