From a06f1ed3b9bf1cde6e23b0d7315bf33cbdcda59d Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Mon, 9 May 2022 15:32:16 +0200 Subject: [PATCH] Fix infinite loop by doing deep copy (#3441) Patch provided by Jaroslav, appears to fix local issues with inifite loop introduced in https://github.com/enso-org/enso/pull/3429. ### Important Notes This renders https://github.com/enso-org/enso/pull/3439 obsolete. Related to https://www.pivotaltracker.com/n/projects/2539304/stories/182024911 --- .../interpreter/node/ClosureRootNode.java | 4 +++ .../enso/interpreter/node/MethodRootNode.java | 29 +++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/ClosureRootNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/ClosureRootNode.java index 0646aab105a8..04b2e55d033e 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/ClosureRootNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/ClosureRootNode.java @@ -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; + } } diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/MethodRootNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/MethodRootNode.java index 0a424ae1ca0f..89dca9c37957 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/MethodRootNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/MethodRootNode.java @@ -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; @@ -108,6 +110,18 @@ 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 provider; @@ -115,11 +129,22 @@ private static class LazyBodyNode extends ExpressionNode { 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; + } } }