Skip to content

Commit e0fe5cc

Browse files
committed
Move options reading from PE'd code
1 parent 63fea62 commit e0fe5cc

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/PromiseHelperNode.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
*/
2323
package com.oracle.truffle.r.nodes.function;
2424

25+
import static com.oracle.truffle.r.runtime.context.FastROptions.PromiseCacheSize;
26+
2527
import com.oracle.truffle.api.Assumption;
2628
import com.oracle.truffle.api.CompilerAsserts;
2729
import com.oracle.truffle.api.CompilerDirectives;
@@ -45,7 +47,6 @@
4547
import com.oracle.truffle.r.nodes.function.visibility.GetVisibilityNode;
4648
import com.oracle.truffle.r.nodes.function.visibility.SetVisibilityNode;
4749
import com.oracle.truffle.r.runtime.DSLConfig;
48-
import static com.oracle.truffle.r.runtime.context.FastROptions.PromiseCacheSize;
4950
import com.oracle.truffle.r.runtime.RArguments;
5051
import com.oracle.truffle.r.runtime.RCaller;
5152
import com.oracle.truffle.r.runtime.RError;
@@ -407,12 +408,18 @@ protected abstract static class GenerateValueNonDefaultOptimizedNode extends Nod
407408
protected static final int CACHE_SIZE = ArgumentStatePush.MAX_COUNTED_ARGS * 2;
408409
protected static final int RECURSIVE_PROMISE_LIMIT = 3;
409410

411+
// If set to -1, then no further recursion should take place
412+
// This avoids having to invoke DSLConfig.getCacheSize in PE'd code
410413
private final byte recursiveCounter;
411414
@Child private PromiseHelperNode nextNode = null;
412415
@Child private SetVisibilityNode visibility;
413416

414417
protected GenerateValueNonDefaultOptimizedNode(byte recursiveCounter) {
415-
this.recursiveCounter = recursiveCounter;
418+
if (recursiveCounter > DSLConfig.getCacheSize(RECURSIVE_PROMISE_LIMIT)) {
419+
this.recursiveCounter = -1;
420+
} else {
421+
this.recursiveCounter = recursiveCounter;
422+
}
416423
}
417424

418425
public abstract Object execute(VirtualFrame frame, int state, EagerPromise promise);
@@ -476,7 +483,7 @@ Object doFallback(@SuppressWarnings("unused") int state, @SuppressWarnings("unus
476483
// If promise evaluates to another promise, we create another RPromiseHelperNode to evaluate
477484
// that, but only up to certain recursion level
478485
private Object evaluateNextNode(VirtualFrame frame, RPromise nextPromise) {
479-
if (recursiveCounter > DSLConfig.getCacheSize(RECURSIVE_PROMISE_LIMIT)) {
486+
if (recursiveCounter == -1) {
480487
evaluateNextNodeSlowPath(frame.materialize(), nextPromise);
481488
}
482489
if (nextNode == null) {

com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/context/RContext.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222
*/
2323
package com.oracle.truffle.r.runtime.context;
2424

25+
import static com.oracle.truffle.r.runtime.context.FastROptions.EagerEval;
26+
import static com.oracle.truffle.r.runtime.context.FastROptions.EagerEvalConstants;
27+
import static com.oracle.truffle.r.runtime.context.FastROptions.EagerEvalDefault;
28+
import static com.oracle.truffle.r.runtime.context.FastROptions.EagerEvalExpressions;
29+
import static com.oracle.truffle.r.runtime.context.FastROptions.EagerEvalVariables;
30+
2531
import java.io.IOException;
2632
import java.io.InputStream;
2733
import java.io.OutputStream;
@@ -46,7 +52,10 @@
4652
import java.util.function.Consumer;
4753
import java.util.function.Supplier;
4854

55+
import org.graalvm.options.OptionKey;
56+
4957
import com.oracle.truffle.api.Assumption;
58+
import com.oracle.truffle.api.CompilerDirectives;
5059
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
5160
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
5261
import com.oracle.truffle.api.RootCallTarget;
@@ -67,11 +76,6 @@
6776
import com.oracle.truffle.api.source.Source;
6877
import com.oracle.truffle.r.launcher.RCmdOptions;
6978
import com.oracle.truffle.r.launcher.RStartParams;
70-
import static com.oracle.truffle.r.runtime.context.FastROptions.EagerEval;
71-
import static com.oracle.truffle.r.runtime.context.FastROptions.EagerEvalConstants;
72-
import static com.oracle.truffle.r.runtime.context.FastROptions.EagerEvalDefault;
73-
import static com.oracle.truffle.r.runtime.context.FastROptions.EagerEvalExpressions;
74-
import static com.oracle.truffle.r.runtime.context.FastROptions.EagerEvalVariables;
7579
import com.oracle.truffle.r.runtime.LazyDBCache;
7680
import com.oracle.truffle.r.runtime.PrimitiveMethodsInfo;
7781
import com.oracle.truffle.r.runtime.REnvVars;
@@ -106,7 +110,6 @@
106110
import com.oracle.truffle.r.runtime.nodes.RCodeBuilder;
107111
import com.oracle.truffle.r.runtime.nodes.RSyntaxNode;
108112
import com.oracle.truffle.r.runtime.rng.RRNG;
109-
import org.graalvm.options.OptionKey;
110113

111114
/**
112115
* Encapsulates the runtime state ("context") of an R session. All access to that state from the
@@ -646,21 +649,17 @@ public int getNonNegativeIntOption(OptionKey<Integer> key) {
646649
if (res >= 0) {
647650
return res;
648651
}
649-
System.out.println("non negative integer option value expected");
650-
new RuntimeException().printStackTrace();
651-
System.exit(2);
652-
return -1;
652+
CompilerDirectives.transferToInterpreter();
653+
throw RInternalError.shouldNotReachHere(String.format("R option '%s' has invalid value"));
653654
}
654655

655656
public double getNonNegativeDoubleOption(OptionKey<Double> key) {
656657
double res = getOption(key);
657658
if (res >= 0) {
658659
return res;
659660
}
660-
System.out.println("non negative double option value expected");
661-
new RuntimeException().printStackTrace();
662-
System.exit(2);
663-
return -1;
661+
CompilerDirectives.transferToInterpreter();
662+
throw RInternalError.shouldNotReachHere(String.format("R option '%s' has invalid value"));
664663
}
665664

666665
public boolean noEagerEvalOption() {

0 commit comments

Comments
 (0)