OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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.cps_ir.shrinking_reductions; | 5 library dart2js.cps_ir.shrinking_reductions; |
6 | 6 |
7 import 'cps_ir_nodes.dart'; | 7 import 'cps_ir_nodes.dart'; |
8 import 'optimizers.dart'; | 8 import 'optimizers.dart'; |
9 | 9 |
10 /** | 10 /** |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 return false; | 271 return false; |
272 } | 272 } |
273 | 273 |
274 if (cont.firstRef.parent is! InvokeContinuation) return false; | 274 if (cont.firstRef.parent is! InvokeContinuation) return false; |
275 | 275 |
276 InvokeContinuation invoke = cont.firstRef.parent; | 276 InvokeContinuation invoke = cont.firstRef.parent; |
277 if (cont != invoke.continuation.definition) return false; | 277 if (cont != invoke.continuation.definition) return false; |
278 | 278 |
279 // Beta-reduction will move the continuation's body to its unique invocation | 279 // Beta-reduction will move the continuation's body to its unique invocation |
280 // site. This is not safe if the body is moved into an exception handler | 280 // site. This is not safe if the body is moved into an exception handler |
281 // binding. | 281 // binding. Search from the invocation to the continuation binding to |
| 282 // make sure that there is no binding for a handler. |
282 Node current = invoke.parent; | 283 Node current = invoke.parent; |
283 while (current != cont.parent) { | 284 while (current != cont.parent) { |
| 285 // There is no need to reduce a beta-redex inside a deleted subterm. |
| 286 if (current == ShrinkingReducer._DELETED) return false; |
284 if (current is LetHandler) return false; | 287 if (current is LetHandler) return false; |
285 current = current.parent; | 288 current = current.parent; |
286 } | 289 } |
287 return true; | 290 return true; |
288 } | 291 } |
289 | 292 |
290 /// Returns true iff the continuation consists of a continuation | 293 /// Returns true iff the continuation consists of a continuation |
291 /// invocation, passing on all parameters. Special cases exist (see below). | 294 /// invocation, passing on all parameters. Special cases exist (see below). |
292 bool _isEtaCont(Continuation cont) { | 295 bool _isEtaCont(Continuation cont) { |
293 if (cont.isReturnContinuation || cont.body is! InvokeContinuation) { | 296 if (cont.isReturnContinuation || cont.body is! InvokeContinuation) { |
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
722 } | 725 } |
723 | 726 |
724 String toString() => "$kind: $node"; | 727 String toString() => "$kind: $node"; |
725 } | 728 } |
726 | 729 |
727 /// A dummy class used solely to mark nodes as deleted once they are removed | 730 /// A dummy class used solely to mark nodes as deleted once they are removed |
728 /// from a term. | 731 /// from a term. |
729 class _DeletedNode extends Node { | 732 class _DeletedNode extends Node { |
730 accept(_) => null; | 733 accept(_) => null; |
731 } | 734 } |
OLD | NEW |