Skip to content

Commit

Permalink
Fix infinite loop by doing deep copy (#3441)
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.

### Important Notes

This renders #3439 obsolete. Related to https://www.pivotaltracker.com/n/projects/2539304/stories/182024911
  • Loading branch information
hubertp authored May 9, 2022
1 parent 078c665 commit a06f1ed
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 a06f1ed

Please sign in to comment.