Skip to content
Snippets Groups Projects
Commit 079c6513 authored by Florian Angerer's avatar Florian Angerer
Browse files

[GR-5543] Improvements around promises/arguments.

PullRequest: fastr/1198
parents eb8bc833 25dd1f98
No related branches found
No related tags found
No related merge requests found
...@@ -242,7 +242,8 @@ public abstract class InternalNode extends OperatorNode { ...@@ -242,7 +242,8 @@ public abstract class InternalNode extends OperatorNode {
protected Object[] prepareArgs(VirtualFrame frame) { protected Object[] prepareArgs(VirtualFrame frame) {
Object[] args = new Object[arguments.length]; Object[] args = new Object[arguments.length];
for (int i = 0; i < args.length; i++) { for (int i = 0; i < args.length; i++) {
args[i] = arguments[i].execute(frame); Object execute = arguments[i].execute(frame);
args[i] = execute;
} }
return args; return args;
} }
...@@ -300,11 +301,13 @@ public abstract class InternalNode extends OperatorNode { ...@@ -300,11 +301,13 @@ public abstract class InternalNode extends OperatorNode {
Object[] args = new Object[factory.getSignature().getLength()]; Object[] args = new Object[factory.getSignature().getLength()];
for (int i = 0; i < args.length - 1; i++) { for (int i = 0; i < args.length - 1; i++) {
args[i] = arguments[i].execute(frame); Object arg = arguments[i].execute(frame);
args[i] = arg;
} }
Object[] varArgs = new Object[arguments.length - (factory.getSignature().getLength() - 1)]; Object[] varArgs = new Object[arguments.length - (factory.getSignature().getLength() - 1)];
for (int i = 0; i < varArgs.length; i++) { for (int i = 0; i < varArgs.length; i++) {
varArgs[i] = arguments[args.length - 1 + i].execute(frame); Object arg = arguments[args.length - 1 + i].execute(frame);
varArgs[i] = arg;
} }
args[args.length - 1] = new RArgsValuesAndNames(varArgs, ArgumentsSignature.empty(varArgs.length)); args[args.length - 1] = new RArgsValuesAndNames(varArgs, ArgumentsSignature.empty(varArgs.length));
return args; return args;
......
...@@ -540,10 +540,10 @@ public abstract class PromiseNode extends RNode { ...@@ -540,10 +540,10 @@ public abstract class PromiseNode extends RNode {
evaluatedArgs[i] = argValue; evaluatedArgs[i] = argValue;
} else { } else {
size++; size++;
evaluatedArgs[i] = promiseCheckHelper.checkEvaluate(frame, argValue); Object arg = promiseCheckHelper.checkEvaluate(frame, argValue);
evaluatedArgs[i] = arg;
} }
if (evaluatedArgs[i] == null) { if (evaluatedArgs[i] == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
throw RInternalError.shouldNotReachHere("evaluated argument must not be null"); throw RInternalError.shouldNotReachHere("evaluated argument must not be null");
} }
} }
...@@ -565,10 +565,10 @@ public abstract class PromiseNode extends RNode { ...@@ -565,10 +565,10 @@ public abstract class PromiseNode extends RNode {
evaluatedArgs[i] = argValue; evaluatedArgs[i] = argValue;
} else { } else {
size++; size++;
evaluatedArgs[i] = promiseCheckHelper.checkEvaluate(frame, argValue); Object arg = promiseCheckHelper.checkEvaluate(frame, argValue);
evaluatedArgs[i] = arg;
} }
if (evaluatedArgs[i] == null) { if (evaluatedArgs[i] == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
throw RInternalError.shouldNotReachHere("evaluated argument must not be null"); throw RInternalError.shouldNotReachHere("evaluated argument must not be null");
} }
} }
......
...@@ -91,7 +91,10 @@ public final class OptForcedEagerPromiseNode extends PromiseNode { ...@@ -91,7 +91,10 @@ public final class OptForcedEagerPromiseNode extends PromiseNode {
call = call.getParent(); call = call.getParent();
} }
} }
return factory.createEagerSuppliedPromise(value, alwaysValidAssumption, call, null, wrapIndex); if (CompilerDirectives.inInterpreter()) {
return factory.createEagerSuppliedPromise(value, alwaysValidAssumption, call, null, wrapIndex, frame.materialize());
}
return factory.createEagerSuppliedPromise(value, alwaysValidAssumption, call, null, wrapIndex, null);
} }
@Override @Override
......
...@@ -25,6 +25,7 @@ package com.oracle.truffle.r.nodes.function.opt; ...@@ -25,6 +25,7 @@ package com.oracle.truffle.r.nodes.function.opt;
import com.oracle.truffle.api.Assumption; import com.oracle.truffle.api.Assumption;
import com.oracle.truffle.api.CompilerDirectives; import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.frame.FrameSlot; import com.oracle.truffle.api.frame.FrameSlot;
import com.oracle.truffle.api.frame.MaterializedFrame;
import com.oracle.truffle.api.frame.VirtualFrame; import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.InvalidAssumptionException; import com.oracle.truffle.api.nodes.InvalidAssumptionException;
import com.oracle.truffle.api.profiles.BranchProfile; import com.oracle.truffle.api.profiles.BranchProfile;
...@@ -99,10 +100,16 @@ public abstract class OptVariablePromiseBaseNode extends PromiseNode implements ...@@ -99,10 +100,16 @@ public abstract class OptVariablePromiseBaseNode extends PromiseNode implements
promiseCallerProfile.enter(); promiseCallerProfile.enter();
call = call.getParent(); call = call.getParent();
} }
MaterializedFrame execFrame = null;
if (CompilerDirectives.inInterpreter()) {
execFrame = frame.materialize();
}
if (result instanceof RPromise) { if (result instanceof RPromise) {
return factory.createPromisedPromise((RPromise) result, notChangedNonLocally, call, this); return factory.createPromisedPromise((RPromise) result, notChangedNonLocally, call, this, execFrame);
} else { } else {
return factory.createEagerSuppliedPromise(result, notChangedNonLocally, call, this, wrapIndex); return factory.createEagerSuppliedPromise(result, notChangedNonLocally, call, this, wrapIndex, execFrame);
} }
} }
......
...@@ -502,18 +502,18 @@ public final class RDataFactory { ...@@ -502,18 +502,18 @@ public final class RDataFactory {
} }
public static RPromise createEagerPromise(PromiseState state, Closure exprClosure, Object eagerValue, Assumption notChangedNonLocally, RCaller targetFrame, EagerFeedback feedback, public static RPromise createEagerPromise(PromiseState state, Closure exprClosure, Object eagerValue, Assumption notChangedNonLocally, RCaller targetFrame, EagerFeedback feedback,
int wrapIndex) { int wrapIndex, MaterializedFrame execFrame) {
if (FastROptions.noEagerEval()) { if (FastROptions.noEagerEval()) {
throw RInternalError.shouldNotReachHere(); throw RInternalError.shouldNotReachHere();
} }
return traceDataCreated(new RPromise.EagerPromise(state, exprClosure, eagerValue, notChangedNonLocally, targetFrame, feedback, wrapIndex)); return traceDataCreated(new RPromise.EagerPromise(state, exprClosure, eagerValue, notChangedNonLocally, targetFrame, feedback, wrapIndex, execFrame));
} }
public static RPromise createPromisedPromise(Closure exprClosure, Object eagerValue, Assumption notChangedNonLocally, RCaller targetFrame, EagerFeedback feedback) { public static RPromise createPromisedPromise(Closure exprClosure, Object eagerValue, Assumption notChangedNonLocally, RCaller targetFrame, EagerFeedback feedback, MaterializedFrame execFrame) {
if (FastROptions.noEagerEval()) { if (FastROptions.noEagerEval()) {
throw RInternalError.shouldNotReachHere(); throw RInternalError.shouldNotReachHere();
} }
return traceDataCreated(new RPromise.EagerPromise(PromiseState.Promised, exprClosure, eagerValue, notChangedNonLocally, targetFrame, feedback, -1)); return traceDataCreated(new RPromise.EagerPromise(PromiseState.Promised, exprClosure, eagerValue, notChangedNonLocally, targetFrame, feedback, -1, execFrame));
} }
public static Object createLangPairList(int size) { public static Object createLangPairList(int size) {
......
...@@ -26,7 +26,6 @@ import java.util.HashMap; ...@@ -26,7 +26,6 @@ import java.util.HashMap;
import com.oracle.truffle.api.Assumption; import com.oracle.truffle.api.Assumption;
import com.oracle.truffle.api.CompilerAsserts; import com.oracle.truffle.api.CompilerAsserts;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal; import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.CompilerDirectives.ValueType; import com.oracle.truffle.api.CompilerDirectives.ValueType;
...@@ -301,8 +300,8 @@ public class RPromise extends RObject implements RTypedValue { ...@@ -301,8 +300,8 @@ public class RPromise extends RObject implements RTypedValue {
*/ */
private boolean deoptimized = false; private boolean deoptimized = false;
EagerPromise(PromiseState state, Closure closure, Object eagerValue, Assumption notChangedNonLocally, RCaller targetFrame, EagerFeedback feedback, int wrapIndex) { EagerPromise(PromiseState state, Closure closure, Object eagerValue, Assumption notChangedNonLocally, RCaller targetFrame, EagerFeedback feedback, int wrapIndex, MaterializedFrame execFrame) {
super(state, (MaterializedFrame) null, closure); super(state, execFrame, closure);
assert state != PromiseState.Explicit; assert state != PromiseState.Explicit;
this.eagerValue = eagerValue; this.eagerValue = eagerValue;
this.notChangedNonLocally = notChangedNonLocally; this.notChangedNonLocally = notChangedNonLocally;
...@@ -317,7 +316,6 @@ public class RPromise extends RObject implements RTypedValue { ...@@ -317,7 +316,6 @@ public class RPromise extends RObject implements RTypedValue {
public boolean deoptimize() { public boolean deoptimize() {
if (!deoptimized && !isEvaluated() && feedback != null) { if (!deoptimized && !isEvaluated() && feedback != null) {
deoptimized = true; deoptimized = true;
notifyFailure();
materialize(); materialize();
return false; return false;
} }
...@@ -327,8 +325,10 @@ public class RPromise extends RObject implements RTypedValue { ...@@ -327,8 +325,10 @@ public class RPromise extends RObject implements RTypedValue {
@TruffleBoundary @TruffleBoundary
public void materialize() { public void materialize() {
if (execFrame == null) { if (execFrame == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
this.execFrame = Utils.getStackFrame(FrameAccess.MATERIALIZE, targetFrame).materialize(); this.execFrame = Utils.getStackFrame(FrameAccess.MATERIALIZE, targetFrame).materialize();
if (feedback != null) {
notifyFailure();
}
} }
} }
...@@ -408,14 +408,14 @@ public class RPromise extends RObject implements RTypedValue { ...@@ -408,14 +408,14 @@ public class RPromise extends RObject implements RTypedValue {
* until evaluation * until evaluation
* @return An {@link EagerPromise} * @return An {@link EagerPromise}
*/ */
public RPromise createEagerSuppliedPromise(Object eagerValue, Assumption notChangedNonLocally, RCaller targetFrame, EagerFeedback feedback, int wrapIndex) { public RPromise createEagerSuppliedPromise(Object eagerValue, Assumption notChangedNonLocally, RCaller targetFrame, EagerFeedback feedback, int wrapIndex, MaterializedFrame execFrame) {
return RDataFactory.createEagerPromise(state == PromiseState.Default ? PromiseState.EagerDefault : PromiseState.EagerSupplied, exprClosure, eagerValue, notChangedNonLocally, targetFrame, return RDataFactory.createEagerPromise(state == PromiseState.Default ? PromiseState.EagerDefault : PromiseState.EagerSupplied, exprClosure, eagerValue, notChangedNonLocally, targetFrame,
feedback, wrapIndex); feedback, wrapIndex, execFrame);
} }
public RPromise createPromisedPromise(RPromise promisedPromise, Assumption notChangedNonLocally, RCaller targetFrame, EagerFeedback feedback) { public RPromise createPromisedPromise(RPromise promisedPromise, Assumption notChangedNonLocally, RCaller targetFrame, EagerFeedback feedback, MaterializedFrame execFrame) {
assert state == PromiseState.Supplied; assert state == PromiseState.Supplied;
return RDataFactory.createPromisedPromise(exprClosure, promisedPromise, notChangedNonLocally, targetFrame, feedback); return RDataFactory.createPromisedPromise(exprClosure, promisedPromise, notChangedNonLocally, targetFrame, feedback, execFrame);
} }
public Object getExpr() { public Object getExpr() {
......
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