| Index: pkg/compiler/lib/src/cps_ir/shrinking_reductions.dart
|
| diff --git a/pkg/compiler/lib/src/cps_ir/shrinking_reductions.dart b/pkg/compiler/lib/src/cps_ir/shrinking_reductions.dart
|
| index 6615aa5651e36d4f31715cde6b236958962ccf78..089921bf92b559355e2be941b59bb2516e56111f 100644
|
| --- a/pkg/compiler/lib/src/cps_ir/shrinking_reductions.dart
|
| +++ b/pkg/compiler/lib/src/cps_ir/shrinking_reductions.dart
|
| @@ -46,27 +46,8 @@ class ShrinkingReducer extends PassMixin {
|
| node.parent = _DELETED;
|
| }
|
|
|
| - /// Remove a given continuation from the CPS graph. The LetCont itself is
|
| - /// removed if the given continuation is the only binding.
|
| - void _removeContinuation(Continuation cont) {
|
| - LetCont parent = cont.parent;
|
| - if (parent.continuations.length == 1) {
|
| - assert(cont.parent_index == 0);
|
| - _removeNode(parent);
|
| - } else {
|
| - List<Continuation> continuations = parent.continuations;
|
| - for (int i = cont.parent_index; i < continuations.length - 1; ++i) {
|
| - Continuation current = continuations[i + 1];
|
| - continuations[i] = current;
|
| - current.parent_index = i;
|
| - }
|
| - continuations.removeLast();
|
| - }
|
| - cont.parent = _DELETED;
|
| - }
|
| -
|
| void _processTask(_ReductionTask task) {
|
| - // Skip tasks for deleted nodes.
|
| + // Lazily skip tasks for deleted nodes.
|
| if (task.node.parent == _DELETED) {
|
| return;
|
| }
|
| @@ -108,11 +89,11 @@ class ShrinkingReducer extends PassMixin {
|
| assert(_isDeadCont(task.node));
|
|
|
| // Remove dead continuation.
|
| - Continuation cont = task.node;
|
| - _removeContinuation(cont);
|
| + LetCont letCont = task.node;
|
| + _removeNode(letCont);
|
|
|
| // Perform bookkeeping on removed body and scan for new redexes.
|
| - new _RemovalRedexVisitor(_worklist).visit(cont);
|
| + new _RemovalRedexVisitor(_worklist).visit(letCont.continuation);
|
| }
|
|
|
| /// Applies the beta-cont-lin reduction:
|
| @@ -130,8 +111,9 @@ class ShrinkingReducer extends PassMixin {
|
| }
|
|
|
| // Remove the continuation.
|
| - Continuation cont = task.node;
|
| - _removeContinuation(cont);
|
| + LetCont letCont = task.node;
|
| + Continuation cont = letCont.continuation;
|
| + _removeNode(letCont);
|
|
|
| // Replace its invocation with the continuation body.
|
| InvokeContinuation invoke = cont.firstRef.parent;
|
| @@ -146,7 +128,7 @@ class ShrinkingReducer extends PassMixin {
|
| argRef.definition.substituteFor(cont.parameters[i]);
|
| }
|
|
|
| - // Perform bookkeeping on substituted body and scan for new redexes.
|
| + // Perform bookkeeping on removed body and scan for new redexes.
|
| new _RemovalRedexVisitor(_worklist).visit(invoke);
|
| }
|
|
|
| @@ -165,8 +147,9 @@ class ShrinkingReducer extends PassMixin {
|
| }
|
|
|
| // Remove the continuation.
|
| - Continuation cont = task.node;
|
| - _removeContinuation(cont);
|
| + LetCont letCont = task.node;
|
| + Continuation cont = letCont.continuation;
|
| + _removeNode(letCont);
|
|
|
| InvokeContinuation invoke = cont.body;
|
| Continuation wrappedCont = invoke.continuation.definition;
|
| @@ -182,14 +165,13 @@ class ShrinkingReducer extends PassMixin {
|
| /// Returns true iff the bound primitive is unused.
|
| bool _isDeadVal(LetPrim node) => !node.primitive.hasAtLeastOneUse;
|
|
|
| -/// Returns true iff the continuation is unused.
|
| -bool _isDeadCont(Continuation cont) {
|
| - return !cont.hasAtLeastOneUse && !cont.isReturnContinuation;
|
| -}
|
| +/// Returns true iff the bound continuation is unused.
|
| +bool _isDeadCont(LetCont node) => !node.continuation.hasAtLeastOneUse;
|
|
|
| -/// Returns true iff the continuation is used exactly once, and that
|
| -/// use is as the continuation of a continuation invocation.
|
| -bool _isBetaContLin(Continuation cont) {
|
| +/// Returns true iff the bound continuation is used exactly once, and that
|
| +/// use is as the receiver of a continuation invocation.
|
| +bool _isBetaContLin(LetCont node) {
|
| + Continuation cont = node.continuation;
|
| if (!cont.hasExactlyOneUse) {
|
| return false;
|
| }
|
| @@ -200,12 +182,14 @@ bool _isBetaContLin(Continuation cont) {
|
| }
|
|
|
| return false;
|
| +
|
| }
|
|
|
| -/// Returns true iff the continuation consists of a continuation
|
| +/// Returns true iff the bound continuation consists of a continuation
|
| /// invocation, passing on all parameters. Special cases exist (see below).
|
| -bool _isEtaCont(Continuation cont) {
|
| - if (cont.body is! InvokeContinuation) {
|
| +bool _isEtaCont(LetCont node) {
|
| + Continuation cont = node.continuation;
|
| + if (!(cont.body is InvokeContinuation)) {
|
| return false;
|
| }
|
|
|
| @@ -258,16 +242,12 @@ class _RedexVisitor extends RecursiveVisitor {
|
| void processLetCont(LetCont node) {
|
| if (node.parent == ShrinkingReducer._DELETED) {
|
| return;
|
| - }
|
| - for (int i = 0; i < node.continuations.length; ++i) {
|
| - Continuation cont = node.continuations[i];
|
| - if (_isDeadCont(cont)) {
|
| - worklist.add(new _ReductionTask(_ReductionKind.DEAD_CONT, cont));
|
| - } else if (_isEtaCont(cont)) {
|
| - worklist.add(new _ReductionTask(_ReductionKind.ETA_CONT, cont));
|
| - } else if (_isBetaContLin(cont)){
|
| - worklist.add(new _ReductionTask(_ReductionKind.BETA_CONT_LIN, cont));
|
| - }
|
| + } else if (_isDeadCont(node)) {
|
| + worklist.add(new _ReductionTask(_ReductionKind.DEAD_CONT, node));
|
| + } else if (_isEtaCont(node)) {
|
| + worklist.add(new _ReductionTask(_ReductionKind.ETA_CONT, node));
|
| + } else if (_isBetaContLin(node)){
|
| + worklist.add(new _ReductionTask(_ReductionKind.BETA_CONT_LIN, node));
|
| }
|
| }
|
| }
|
| @@ -286,10 +266,6 @@ class _RemovalRedexVisitor extends _RedexVisitor {
|
| node.parent = ShrinkingReducer._DELETED;
|
| }
|
|
|
| - void processContinuation(Continuation node) {
|
| - node.parent = ShrinkingReducer._DELETED;
|
| - }
|
| -
|
| void processReference(Reference reference) {
|
| reference.unlink();
|
|
|
| @@ -307,8 +283,9 @@ class _RemovalRedexVisitor extends _RedexVisitor {
|
| // removed, or it is called nonrecursively outside its body.
|
| cont.isRecursive = false;
|
| }
|
| - if (_isDeadCont(cont)) {
|
| - worklist.add(new _ReductionTask(_ReductionKind.DEAD_CONT, cont));
|
| + Node parent = cont.parent;
|
| + if (parent is LetCont && _isDeadCont(parent)) {
|
| + worklist.add(new _ReductionTask(_ReductionKind.DEAD_CONT, parent));
|
| }
|
| }
|
| }
|
| @@ -316,6 +293,7 @@ class _RemovalRedexVisitor extends _RedexVisitor {
|
|
|
| /// Traverses the CPS term and sets node.parent for each visited node.
|
| class ParentVisitor extends RecursiveVisitor {
|
| +
|
| processFunctionDefinition(FunctionDefinition node) {
|
| node.body.parent = node;
|
| node.parameters.forEach((Definition p) => p.parent = node);
|
| @@ -348,17 +326,13 @@ class ParentVisitor extends RecursiveVisitor {
|
| }
|
|
|
| processLetCont(LetCont node) {
|
| - for (int i = 0; i < node.continuations.length; ++i) {
|
| - Continuation cont = node.continuations[i];
|
| - cont.parent = node;
|
| - cont.parent_index = i;
|
| - }
|
| + node.continuation.parent = node;
|
| node.body.parent = node;
|
| }
|
|
|
| processInvokeStatic(InvokeStatic node) {
|
| - node.arguments.forEach((Reference ref) => ref.parent = node);
|
| node.continuation.parent = node;
|
| + node.arguments.forEach((Reference ref) => ref.parent = node);
|
| }
|
|
|
| processInvokeContinuation(InvokeContinuation node) {
|
|
|