Skip to content

Commit 3f24d31

Browse files
committed
[GR-2798] Implement XYZ_NO_NA and XYZ_IS_SORTED, add test heapdump.R, improve configure_fastr.
PullRequest: fastr/2480
2 parents a6545b7 + 4bd8f5c commit 3f24d31

File tree

11 files changed

+312
-19
lines changed

11 files changed

+312
-19
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ Bug fixes:
55
* FastR cleans-up the temporary directory created for internal implementation of the R input handlers
66
* Improve performance of `unique` #154
77

8+
Added missing R builtins and C APIs
9+
10+
* Dummy implementations of `X_IS_SORTED` and `X_NO_NA` for `X = STRING,INTEGER,REAL` #156
11+
812
# 20.1.0
913

1014
New features:

com.oracle.truffle.r.native/fficall/src/truffle_common/Rinternals_truffle_common.h

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1969,14 +1969,43 @@ const SEXP *(STRING_PTR_RO)(SEXP x) {
19691969
}
19701970

19711971
// The ALTREP framework is not implemented on FastR yet
1972-
1973-
#define ALTREP_UNIMPLEMENTED { UNIMPLEMENTED; }
1972+
// Dummy implementations:
19741973

19751974
int (ALTREP)(SEXP x) {
19761975
// there can be no ALTREP objects on FastR
19771976
return 0;
19781977
}
19791978

1979+
int STRING_NO_NA(SEXP x) {
1980+
return 0;
1981+
}
1982+
1983+
int REAL_NO_NA(SEXP x) {
1984+
return 0;
1985+
}
1986+
1987+
int INTEGER_NO_NA(SEXP x) {
1988+
return 0;
1989+
}
1990+
1991+
int INTEGER_IS_SORTED(SEXP x) {
1992+
return UNKNOWN_SORTEDNESS;
1993+
}
1994+
1995+
int REAL_IS_SORTED(SEXP x) {
1996+
return UNKNOWN_SORTEDNESS;
1997+
}
1998+
1999+
int STRING_IS_SORTED(SEXP x) {
2000+
return UNKNOWN_SORTEDNESS;
2001+
}
2002+
2003+
// Looks like there are not implemented even in GNU-R:
2004+
#define ALTREP_UNIMPLEMENTED { UNIMPLEMENTED; }
2005+
SEXP REAL_IS_NA(SEXP x) ALTREP_UNIMPLEMENTED
2006+
SEXP INTEGER_IS_NA(SEXP x) ALTREP_UNIMPLEMENTED
2007+
2008+
// Functions that we cannot implement without ALTREP support:
19802009
SEXP R_altrep_data1(SEXP x) ALTREP_UNIMPLEMENTED
19812010
SEXP R_altrep_data2(SEXP x) ALTREP_UNIMPLEMENTED
19822011
void R_set_altrep_data1(SEXP x, SEXP v) ALTREP_UNIMPLEMENTED
@@ -2010,23 +2039,15 @@ void ALTCOMPLEX_SET_ELT(SEXP x, R_xlen_t i, Rcomplex v) ALTREP_UNIMPLEMENTED
20102039
Rbyte ALTRAW_ELT(SEXP x, R_xlen_t i) ALTREP_UNIMPLEMENTED
20112040
void ALTRAW_SET_ELT(SEXP x, R_xlen_t i, Rbyte v) ALTREP_UNIMPLEMENTED
20122041
R_xlen_t INTEGER_GET_REGION(SEXP sx, R_xlen_t i, R_xlen_t n, int *buf) ALTREP_UNIMPLEMENTED
2013-
int INTEGER_IS_SORTED(SEXP x) ALTREP_UNIMPLEMENTED
2014-
int INTEGER_NO_NA(SEXP x) ALTREP_UNIMPLEMENTED
20152042
SEXP ALTINTEGER_SUM(SEXP x, Rboolean narm) ALTREP_UNIMPLEMENTED
20162043
SEXP ALTREAL_SUM(SEXP x, Rboolean narm) ALTREP_UNIMPLEMENTED
20172044
SEXP ALTINTEGER_MIN(SEXP x, Rboolean narm) ALTREP_UNIMPLEMENTED
20182045
SEXP ALTINTEGER_MAX(SEXP x, Rboolean narm) ALTREP_UNIMPLEMENTED
20192046
SEXP ALTREAL_MIN(SEXP x, Rboolean narm) ALTREP_UNIMPLEMENTED
20202047
SEXP ALTREAL_MAX(SEXP x, Rboolean narm) ALTREP_UNIMPLEMENTED
20212048
SEXP INTEGER_MATCH(SEXP a, SEXP b, int c, SEXP d, SEXP e, Rboolean f) ALTREP_UNIMPLEMENTED
2022-
SEXP INTEGER_IS_NA(SEXP x) ALTREP_UNIMPLEMENTED
20232049
SEXP REAL_MATCH(SEXP a, SEXP b, int c, SEXP d, SEXP e, Rboolean f) ALTREP_UNIMPLEMENTED
20242050
R_xlen_t REAL_GET_REGION(SEXP sx, R_xlen_t i, R_xlen_t n, double *buf) ALTREP_UNIMPLEMENTED
2025-
int REAL_IS_SORTED(SEXP x) ALTREP_UNIMPLEMENTED
2026-
int REAL_NO_NA(SEXP x) ALTREP_UNIMPLEMENTED
2027-
SEXP REAL_IS_NA(SEXP x) ALTREP_UNIMPLEMENTED
2028-
int STRING_IS_SORTED(SEXP x) ALTREP_UNIMPLEMENTED
2029-
int STRING_NO_NA(SEXP x) ALTREP_UNIMPLEMENTED
20302051
SEXP R_compact_intrange(R_xlen_t n1, R_xlen_t n2) ALTREP_UNIMPLEMENTED
20312052
SEXP R_deferred_coerceToString(SEXP v, SEXP sp) ALTREP_UNIMPLEMENTED
20322053
SEXP R_virtrep_vec(SEXP x, SEXP y) ALTREP_UNIMPLEMENTED

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ done
6767
res=0
6868
if ! ldconfig -p | grep --quiet "libgomp.so.1"; then
6969
echo "Error: could not find OpenMP runtime library: libgomp.so.1"
70-
echo "Please install the OpenMP runtime library runtime libraries:"
70+
echo "Please install the OpenMP runtime library:"
7171
echo " On Debian based systems: apt-get install libgomp1"
7272
echo " On Oracle Linux: yum install libgomp"
7373
echo " Note: Oracle Linux 8 should contain libgomp by default"
@@ -86,7 +86,7 @@ done
8686
echo " On Oracle Linux: yum groupinstall 'Development Tools' && yum install gcc-gfortran"
8787
fi
8888
elif [[ "$OSTYPE" == "darwin"* ]]; then
89-
echo "The basic configuration of FastR was successfull."
89+
echo "FastR should not have any requirements on MacOS."
9090
echo ""
9191
echo "Note: if you intend to install R packages you may need additional dependencies."
9292
echo "The most common dependency is GFortran, which must be of version 8.3.0 or later."
@@ -104,7 +104,8 @@ done
104104
R_LIBS_USER=`"$FASTR_HOME_DIR/bin/R" --slave -e 'cat(path.expand(Sys.getenv("R_LIBS_USER")))'`
105105
if [ ! -d "$R_LIBS_USER" ]; then
106106
echo
107-
read -p "Default personal library directory ($R_LIBS_USER) does exist. Do you wish to create it? (Yy/Nn) " -n 1 -r
107+
echo "Default personal library directory ($R_LIBS_USER) does not exist."
108+
read -p "Do you wish to create it now? (Yy/Nn) " -n 1 -r
108109
echo
109110
if [[ $REPLY =~ ^[Yy]$ ]]; then
110111
echo "Creating personal library directory: $R_LIBS_USER"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
66
1+
67

com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/BasePackage.java

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import com.oracle.truffle.r.nodes.binary.BinaryBooleanNodeGen;
3636
import com.oracle.truffle.r.nodes.binary.BinaryBooleanScalarNodeGen;
3737
import com.oracle.truffle.r.nodes.binary.BinaryBooleanSpecial;
38+
import com.oracle.truffle.r.nodes.builtin.RBuiltinNode;
3839
import com.oracle.truffle.r.nodes.builtin.RBuiltinPackage;
3940
import com.oracle.truffle.r.nodes.builtin.base.ConnectionFunctions.SockSelect;
4041
import com.oracle.truffle.r.nodes.builtin.base.ConnectionFunctionsFactory.SockSelectNodeGen;
@@ -880,15 +881,56 @@ private void addGridIntrinsics() {
880881
}
881882

882883
private void addBinaryArithmetic(Class<?> builtinClass, BinaryArithmeticFactory binaryFactory, UnaryArithmeticFactory unaryFactory) {
883-
add(builtinClass, () -> BinaryArithmeticNodeGen.create(binaryFactory, unaryFactory), BinaryArithmeticSpecial.createSpecialFactory(binaryFactory, unaryFactory));
884+
add(builtinClass, new BinaryArithmeticBuiltinFactory(binaryFactory, unaryFactory), BinaryArithmeticSpecial.createSpecialFactory(binaryFactory, unaryFactory));
884885
}
885886

886887
private void addUnaryArithmetic(Class<?> builtinClass, UnaryArithmeticFactory unaryFactory) {
887-
add(builtinClass, () -> new UnaryArithmeticBuiltinNode(unaryFactory), UnaryArithmeticSpecial.createSpecialFactory(unaryFactory));
888+
add(builtinClass, new UnaryArithmeticBuiltinFactory(unaryFactory), UnaryArithmeticSpecial.createSpecialFactory(unaryFactory));
888889
}
889890

890891
private void addBinaryCompare(Class<?> builtinClass, BooleanOperationFactory factory) {
891-
add(builtinClass, () -> BinaryBooleanNodeGen.create(factory), BinaryBooleanSpecial.createSpecialFactory(factory));
892+
add(builtinClass, new BinaryCompareBuiltinFactory(factory), BinaryBooleanSpecial.createSpecialFactory(factory));
893+
}
894+
895+
private static final class BinaryArithmeticBuiltinFactory implements Supplier<RBuiltinNode> {
896+
private final BinaryArithmeticFactory binaryFactory;
897+
private final UnaryArithmeticFactory unaryFactory;
898+
899+
BinaryArithmeticBuiltinFactory(BinaryArithmeticFactory binaryFactory, UnaryArithmeticFactory unaryFactory) {
900+
this.binaryFactory = binaryFactory;
901+
this.unaryFactory = unaryFactory;
902+
}
903+
904+
@Override
905+
public RBuiltinNode get() {
906+
return BinaryArithmeticNodeGen.create(binaryFactory, unaryFactory);
907+
}
908+
}
909+
910+
private static final class UnaryArithmeticBuiltinFactory implements Supplier<RBuiltinNode> {
911+
private final UnaryArithmeticFactory unaryFactory;
912+
913+
UnaryArithmeticBuiltinFactory(UnaryArithmeticFactory unaryFactory) {
914+
this.unaryFactory = unaryFactory;
915+
}
916+
917+
@Override
918+
public RBuiltinNode get() {
919+
return new UnaryArithmeticBuiltinNode(unaryFactory);
920+
}
921+
}
922+
923+
private static final class BinaryCompareBuiltinFactory implements Supplier<RBuiltinNode> {
924+
private final BooleanOperationFactory factory;
925+
926+
BinaryCompareBuiltinFactory(BooleanOperationFactory factory) {
927+
this.factory = factory;
928+
}
929+
930+
@Override
931+
public RBuiltinNode get() {
932+
return BinaryBooleanNodeGen.create(factory);
933+
}
892934
}
893935

894936
private static void addFastPath(MaterializedFrame baseFrame, String name, FastPathFactory factory) {

com.oracle.truffle.r.test.native/packages/package.mk

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
33
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
#
55
# This code is free software; you can redistribute it and/or modify it
@@ -54,4 +54,5 @@ $(RIN_R_FILES): $(RIN_FILES)
5454

5555
clean:
5656
rm -f $(PKG_TAR) $(RIN_R_FILES)
57-
57+
$(shell find $(PACKAGE) -name '*.o' -delete)
58+
$(shell find $(PACKAGE) -name '*.so' -delete)

com.oracle.truffle.r.test.native/packages/testrffi/testrffi/R/testrffi.R

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,22 @@ rffi.populateIntVector <- function(n) {
3838
.Call("populateIntVector", as.integer(n), PACKAGE = "testrffi")
3939
}
4040

41+
rffi.populateCharacterVector <- function(n) {
42+
.Call("populateCharacterVector", as.integer(n), PACKAGE = "testrffi")
43+
}
44+
45+
rffi.populateDoubleVector <- function(n) {
46+
.Call("populateDoubleVector", as.integer(n), PACKAGE = "testrffi")
47+
}
48+
49+
rffi.populateComplexVector <- function(n) {
50+
.Call("populateComplexVector", as.integer(n), PACKAGE = "testrffi")
51+
}
52+
53+
rffi.populateRawVector <- function(n) {
54+
.Call("populateRawVector", as.integer(n), PACKAGE = "testrffi")
55+
}
56+
4157
rffi.populateLogicalVector <- function(n) {
4258
.Call("populateLogicalVector", as.integer(n), PACKAGE = "testrffi")
4359
}

com.oracle.truffle.r.test.native/packages/testrffi/testrffi/src/init.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ static const R_CallMethodDef CallEntries[] = {
5353
CALLDEF(addInt, 2),
5454
CALLDEF(addDouble, 2),
5555
CALLDEF(populateIntVector, 1),
56+
CALLDEF(populateDoubleVector, 1),
57+
CALLDEF(populateComplexVector, 1),
58+
CALLDEF(populateCharacterVector, 1),
59+
CALLDEF(populateRawVector, 1),
5660
CALLDEF(populateLogicalVector, 1),
5761
CALLDEF(createExternalPtr, 3),
5862
CALLDEF(getExternalPtrAddr, 1),

com.oracle.truffle.r.test.native/packages/testrffi/testrffi/src/testrffi.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,56 @@ SEXP populateLogicalVector(SEXP n) {
9191
return v;
9292
}
9393

94+
SEXP populateRawVector(SEXP n) {
95+
SEXP v;
96+
int intN = INTEGER_VALUE(n);
97+
PROTECT(v = allocVector(RAWSXP, intN));
98+
int i;
99+
for (i = 0; i < intN; i++) {
100+
RAW(v)[i] = i;
101+
}
102+
UNPROTECT(1);
103+
return v;
104+
}
105+
106+
SEXP populateDoubleVector(SEXP n) {
107+
SEXP v;
108+
int intN = INTEGER_VALUE(n);
109+
PROTECT(v = allocVector(REALSXP, intN));
110+
int i;
111+
for (i = 0; i < intN; i++) {
112+
REAL(v)[i] = i;
113+
}
114+
UNPROTECT(1);
115+
return v;
116+
}
117+
118+
SEXP populateComplexVector(SEXP n) {
119+
SEXP v;
120+
int intN = INTEGER_VALUE(n);
121+
PROTECT(v = allocVector(CPLXSXP, intN));
122+
int i;
123+
for (i = 0; i < intN; i++) {
124+
double d = i;
125+
COMPLEX(v)[i] = (Rcomplex) {d, d};
126+
}
127+
UNPROTECT(1);
128+
return v;
129+
}
130+
131+
SEXP populateCharacterVector(SEXP n) {
132+
SEXP v, item;
133+
int intN = INTEGER_VALUE(n);
134+
PROTECT(v = allocVector(STRSXP, intN));
135+
PROTECT(item = mkChar("A"));
136+
int i;
137+
for (i = 0; i < intN; i++) {
138+
SET_STRING_ELT(v, i, item);
139+
}
140+
UNPROTECT(2);
141+
return v;
142+
}
143+
94144
SEXP createExternalPtr(SEXP addr, SEXP tag, SEXP prot) {
95145
return R_MakeExternalPtr((void *) (long) INTEGER_VALUE(addr), tag, prot);
96146
}

com.oracle.truffle.r.test.native/packages/testrffi/testrffi/src/testrffi.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ extern SEXP addDouble(SEXP a, SEXP b);
2929

3030
extern SEXP populateIntVector(SEXP n);
3131

32+
extern SEXP populateRawVector(SEXP n);
33+
34+
extern SEXP populateCharacterVector(SEXP n);
35+
36+
extern SEXP populateComplexVector(SEXP n);
37+
38+
extern SEXP populateDoubleVector(SEXP n);
39+
3240
extern SEXP populateLogicalVector(SEXP n);
3341

3442
extern SEXP createExternalPtr(SEXP addr, SEXP tag, SEXP prot);

0 commit comments

Comments
 (0)