Skip to content

Commit

Permalink
Fix infinite loop by doing deep copy
Browse files Browse the repository at this point in the history
Patch provided by Jaroslav, appears to fix local issues with inifite loop
introduced in #3429.
This renders #3439 obsolete.
  • Loading branch information
hubertp committed May 9, 2022
1 parent 078c665 commit 23f63e4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,8 @@ public Object execute(VirtualFrame frame) {
state = FrameUtil.getObjectSafe(frame, this.getStateFrameSlot());
return new Stateful(state, result);
}

final ExpressionNode getBody() {
return body;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.enso.interpreter.node;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.ReportPolymorphism;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.nodes.NodeInfo;
import com.oracle.truffle.api.source.SourceSection;
import java.util.function.Supplier;
Expand Down Expand Up @@ -108,18 +110,41 @@ public String getMethodName() {
return methodName;
}

@Override
public Node deepCopy() {
LazyBodyNode.replaceLazyNode(getBody());
return super.deepCopy();
}

@Override
public Node copy() {
LazyBodyNode.replaceLazyNode(getBody());
return super.copy();
}

private static class LazyBodyNode extends ExpressionNode {
private final Supplier<ExpressionNode> provider;

LazyBodyNode(Supplier<ExpressionNode> body) {
this.provider = body;
}

static void replaceLazyNode(Node n) {
if (n instanceof LazyBodyNode lazy) {
lazy.replaceItself();
}
}

@Override
public Object executeGeneric(VirtualFrame frame) {
ExpressionNode newNode = replace(provider.get());
notifyInserted(newNode);
ExpressionNode newNode = replaceItself();
return newNode.executeGeneric(frame);
}

final ExpressionNode replaceItself() {
ExpressionNode newNode = replace(provider.get());
notifyInserted(newNode);
return newNode;
}
}
}

0 comments on commit 23f63e4

Please sign in to comment.