Skip to content

Commit f768409

Browse files
committed
[GR-24715] Implement INTEGER, REAL, RAW, LOGICAL, COMPLEX, R_CHAR upcalls as nodes.
PullRequest: fastr/2489
2 parents 4bb65dc + 820f234 commit f768409

File tree

13 files changed

+496
-80
lines changed

13 files changed

+496
-80
lines changed

com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/common/JavaUpCallsRFFIImpl.java

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@
8989
import com.oracle.truffle.r.runtime.data.RSymbol;
9090
import com.oracle.truffle.r.runtime.data.RUnboundValue;
9191
import com.oracle.truffle.r.runtime.data.RWeakRef;
92-
import com.oracle.truffle.r.runtime.data.model.RAbstractAtomicVector;
9392
import com.oracle.truffle.r.runtime.data.RStringVector;
9493
import com.oracle.truffle.r.runtime.data.model.RAbstractVector;
9594
import com.oracle.truffle.r.runtime.data.nodes.ShareObjectNode;
@@ -1488,7 +1487,7 @@ public Object R_GetConnection(int fd) {
14881487

14891488
private static RObjectDataPtr wrapString(String s) {
14901489
CharSXPWrapper v = CharSXPWrapper.create(s);
1491-
return RObjectDataPtr.get(v);
1490+
return RObjectDataPtr.getUncached(v);
14921491
}
14931492

14941493
@Override
@@ -2387,44 +2386,37 @@ public Object octsize(Object size) {
23872386

23882387
@Override
23892388
public Object FASTR_DATAPTR(Object x) {
2390-
if ((x instanceof RStringVector) || (x instanceof RList)) {
2391-
return RObjectDataPtr.get((RAbstractVector) wrapStrings(x));
2392-
}
2393-
CompilerDirectives.transferToInterpreter();
2394-
throw RError.error(RError.NO_CALLER, Message.GENERIC, "DATAPTR not implemented for type " + Utils.getTypeName(x));
2389+
throw implementedAsNode();
23952390
}
23962391

23972392
@Override
23982393
public Object INTEGER(Object x) {
2399-
// Note: there is no validation in GNU-R and so packages call this with all types of vectors
2400-
return RObjectDataPtr.get(guaranteeVectorOrNull(wrapStrings(x), RAbstractAtomicVector.class));
2394+
throw implementedAsNode();
24012395
}
24022396

24032397
@Override
24042398
public Object LOGICAL(Object x) {
2405-
return RObjectDataPtr.get(guaranteeVectorOrNull(wrapStrings(x), RLogicalVector.class));
2399+
throw implementedAsNode();
24062400
}
24072401

24082402
@Override
2409-
@TruffleBoundary
24102403
public Object REAL(Object x) {
2411-
// Note: there is no validation in GNU-R and so packages call this with all types of vectors
2412-
return RObjectDataPtr.get(guaranteeVectorOrNull(wrapStrings(x), RAbstractAtomicVector.class));
2404+
throw implementedAsNode();
24132405
}
24142406

24152407
@Override
24162408
public Object RAW(Object x) {
2417-
return RObjectDataPtr.get(guaranteeVectorOrNull(wrapStrings(x), RRawVector.class));
2409+
throw implementedAsNode();
24182410
}
24192411

24202412
@Override
24212413
public Object COMPLEX(Object x) {
2422-
return RObjectDataPtr.get(guaranteeVectorOrNull(wrapStrings(x), RComplexVector.class));
2414+
throw implementedAsNode();
24232415
}
24242416

24252417
@Override
24262418
public Object R_CHAR(Object x) {
2427-
return RObjectDataPtr.get(guaranteeVectorOrNull(wrapStrings(x), CharSXPWrapper.class));
2419+
throw implementedAsNode();
24282420
}
24292421

24302422
@Override
@@ -2447,20 +2439,6 @@ public void R_MakeActiveBinding(Object symArg, Object funArg, Object envArg) {
24472439
throw implementedAsNode();
24482440
}
24492441

2450-
private static RBaseObject guaranteeVectorOrNull(Object obj, Class<? extends RBaseObject> clazz) {
2451-
if (obj == RNull.instance) {
2452-
return RNull.instance;
2453-
}
2454-
return guaranteeInstanceOf(obj, clazz);
2455-
}
2456-
2457-
private static Object wrapStrings(Object obj) {
2458-
if (obj instanceof RStringVector) {
2459-
((RStringVector) obj).wrapStrings();
2460-
}
2461-
return obj;
2462-
}
2463-
24642442
private static JavaGDContext getJavaGDContext(RContext ctx) {
24652443
assert ctx.gridContext != null;
24662444
return (JavaGDContext) ctx.gridContext;
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 3 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 3 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 3 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
package com.oracle.truffle.r.ffi.impl.nodes;
24+
25+
import com.oracle.truffle.api.dsl.Cached;
26+
import com.oracle.truffle.api.dsl.GenerateUncached;
27+
import com.oracle.truffle.api.dsl.Specialization;
28+
import com.oracle.truffle.r.runtime.data.RComplexVector;
29+
import com.oracle.truffle.r.runtime.data.RNull;
30+
import com.oracle.truffle.r.runtime.ffi.RObjectDataPtr;
31+
32+
@GenerateUncached
33+
public abstract class COMPLEXNode extends FFIUpCallNode.Arg1 {
34+
35+
public static COMPLEXNode create() {
36+
return COMPLEXNodeGen.create();
37+
}
38+
39+
@Specialization
40+
protected RObjectDataPtr doForNull(RNull rNull,
41+
@Cached.Shared("getObjectDataPtrNode") @Cached RObjectDataPtr.GetObjectDataPtrNode getObjectDataPtrNode) {
42+
return getObjectDataPtrNode.execute(rNull);
43+
}
44+
45+
@Specialization
46+
protected RObjectDataPtr doForComplexVector(RComplexVector complexVec,
47+
@Cached.Shared("getObjectDataPtrNode") @Cached RObjectDataPtr.GetObjectDataPtrNode getObjectDataPtrNode) {
48+
return getObjectDataPtrNode.execute(complexVec);
49+
}
50+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 3 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 3 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 3 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
package com.oracle.truffle.r.ffi.impl.nodes;
24+
25+
import com.oracle.truffle.api.dsl.Cached;
26+
import com.oracle.truffle.api.dsl.Cached.Shared;
27+
import com.oracle.truffle.api.dsl.GenerateUncached;
28+
import com.oracle.truffle.api.dsl.Specialization;
29+
import com.oracle.truffle.api.profiles.ConditionProfile;
30+
import com.oracle.truffle.r.runtime.data.RList;
31+
import com.oracle.truffle.r.runtime.data.RStringVector;
32+
import com.oracle.truffle.r.runtime.ffi.RObjectDataPtr;
33+
34+
@GenerateUncached
35+
public abstract class FASTR_DATAPTRNode extends FFIUpCallNode.Arg1 {
36+
public static FASTR_DATAPTRNode create() {
37+
return FASTR_DATAPTRNodeGen.create();
38+
}
39+
40+
@Specialization
41+
protected RObjectDataPtr doForStringVector(RStringVector stringVector,
42+
@Cached ConditionProfile isNativized,
43+
@Cached ConditionProfile needsWrapping,
44+
@Shared("getObjectDataPtrNode") @Cached RObjectDataPtr.GetObjectDataPtrNode getObjectDataPtrNode) {
45+
stringVector.wrapStrings(isNativized, needsWrapping);
46+
return getObjectDataPtrNode.execute(stringVector);
47+
}
48+
49+
@Specialization
50+
protected RObjectDataPtr doForList(RList list,
51+
@Shared("getObjectDataPtrNode") @Cached RObjectDataPtr.GetObjectDataPtrNode getObjectDataPtrNode) {
52+
return getObjectDataPtrNode.execute(list);
53+
}
54+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 3 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 3 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 3 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
package com.oracle.truffle.r.ffi.impl.nodes;
24+
25+
import com.oracle.truffle.api.dsl.Cached;
26+
import com.oracle.truffle.api.dsl.Cached.Shared;
27+
import com.oracle.truffle.api.dsl.GenerateUncached;
28+
import com.oracle.truffle.api.dsl.Specialization;
29+
import com.oracle.truffle.api.profiles.ConditionProfile;
30+
import com.oracle.truffle.r.runtime.data.RNull;
31+
import com.oracle.truffle.r.runtime.data.RStringVector;
32+
import com.oracle.truffle.r.runtime.data.model.RAbstractAtomicVector;
33+
import com.oracle.truffle.r.runtime.ffi.RObjectDataPtr;
34+
35+
@GenerateUncached
36+
public abstract class INTEGERNode extends FFIUpCallNode.Arg1 {
37+
38+
public static INTEGERNode create() {
39+
return INTEGERNodeGen.create();
40+
}
41+
42+
@Specialization
43+
protected RObjectDataPtr doForNull(RNull rNull,
44+
@Shared("getObjectDataPtrNode") @Cached RObjectDataPtr.GetObjectDataPtrNode getObjectDataPtrNode) {
45+
return getObjectDataPtrNode.execute(rNull);
46+
}
47+
48+
@Specialization
49+
protected RObjectDataPtr doForAtomicVector(RAbstractAtomicVector atomicVector,
50+
@Shared("getObjectDataPtrNode") @Cached RObjectDataPtr.GetObjectDataPtrNode getObjectDataPtrNode,
51+
@Cached ConditionProfile isStringProfile,
52+
@Cached ConditionProfile isNativized,
53+
@Cached ConditionProfile needsWrapping) {
54+
if (isStringProfile.profile(atomicVector instanceof RStringVector)) {
55+
((RStringVector) atomicVector).wrapStrings(isNativized, needsWrapping);
56+
}
57+
return getObjectDataPtrNode.execute(atomicVector);
58+
}
59+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 3 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 3 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 3 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
package com.oracle.truffle.r.ffi.impl.nodes;
24+
25+
import com.oracle.truffle.api.dsl.Cached;
26+
import com.oracle.truffle.api.dsl.GenerateUncached;
27+
import com.oracle.truffle.api.dsl.Specialization;
28+
import com.oracle.truffle.r.runtime.data.RLogicalVector;
29+
import com.oracle.truffle.r.runtime.data.RNull;
30+
import com.oracle.truffle.r.runtime.ffi.RObjectDataPtr;
31+
32+
@GenerateUncached
33+
public abstract class LOGICALNode extends FFIUpCallNode.Arg1 {
34+
35+
public static LOGICALNode create() {
36+
return LOGICALNodeGen.create();
37+
}
38+
39+
@Specialization
40+
protected RObjectDataPtr doForNull(RNull rNull,
41+
@Cached.Shared("getObjectDataPtrNode") @Cached RObjectDataPtr.GetObjectDataPtrNode getObjectDataPtrNode) {
42+
return getObjectDataPtrNode.execute(rNull);
43+
}
44+
45+
@Specialization
46+
protected RObjectDataPtr doForLogicalVector(RLogicalVector logicalVec,
47+
@Cached.Shared("getObjectDataPtrNode") @Cached RObjectDataPtr.GetObjectDataPtrNode getObjectDataPtrNode) {
48+
return getObjectDataPtrNode.execute(logicalVec);
49+
}
50+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 3 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 3 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 3 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
package com.oracle.truffle.r.ffi.impl.nodes;
24+
25+
import com.oracle.truffle.api.dsl.Cached;
26+
import com.oracle.truffle.api.dsl.GenerateUncached;
27+
import com.oracle.truffle.api.dsl.Specialization;
28+
import com.oracle.truffle.r.runtime.data.RNull;
29+
import com.oracle.truffle.r.runtime.data.RRawVector;
30+
import com.oracle.truffle.r.runtime.ffi.RObjectDataPtr;
31+
32+
@GenerateUncached
33+
public abstract class RAWNode extends FFIUpCallNode.Arg1 {
34+
public static RAWNode create() {
35+
return RAWNodeGen.create();
36+
}
37+
38+
@Specialization
39+
protected RObjectDataPtr doForNull(RNull rNull,
40+
@Cached.Shared("getObjectDataPtrNode") @Cached RObjectDataPtr.GetObjectDataPtrNode getObjectDataPtrNode) {
41+
return getObjectDataPtrNode.execute(rNull);
42+
}
43+
44+
@Specialization
45+
protected RObjectDataPtr doForRawVector(RRawVector rawVector,
46+
@Cached.Shared("getObjectDataPtrNode") @Cached RObjectDataPtr.GetObjectDataPtrNode getObjectDataPtrNode) {
47+
return getObjectDataPtrNode.execute(rawVector);
48+
}
49+
}

0 commit comments

Comments
 (0)