Skip to content

Commit 359681e

Browse files
[GR-19325] [GR-19296] [GR-19297] [GR-17422] [GR-19326] Backport configuration related fixes to 19.3.0.
PullRequest: fastr/2209
2 parents a39acb9 + 4ee3d21 commit 359681e

File tree

8 files changed

+118
-67
lines changed

8 files changed

+118
-67
lines changed

ci_common/common.hocon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# java 7 is needed by Truffle (for now)
22
java7 : {name : oraclejdk, version : "7", platformspecific: true}
33
# java 8 must be a jvmci enabled variant
4-
java8 : {name : oraclejdk, version : "8u221-jvmci-19.3-b02", platformspecific: true}
4+
java8 : {name : oraclejdk, version : "8u231-jvmci-19.3-b04", platformspecific: true}
55
java11 : {name : labsjdk, version : "ce-11.0.5+9-jvmci-19.3-b03", platformspecific: true}
66

77
java8Downloads : {

com.oracle.truffle.r.native/run/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,11 @@ $(FASTR_BIN_DIR)/R: Makefile R.sh Rscript.sh Rscript_exec.sh Rclasspath.sh
8989
cp $(GNUR_HOME_BINARY)/etc/Makeconf Makeconf.etc
9090
cp $(GNUR_HOME_BINARY)/etc/javaconf $(FASTR_ETC_DIR)/javaconf
9191
cp $(GNUR_HOME_BINARY)/etc/repositories $(FASTR_ETC_DIR)/repositories
92-
cp $(GNUR_HOME_BINARY)/etc/ldpaths $(FASTR_ETC_DIR)/ldpaths
92+
# ldpaths: create two versions: ldpaths.llvm (used also as default ldpaths) and ldpaths.native
93+
# the llvm version adds the LLVM lib folder to the LD_LIBRARY_PATH
94+
sed 's!export LD_LIBRARY_PATH!LD_LIBRARY_PATH="$$\{R_HOME\}/../llvm/native/lib/:$$\{LD_LIBRARY_PATH\}"; export LD_LIBRARY_PATH!' $(GNUR_HOME_BINARY)/etc/ldpaths > $(FASTR_ETC_DIR)/ldpaths
95+
cp $(FASTR_ETC_DIR)/ldpaths $(FASTR_ETC_DIR)/ldpaths.llvm
96+
cp $(GNUR_HOME_BINARY)/etc/ldpaths $(FASTR_ETC_DIR)/ldpaths.native
9397
# the ed script adds -DFASTR to compiler options and removes JAVA related variables
9498
ed Makeconf.etc < edMakeconf.etc
9599
# Backup the current state of Makeconf.etc to allow users to switch back to the native toolchain

com.oracle.truffle.r.native/run/configure_fastr

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ function printHelp {
7676
GCC_LIB_PATH=""
7777
CONFIGURE_ARGS=""
7878
CONFIGURE_ETC=0
79+
CONFIGURE_NATIVE_TOOLCHAIN=0
7980
while [[ $# -gt 0 ]]; do
8081
case $1 in
8182
--help)
@@ -88,26 +89,62 @@ while [[ $# -gt 0 ]]; do
8889
;;
8990
--configure-etc)
9091
CONFIGURE_ETC=1
91-
;;
92+
;;
93+
--enable-native-compilers-toolchain)
94+
CONFIGURE_NATIVE_TOOLCHAIN=1
95+
CONFIGURE_ARGS="$CONFIGURE_ARGS $1"
96+
;;
9297
*)
9398
CONFIGURE_ARGS="$CONFIGURE_ARGS $1"
9499
;;
95100
esac
96101
shift
97-
done
102+
done
103+
104+
if [[ $CONFIGURE_NATIVE_TOOLCHAIN = 1 ]] && [[ $CONFIGURE_ETC = 0 ]]; then
105+
echo "Error: --enable-native-compilers-toolchain does not have any effect when not run with --configure-etc."
106+
exit 100
107+
fi
98108

99109
(
100110
if [[ "$OSTYPE" == "linux-gnu" ]]; then
101-
echo "int main(){}" | gcc -x c -Wl,--no-as-needed -lgfortran -lgcc_s -lquadmath -o /dev/null - > /dev/null 2>/dev/null
102-
res=$?
111+
res=0
112+
for lib in libgfortran.so.3 libm.so.6 libquadmath.so.0 libgcc_s.so.1; do
113+
if ! ldconfig -p | grep --quiet $lib; then
114+
echo "Error: could not find gfortran3 runtime library: $lib"
115+
echo "Please install the gfortran3 runtime libraries:"
116+
echo " On Debian based systems: apt-get install libgfortran3"
117+
echo " On Oracle Linux 7: yum install libgfortran"
118+
echo " On Oracle Linux 8: yum install compat-libgfortran-48"
119+
res=1
120+
break
121+
fi
122+
done
123+
if ! ldconfig -p | grep --quiet "libgomp.so.1"; then
124+
echo "Error: could not find OpenMP runtime library: libgomp.so.1"
125+
echo "Please install the OpenMP runtime library runtime libraries:"
126+
echo " On Debian based systems: apt-get install libgomp1"
127+
echo " On Oracle Linux 7 and 8: yum install libgomp"
128+
echo " Note: Oracle Linux 8 should contain libgomp by default"
129+
res=1
130+
fi
131+
if which gfortran > /dev/null 2> /dev/null; then
132+
echo "Note: if you intend to install R packages you may need additional packages."
133+
echo "The following packages should cover the most commonly used R packages:"
134+
echo " On Debian based systems: apt-get install build-essential gfortran libxml2 libc++-dev"
135+
echo " On Oracle Linux 7 and 8: yum groupinstall 'Development Tools'"
136+
if [[ $res != 0 ]]; then
137+
echo "Caution: you still need to install gfortran3 runtime libraries on all systems where this version is not the default (Ubuntu 18 or higher, Oracle Linux 8 or higher)."
138+
fi
139+
fi
103140
if [[ $res != 0 ]]; then
104-
echo "Cannot build a simple C program linking with libgfortran, libgcc_s, and libquadmath."
105-
echo "Please install GCC and gfortran using:"
106-
echo " On Debian based systems: sudo apt-get install build-essential gfortran"
107-
echo " On CentOS/RHEL/Oracle Linux: sudo yum groupinstall \"Developent Tools\"; yum install gcc-gfortran"
108-
echo ""
109-
printHelp
141+
echo "The basic configuration of FastR failed."
142+
echo "To learn more:"
143+
echo " run this script with '--help'"
144+
echo " visit https://www.graalvm.org/docs/reference-manual/languages/r"
110145
exit 1
146+
else
147+
echo "The basic configuration of FastR was successfull."
111148
fi
112149
elif [[ "$OSTYPE" == "darwin"* ]]; then
113150
cd -P "$( dirname "$source" )/../lib"
@@ -144,7 +181,7 @@ done
144181
# don't look at symlinks
145182
if [ ! -L "${TARGET_LIB}" ] ; then
146183
# grep for the current path of this gfortran library in this library's linking info
147-
CURRENT_LIB_NAME=`otool -L ${TARGET_LIB} | grep -o "\t.*${GFORTRAN_LIB_BASE}"`
184+
CURRENT_LIB_NAME=`otool -L ${TARGET_LIB} | grep -o "\t.*${GFORTRAN_LIB_BASE}[^ ]*"`
148185
if [ ! -z "$CURRENT_LIB_NAME" ] ; then
149186
if [ "$CURRENT_LIB_NAME" != "$LIB_LOCATION" ] ; then
150187
# change to the new location

com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/fastr/FastRSetToolchain.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,25 @@ public abstract class FastRSetToolchain extends RBuiltinNode.Arg1 {
5252
@Specialization
5353
protected RNull setToolchain(String name) {
5454
String srcConf;
55+
String srcLdpaths;
5556
if ("native".equals(name)) {
5657
srcConf = "Makeconf.native";
58+
srcLdpaths = "ldpaths.native";
5759
} else if ("llvm".equals(name)) {
5860
srcConf = "Makeconf.llvm";
61+
srcLdpaths = "ldpaths.llvm";
5962
} else {
6063
throw error(RError.Message.GENERIC, "Only 'native' or 'llvm' argument values accepted");
6164
}
6265
TruffleFile rHome = REnvVars.getRHomeTruffleFile(RContext.getInstance().getEnv());
6366
TruffleFile etc = rHome.resolve("etc");
64-
TruffleFile src = etc.resolve(srcConf);
65-
TruffleFile dst = etc.resolve("Makeconf");
67+
TruffleFile srcConfFile = etc.resolve(srcConf);
68+
TruffleFile dstConfFile = etc.resolve("Makeconf");
69+
TruffleFile srcLdpathsFile = etc.resolve(srcLdpaths);
70+
TruffleFile dstLdpathsFile = etc.resolve("ldpaths");
6671
try {
67-
src.copy(dst, StandardCopyOption.REPLACE_EXISTING);
72+
srcConfFile.copy(dstConfFile, StandardCopyOption.REPLACE_EXISTING);
73+
srcLdpathsFile.copy(dstLdpathsFile, StandardCopyOption.REPLACE_EXISTING);
6874
} catch (IOException e) {
6975
throw new RInternalError(String.format("Copying %s over etc/Makeconf failed", srcConf), e);
7076
}

com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/InlineCacheNode.java

Lines changed: 51 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,17 @@
2222
*/
2323
package com.oracle.truffle.r.nodes;
2424

25+
import com.oracle.truffle.api.CompilerDirectives;
26+
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
2527
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
26-
import com.oracle.truffle.api.Truffle;
27-
import com.oracle.truffle.api.TruffleLanguage;
28-
import com.oracle.truffle.api.TruffleRuntime;
2928
import com.oracle.truffle.api.dsl.Cached;
3029
import com.oracle.truffle.api.dsl.ReportPolymorphism;
3130
import com.oracle.truffle.api.dsl.Specialization;
3231
import com.oracle.truffle.api.frame.Frame;
3332
import com.oracle.truffle.api.frame.MaterializedFrame;
3433
import com.oracle.truffle.api.frame.VirtualFrame;
35-
import com.oracle.truffle.api.nodes.DirectCallNode;
36-
import com.oracle.truffle.api.nodes.RootNode;
37-
import com.oracle.truffle.api.profiles.ValueProfile;
38-
import com.oracle.truffle.r.runtime.context.RContext;
34+
import com.oracle.truffle.api.nodes.Node;
35+
import com.oracle.truffle.api.profiles.ConditionProfile;
3936
import com.oracle.truffle.r.runtime.data.Closure;
4037
import com.oracle.truffle.r.runtime.nodes.RBaseNode;
4138
import com.oracle.truffle.r.runtime.nodes.RNode;
@@ -55,61 +52,65 @@ protected InlineCacheNode(int maxPicDepth) {
5552
this.maxPicDepth = maxPicDepth;
5653
}
5754

58-
/**
59-
* Creates an inline cache that will execute promises closures by using a polymorphic inline
60-
* cache (PIC) and falling back to
61-
* {@link InlineCacheNode#evalPromise(MaterializedFrame, Closure)}.
62-
*
63-
* @param maxPicDepth maximum number of entries in the PIC
64-
*/
65-
public static InlineCacheNode create(int maxPicDepth) {
66-
return InlineCacheNodeGen.create(maxPicDepth);
67-
}
55+
@SuppressWarnings("unused")
56+
@Specialization(limit = "maxPicDepth", guards = "value == cachedValue")
57+
protected Object doCached(Frame frame, Object value,
58+
@Cached("value") Object cachedValue,
59+
@Cached("createBinaryProfile()") ConditionProfile isVirtualFrameProfile,
60+
@Cached("cache(cachedValue)") RNode reified,
61+
@Cached("new(reified)") NodeInsertedClosure nodeInsertedClosure) {
62+
VirtualFrame vf;
63+
if (isVirtualFrameProfile.profile(frame instanceof VirtualFrame)) {
64+
vf = (VirtualFrame) frame;
65+
} else {
66+
vf = frame.materialize();
67+
}
6868

69-
// Cached case: create a root node and direct call node
70-
// This should allow Truffle PE to inline the promise code if it deems it is beneficial
69+
// Use a closure to notify the root node that a new node has just been inserted. The
70+
// closure is necessary to do the notification just once.
71+
nodeInsertedClosure.notifyNodeInserted();
7172

72-
protected DirectCallNode createInlinableCall(Closure value) {
73-
InlineCacheRootNode rootNode = new InlineCacheRootNode(RContext.getInstance().getLanguage(), RASTUtils.cloneNode((RNode) value.getExpr()));
74-
TruffleRuntime runtime = Truffle.getRuntime();
75-
runtime.createCallTarget(rootNode);
76-
return runtime.createDirectCallNode(rootNode.getCallTarget());
73+
return reified.visibleExecute(vf);
7774
}
7875

79-
private static final class InlineCacheRootNode extends RootNode {
80-
@Child private RNode node;
81-
82-
protected InlineCacheRootNode(TruffleLanguage<?> language, RNode node) {
83-
super(language);
84-
this.node = node;
85-
}
86-
87-
@Override
88-
public Object execute(VirtualFrame frame) {
89-
VirtualFrame execFrame = (VirtualFrame) frame.getArguments()[0];
90-
return node.visibleExecute(execFrame);
91-
}
76+
@Specialization(replaces = "doCached")
77+
protected Object doGeneric(Frame frame, Object value) {
78+
return evalPromise(frame.materialize(), (Closure) value);
9279
}
9380

94-
@Specialization(limit = "maxPicDepth", guards = "value == cachedValue")
95-
protected Object doCached(Frame frame, @SuppressWarnings("unused") Closure value,
96-
@SuppressWarnings("unused") @Cached("value") Closure cachedValue,
97-
@Cached("createClassProfile()") ValueProfile frameClassProfile,
98-
@Cached("createInlinableCall(value)") DirectCallNode callNode) {
99-
return callNode.call(frameClassProfile.profile(frame).materialize());
81+
protected RNode cache(Object value) {
82+
return RASTUtils.cloneNode((RNode) ((Closure) value).getExpr());
10083
}
10184

102-
// Generic case: execute call target cached in the Closure
103-
// We do not go though call node, so not Truffle inlining can take place,
104-
// but nothing is inserted into this AST, so it doesn't grow without limits
105-
106-
@Specialization(replaces = "doCached")
107-
protected Object doGeneric(Frame frame, Closure value) {
108-
return evalPromise(frame.materialize(), value);
85+
/**
86+
* Creates an inline cache that will execute promises closures by using a PIC and falling back
87+
* to {@link InlineCacheNode#evalPromise(MaterializedFrame, Closure)}.
88+
*
89+
* @param maxPicDepth maximum number of entries in the polymorphic inline cache
90+
*/
91+
public static InlineCacheNode create(int maxPicDepth) {
92+
return InlineCacheNodeGen.create(maxPicDepth);
10993
}
11094

11195
@TruffleBoundary
11296
protected static Object evalPromise(MaterializedFrame frame, Closure closure) {
11397
return closure.eval(frame);
11498
}
99+
100+
protected class NodeInsertedClosure {
101+
private final Node n;
102+
@CompilationFinal boolean notified;
103+
104+
public NodeInsertedClosure(Node n) {
105+
this.n = n;
106+
}
107+
108+
void notifyNodeInserted() {
109+
if (!notified) {
110+
CompilerDirectives.transferToInterpreterAndInvalidate();
111+
InlineCacheNode.this.notifyInserted(n);
112+
notified = true;
113+
}
114+
}
115+
}
115116
}

com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/CachedExtractVectorNode.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,8 @@ private void applyDimensions(RAbstractContainer originalTarget, RAbstractVector
308308
}
309309
newDimNames[dimIndex] = result;
310310
if (newDimNamesNames != null) {
311+
// (newDimNamesNames == null) <=> (originalDimNamesNames == null)
312+
assert originalDimNamesNames != null;
311313
newDimNamesNames[dimIndex] = originalDimNamesNames.getDataAt(i);
312314
}
313315
}

com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/REnvVars.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public RContext.ContextState initialize(RContext context) {
126126
}
127127
}
128128
TruffleFile userFile = userFilePath != null ? FileSystemUtils.getSafeTruffleFile(env, userFilePath) : null;
129-
if (userFile.exists()) {
129+
if (userFile != null && userFile.exists()) {
130130
safeReadEnvironFile(userFile);
131131
}
132132
}

mx.fastr/mx_fastr_dists.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ def mx_register_dynamic_suite_constituents(register_project, register_distributi
292292
short_name='R',
293293
license_files=['LICENSE_FASTR'],
294294
third_party_license_files=['3rd_party_licenses_fastr.txt'],
295+
dependencies=['Truffle', 'Sulong', 'LLVM.org toolchain'],
295296
truffle_jars=['fastr:FASTR'],
296297
support_distributions=['fastr:FASTR_GRAALVM_SUPPORT'],
297298
provided_executables=[

0 commit comments

Comments
 (0)