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

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

Issue 2615173002: Revert "Ensure we're looking at the correct resolved AST when initializing fields in constructors." (Closed)
Patch Set: Created 3 years, 11 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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 'package:kernel/ast.dart' as ir; 5 import 'package:kernel/ast.dart' as ir;
6 6
7 import '../closure.dart'; 7 import '../closure.dart';
8 import '../common.dart'; 8 import '../common.dart';
9 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem; 9 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem;
10 import '../common/names.dart'; 10 import '../common/names.dart';
11 import '../common/tasks.dart' show CompilerTask; 11 import '../common/tasks.dart' show CompilerTask;
12 import '../compiler.dart'; 12 import '../compiler.dart';
13 import '../constants/values.dart' 13 import '../constants/values.dart'
14 show 14 show
15 ConstantValue, 15 ConstantValue,
16 InterceptorConstantValue, 16 InterceptorConstantValue,
17 StringConstantValue, 17 StringConstantValue,
18 TypeConstantValue; 18 TypeConstantValue;
19 import '../elements/resolution_types.dart'; 19 import '../elements/resolution_types.dart';
20 import '../elements/elements.dart'; 20 import '../elements/elements.dart';
21 import '../io/source_information.dart'; 21 import '../io/source_information.dart';
22 import '../js/js.dart' as js; 22 import '../js/js.dart' as js;
23 import '../js_backend/backend.dart' show JavaScriptBackend; 23 import '../js_backend/backend.dart' show JavaScriptBackend;
24 import '../kernel/kernel.dart'; 24 import '../kernel/kernel.dart';
25 import '../native/native.dart' as native; 25 import '../native/native.dart' as native;
26 import '../resolution/tree_elements.dart';
26 import '../tree/dartstring.dart'; 27 import '../tree/dartstring.dart';
27 import '../tree/nodes.dart' show Node, BreakStatement; 28 import '../tree/nodes.dart' show Node, BreakStatement;
28 import '../types/masks.dart'; 29 import '../types/masks.dart';
29 import '../universe/call_structure.dart' show CallStructure; 30 import '../universe/call_structure.dart' show CallStructure;
30 import '../universe/selector.dart'; 31 import '../universe/selector.dart';
31 import '../universe/side_effects.dart' show SideEffects; 32 import '../universe/side_effects.dart' show SideEffects;
32 import '../universe/use.dart' show StaticUse; 33 import '../universe/use.dart' show StaticUse;
33 import '../world.dart'; 34 import '../world.dart';
34 import 'graph_builder.dart'; 35 import 'graph_builder.dart';
35 import 'jump_handler.dart'; 36 import 'jump_handler.dart';
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 // TODO(karlklose): consider removing this and keeping the (substituted) types 108 // TODO(karlklose): consider removing this and keeping the (substituted) types
108 // of the type variables in an environment (like the [LocalsHandler]). 109 // of the type variables in an environment (like the [LocalsHandler]).
109 final List<ResolutionDartType> currentImplicitInstantiations = 110 final List<ResolutionDartType> currentImplicitInstantiations =
110 <ResolutionDartType>[]; 111 <ResolutionDartType>[];
111 112
112 HInstruction rethrowableException; 113 HInstruction rethrowableException;
113 114
114 @override 115 @override
115 JavaScriptBackend get backend => compiler.backend; 116 JavaScriptBackend get backend => compiler.backend;
116 117
118 @override
119 TreeElements get elements => resolvedAst.elements;
120
117 SourceInformationBuilder sourceInformationBuilder; 121 SourceInformationBuilder sourceInformationBuilder;
118 KernelAstAdapter astAdapter; 122 KernelAstAdapter astAdapter;
119 LoopHandler<ir.Node> loopHandler; 123 LoopHandler<ir.Node> loopHandler;
120 TypeBuilder typeBuilder; 124 TypeBuilder typeBuilder;
121 125
122 final Map<ir.VariableDeclaration, HInstruction> letBindings = 126 final Map<ir.VariableDeclaration, HInstruction> letBindings =
123 <ir.VariableDeclaration, HInstruction>{}; 127 <ir.VariableDeclaration, HInstruction>{};
124 128
125 /// True if we are visiting the expression of a throw statement; we assume 129 /// True if we are visiting the expression of a throw statement; we assume
126 /// this is a slow path. 130 /// this is a slow path.
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 } 291 }
288 292
289 /// Maps the fields of a class to their SSA values. 293 /// Maps the fields of a class to their SSA values.
290 Map<ir.Field, HInstruction> _collectFieldValues(ir.Class clazz) { 294 Map<ir.Field, HInstruction> _collectFieldValues(ir.Class clazz) {
291 final fieldValues = <ir.Field, HInstruction>{}; 295 final fieldValues = <ir.Field, HInstruction>{};
292 296
293 for (var field in clazz.fields) { 297 for (var field in clazz.fields) {
294 if (field.initializer == null) { 298 if (field.initializer == null) {
295 fieldValues[field] = graph.addConstantNull(closedWorld); 299 fieldValues[field] = graph.addConstantNull(closedWorld);
296 } else { 300 } else {
297 // Gotta update the resolvedAst when we're looking at field values
298 // outside the constructor.
299 astAdapter.pushResolvedAst(field);
300 field.initializer.accept(this); 301 field.initializer.accept(this);
301 fieldValues[field] = pop(); 302 fieldValues[field] = pop();
302 astAdapter.popResolvedAstStack();
303 } 303 }
304 } 304 }
305 305
306 return fieldValues; 306 return fieldValues;
307 } 307 }
308 308
309 /// Collects field initializers all the way up the inheritance chain. 309 /// Collects field initializers all the way up the inheritance chain.
310 void _buildInitializers( 310 void _buildInitializers(
311 ir.Constructor constructor, Map<ir.Field, HInstruction> fieldValues) { 311 ir.Constructor constructor, Map<ir.Field, HInstruction> fieldValues) {
312 var foundSuperOrRedirectCall = false; 312 var foundSuperOrRedirectCall = false;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 assert(invariant(element, constantValue != null, 379 assert(invariant(element, constantValue != null,
380 message: 'No constant computed for $element')); 380 message: 'No constant computed for $element'));
381 builtArguments.add(graph.addConstant(constantValue, closedWorld)); 381 builtArguments.add(graph.addConstant(constantValue, closedWorld));
382 } 382 }
383 }); 383 });
384 } 384 }
385 385
386 return builtArguments; 386 return builtArguments;
387 } 387 }
388 388
389 /// Inlines the given super [constructor]'s initializers by collecting its 389 /// Inlines the given super [constructor]'s initializers by collecting it's
390 /// field values and building its constructor initializers. We visit super 390 /// field values and building its constructor initializers. We visit super
391 /// constructors all the way up to the [Object] constructor. 391 /// constructors all the way up to the [Object] constructor.
392 void _buildInlinedInitializers(ir.Constructor constructor, 392 void _buildInlinedInitializers(ir.Constructor constructor,
393 List<HInstruction> arguments, Map<ir.Field, HInstruction> fieldValues) { 393 List<HInstruction> arguments, Map<ir.Field, HInstruction> fieldValues) {
394 // TODO(het): Handle RTI if class needs it 394 // TODO(het): Handle RTI if class needs it
395 fieldValues.addAll(_collectFieldValues(constructor.enclosingClass)); 395 fieldValues.addAll(_collectFieldValues(constructor.enclosingClass));
396 396
397 var signature = astAdapter.getFunctionSignature(constructor.function); 397 var signature = astAdapter.getFunctionSignature(constructor.function);
398 var index = 0; 398 var index = 0;
399 signature.orderedForEachParameter((ParameterElement parameter) { 399 signature.orderedForEachParameter((ParameterElement parameter) {
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 @override 786 @override
787 visitDoStatement(ir.DoStatement doStatement) { 787 visitDoStatement(ir.DoStatement doStatement) {
788 // TODO(efortuna): I think this can be rewritten using 788 // TODO(efortuna): I think this can be rewritten using
789 // LoopHandler.handleLoop with some tricks about when the "update" happens. 789 // LoopHandler.handleLoop with some tricks about when the "update" happens.
790 LocalsHandler savedLocals = new LocalsHandler.from(localsHandler); 790 LocalsHandler savedLocals = new LocalsHandler.from(localsHandler);
791 localsHandler.startLoop(astAdapter.getNode(doStatement)); 791 localsHandler.startLoop(astAdapter.getNode(doStatement));
792 JumpHandler jumpHandler = loopHandler.beginLoopHeader(doStatement); 792 JumpHandler jumpHandler = loopHandler.beginLoopHeader(doStatement);
793 HLoopInformation loopInfo = current.loopInformation; 793 HLoopInformation loopInfo = current.loopInformation;
794 HBasicBlock loopEntryBlock = current; 794 HBasicBlock loopEntryBlock = current;
795 HBasicBlock bodyEntryBlock = current; 795 HBasicBlock bodyEntryBlock = current;
796 JumpTarget target = astAdapter.elements 796 JumpTarget target =
797 .getTargetDefinition(astAdapter.getNode(doStatement)); 797 elements.getTargetDefinition(astAdapter.getNode(doStatement));
798 bool hasContinues = target != null && target.isContinueTarget; 798 bool hasContinues = target != null && target.isContinueTarget;
799 if (hasContinues) { 799 if (hasContinues) {
800 // Add extra block to hang labels on. 800 // Add extra block to hang labels on.
801 // It doesn't currently work if they are on the same block as the 801 // It doesn't currently work if they are on the same block as the
802 // HLoopInfo. The handling of HLabeledBlockInformation will visit a 802 // HLoopInfo. The handling of HLabeledBlockInformation will visit a
803 // SubGraph that starts at the same block again, so the HLoopInfo is 803 // SubGraph that starts at the same block again, so the HLoopInfo is
804 // either handled twice, or it's handled after the labeled block info, 804 // either handled twice, or it's handled after the labeled block info,
805 // both of which generate the wrong code. 805 // both of which generate the wrong code.
806 // Using a separate block is just a simple workaround. 806 // Using a separate block is just a simple workaround.
807 bodyEntryBlock = openNewBlock(); 807 bodyEntryBlock = openNewBlock();
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
899 loopEntryBlock.loopInformation = null; 899 loopEntryBlock.loopInformation = null;
900 900
901 if (jumpHandler.hasAnyBreak()) { 901 if (jumpHandler.hasAnyBreak()) {
902 // Null branchBlock because the body of the do-while loop always aborts, 902 // Null branchBlock because the body of the do-while loop always aborts,
903 // so we never get to the condition. 903 // so we never get to the condition.
904 loopHandler.endLoop(loopEntryBlock, null, jumpHandler, localsHandler); 904 loopHandler.endLoop(loopEntryBlock, null, jumpHandler, localsHandler);
905 905
906 // Since the body of the loop has a break, we attach a synthesized label 906 // Since the body of the loop has a break, we attach a synthesized label
907 // to the body. 907 // to the body.
908 SubGraph bodyGraph = new SubGraph(bodyEntryBlock, bodyExitBlock); 908 SubGraph bodyGraph = new SubGraph(bodyEntryBlock, bodyExitBlock);
909 JumpTarget target = astAdapter.elements 909 JumpTarget target =
910 .getTargetDefinition(astAdapter.getNode(doStatement)); 910 elements.getTargetDefinition(astAdapter.getNode(doStatement));
911 LabelDefinition label = target.addLabel(null, 'loop'); 911 LabelDefinition label = target.addLabel(null, 'loop');
912 label.setBreakTarget(); 912 label.setBreakTarget();
913 HLabeledBlockInformation info = new HLabeledBlockInformation( 913 HLabeledBlockInformation info = new HLabeledBlockInformation(
914 new HSubGraphBlockInformation(bodyGraph), <LabelDefinition>[label]); 914 new HSubGraphBlockInformation(bodyGraph), <LabelDefinition>[label]);
915 loopEntryBlock.setBlockFlow(info, current); 915 loopEntryBlock.setBlockFlow(info, current);
916 jumpHandler.forEachBreak((HBreak breakInstruction, _) { 916 jumpHandler.forEachBreak((HBreak breakInstruction, _) {
917 HBasicBlock block = breakInstruction.block; 917 HBasicBlock block = breakInstruction.block;
918 block.addAtExit(new HBreak.toLabel(label)); 918 block.addAtExit(new HBreak.toLabel(label));
919 block.remove(breakInstruction); 919 block.remove(breakInstruction);
920 }); 920 });
(...skipping 1559 matching lines...) Expand 10 before | Expand all | Expand 10 after
2480 kernelBuilder.open(exitBlock); 2480 kernelBuilder.open(exitBlock);
2481 enterBlock.setBlockFlow( 2481 enterBlock.setBlockFlow(
2482 new HTryBlockInformation( 2482 new HTryBlockInformation(
2483 kernelBuilder.wrapStatementGraph(bodyGraph), 2483 kernelBuilder.wrapStatementGraph(bodyGraph),
2484 exception, 2484 exception,
2485 kernelBuilder.wrapStatementGraph(catchGraph), 2485 kernelBuilder.wrapStatementGraph(catchGraph),
2486 kernelBuilder.wrapStatementGraph(finallyGraph)), 2486 kernelBuilder.wrapStatementGraph(finallyGraph)),
2487 exitBlock); 2487 exitBlock);
2488 } 2488 }
2489 } 2489 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/resolved_uri_translator.dart ('k') | pkg/compiler/lib/src/ssa/graph_builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698