Skip to content
Snippets Groups Projects
Commit 44723397 authored by stepan's avatar stepan
Browse files

Remove internal-parent hack from RCaller

parent 24c33740
No related branches found
No related tags found
No related merge requests found
......@@ -544,9 +544,6 @@ public class FrameFunctions {
RCaller call = RArguments.getCall(frame);
int i = 0;
while (i < n + 1) {
if (call.hasInternalParent()) {
i--; // in this loop iteration, we deal with the parent, but do not count it
}
call = call.getParent();
if (call == null) {
nullCallerProfile.enter();
......@@ -616,7 +613,7 @@ public class FrameFunctions {
RCaller currentCall = RArguments.getCall(f);
if (!currentCall.isPromise() && currentCall.getDepth() <= depth) {
int currentCallIdx = currentCall.getDepth() - 1;
while (currentCall != null && (currentCall.hasInternalParent() || currentCall.isPromise())) {
while (currentCall != null && (currentCall.isPromise())) {
currentCall = currentCall.getParent();
}
result[currentCallIdx] = currentCall == null ? 0 : currentCall.getParent().getDepth();
......
......@@ -54,30 +54,24 @@ public final class RCaller {
private final RCaller parent;
/**
* The payload can be an RSyntaxNode, a {@link Supplier}, or an {@link RCaller} (which marks
* promise evaluation frames).
* promise evaluation frames). Payload represents the syntax (AST) of how the function was
* invoked. If the function was invoked via regular call node, then the syntax can be that call
* node (RSyntaxNode case), if the function was invoked by other means and we do not have the
* actual syntax for the invocation, we only provide it lazily via Supplier, so that we do not
* have to always construct the AST nodes.
*/
private final Object payload;
/**
* Marks those callers whose parent should not be taken into account when iterating R level
* frames using e.g. {@code parent.frame()}. This is the case for function invoked through
* {@code do.call} -- R pretends that they were called by the caller of {@code do.call} so that
* code like {@code eval(formula, parent.frame(2))} gives the same results regardless of whether
* the function was invoked directly or through {@code do.call}.
*/
private final boolean parentIsInternal;
private RCaller(Frame callingFrame, Object nodeOrSupplier, boolean parentIsInternal) {
private RCaller(Frame callingFrame, Object nodeOrSupplier) {
this.depth = depthFromFrame(callingFrame);
this.parent = parentFromFrame(callingFrame);
this.payload = nodeOrSupplier;
this.parentIsInternal = parentIsInternal;
}
private RCaller(int depth, RCaller parent, Object nodeOrSupplier) {
this.depth = depth;
this.parent = parent;
this.payload = nodeOrSupplier;
this.parentIsInternal = false;
}
private static int depthFromFrame(Frame callingFrame) {
......@@ -88,17 +82,6 @@ public final class RCaller {
return callingFrame == null ? null : RArguments.getCall(callingFrame);
}
private RCaller(int depth, RCaller parent, Object nodeOrSupplier, boolean parentIsInternal) {
this.depth = depth;
this.parent = parent;
this.payload = nodeOrSupplier;
this.parentIsInternal = parentIsInternal;
}
public RCaller withInternalParent() {
return new RCaller(depth, parent, payload, true);
}
public int getDepth() {
return depth;
}
......@@ -107,10 +90,6 @@ public final class RCaller {
return parent;
}
public boolean hasInternalParent() {
return parentIsInternal;
}
public RSyntaxElement getSyntaxNode() {
assert payload != null && !(payload instanceof RCaller) : payload == null ? "null RCaller" : "promise RCaller";
return payload instanceof RSyntaxElement ? (RSyntaxElement) payload : (RSyntaxElement) ((Supplier<?>) payload).get();
......@@ -129,47 +108,42 @@ public final class RCaller {
}
public static RCaller createInvalid(Frame callingFrame) {
return new RCaller(callingFrame, null, false);
return new RCaller(callingFrame, null);
}
public static RCaller createInvalid(Frame callingFrame, RCaller parent) {
return new RCaller(depthFromFrame(callingFrame), parent, null, false);
return new RCaller(depthFromFrame(callingFrame), parent, null);
}
public static RCaller create(Frame callingFrame, RSyntaxElement node) {
assert node != null;
return new RCaller(callingFrame, node, false);
return new RCaller(callingFrame, node);
}
public static RCaller create(Frame callingFrame, RCaller parent, RSyntaxElement node) {
assert node != null;
return new RCaller(depthFromFrame(callingFrame), parent, node, false);
}
public static RCaller createWithInternalParent(Frame callingFrame, Supplier<RSyntaxElement> supplier) {
assert supplier != null;
return new RCaller(callingFrame, supplier, true);
return new RCaller(depthFromFrame(callingFrame), parent, node);
}
public static RCaller create(Frame callingFrame, Supplier<RSyntaxElement> supplier) {
assert supplier != null;
return new RCaller(callingFrame, supplier, false);
return new RCaller(callingFrame, supplier);
}
public static RCaller create(int depth, RCaller parent, Object payload) {
assert payload != null;
return new RCaller(depth, parent, payload, false);
return new RCaller(depth, parent, payload);
}
public static RCaller create(Frame callingFrame, RCaller parent, Supplier<RSyntaxElement> supplier) {
assert supplier != null;
return new RCaller(depthFromFrame(callingFrame), parent, supplier, false);
return new RCaller(depthFromFrame(callingFrame), parent, supplier);
}
public static RCaller createForPromise(RCaller originalCaller, Frame frame) {
int newDepth = frame == null ? 0 : RArguments.getDepth(frame);
RCaller originalCall = frame == null ? null : RArguments.getCall(frame);
return new RCaller(newDepth, originalCaller, originalCall, false);
return new RCaller(newDepth, originalCaller, originalCall);
}
public boolean getVisibility() {
......@@ -179,8 +153,4 @@ public final class RCaller {
public void setVisibility(boolean visibility) {
this.visibility = visibility;
}
public Object getPayload() {
return payload;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment