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