Skip to content

Commit 3307480

Browse files
author
Pavel Marek
committed
VectorDataLibrary.materializeCharSXPStorage throws UnsupportedMessageException by default
(cherry picked from commit 19ec7c6)
1 parent 8af57c0 commit 3307480

File tree

5 files changed

+41
-12
lines changed

5 files changed

+41
-12
lines changed

com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nodes/AsCharNode.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.oracle.truffle.api.dsl.Fallback;
2727
import com.oracle.truffle.api.dsl.Specialization;
2828
import com.oracle.truffle.api.dsl.TypeSystemReference;
29+
import com.oracle.truffle.api.interop.UnsupportedMessageException;
2930
import com.oracle.truffle.api.library.CachedLibrary;
3031
import com.oracle.truffle.api.profiles.ConditionProfile;
3132
import com.oracle.truffle.r.nodes.unary.CastStringNode;
@@ -60,7 +61,12 @@ protected CharSXPWrapper asChar(RStringVector obj,
6061
if (zeroLengthProfile.profile(obj.getLength() == 0)) {
6162
return CharSXPWrapper_NA;
6263
} else {
63-
Object newCharSXPData = dataLib.materializeCharSXPStorage(obj.getData());
64+
Object newCharSXPData = null;
65+
try {
66+
newCharSXPData = dataLib.materializeCharSXPStorage(obj.getData());
67+
} catch (UnsupportedMessageException e) {
68+
throw RInternalError.shouldNotReachHere(e);
69+
}
6470
obj.setData(newCharSXPData);
6571
CharSXPWrapper result = dataLib.getCharSXPAt(obj.getData(), 0);
6672
return naProfile.profile(RRuntime.isNA(result.getContents())) ? CharSXPWrapper_NA : result;

com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nodes/SetStringEltNode.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424

2525
import com.oracle.truffle.api.dsl.GenerateUncached;
2626
import com.oracle.truffle.api.dsl.Specialization;
27+
import com.oracle.truffle.api.interop.UnsupportedMessageException;
2728
import com.oracle.truffle.api.library.CachedLibrary;
29+
import com.oracle.truffle.r.runtime.RInternalError;
2830
import com.oracle.truffle.r.runtime.data.CharSXPWrapper;
2931
import com.oracle.truffle.r.runtime.data.RStringVector;
3032
import com.oracle.truffle.r.runtime.data.VectorDataLibrary;
@@ -38,7 +40,12 @@ public static SetStringEltNode create() {
3840
@Specialization
3941
Object doIt(RStringVector vector, long index, CharSXPWrapper element,
4042
@CachedLibrary(limit = "getTypedVectorDataLibraryCacheSize()") VectorDataLibrary dataLibrary) {
41-
Object newCharSXPData = dataLibrary.materializeCharSXPStorage(vector.getData());
43+
Object newCharSXPData = null;
44+
try {
45+
newCharSXPData = dataLibrary.materializeCharSXPStorage(vector.getData());
46+
} catch (UnsupportedMessageException e) {
47+
throw RInternalError.shouldNotReachHere(e);
48+
}
4249
vector.setData(newCharSXPData);
4350
dataLibrary.setCharSXPAt(vector.getData(), (int) index, element);
4451
return null;

com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nodes/StringEltNode.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@
2525
import com.oracle.truffle.api.CompilerDirectives;
2626
import com.oracle.truffle.api.dsl.GenerateUncached;
2727
import com.oracle.truffle.api.dsl.Specialization;
28+
import com.oracle.truffle.api.interop.UnsupportedMessageException;
2829
import com.oracle.truffle.api.library.CachedLibrary;
2930
import com.oracle.truffle.r.runtime.RError;
31+
import com.oracle.truffle.r.runtime.RInternalError;
3032
import com.oracle.truffle.r.runtime.data.RStringVector;
3133
import com.oracle.truffle.r.runtime.data.VectorDataLibrary;
3234

@@ -40,7 +42,12 @@ public static StringEltNode create() {
4042
Object doStringVector(RStringVector stringVector, long index,
4143
@CachedLibrary(limit = "getTypedVectorDataLibraryCacheSize()") VectorDataLibrary genericDataLib,
4244
@CachedLibrary("stringVector.getData()") VectorDataLibrary stringVecDataLib) {
43-
Object newCharSXPData = stringVecDataLib.materializeCharSXPStorage(stringVector.getData());
45+
Object newCharSXPData = null;
46+
try {
47+
newCharSXPData = stringVecDataLib.materializeCharSXPStorage(stringVector.getData());
48+
} catch (UnsupportedMessageException e) {
49+
throw RInternalError.shouldNotReachHere(e);
50+
}
4451
stringVector.setData(newCharSXPData);
4552
if (index > Integer.MAX_VALUE) {
4653
CompilerDirectives.transferToInterpreter();

com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RStringVector.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,12 @@ public void wrapStrings() {
426426
public void wrapStrings(ConditionProfile isNativized, ConditionProfile isWrapped) {
427427
if (isNativized.profile(!isNativized())) {
428428
VectorDataLibrary dataLib = getUncachedDataLib();
429-
Object newCharSXPData = dataLib.materializeCharSXPStorage(data);
429+
Object newCharSXPData = null;
430+
try {
431+
newCharSXPData = dataLib.materializeCharSXPStorage(data);
432+
} catch (UnsupportedMessageException e) {
433+
throw RInternalError.shouldNotReachHere(e);
434+
}
430435
if (isWrapped.profile(newCharSXPData == data)) {
431436
return;
432437
}

com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/VectorDataLibrary.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,15 @@ public boolean isWriteable(Object data) {
151151
* {@link VectorDataLibrary}. Moreover, the receiver should transform into an object containing
152152
* {@link CharSXPWrapper} data, if possible.
153153
*
154+
* Must be implemented when {@code getType() == Character}.
155+
*
154156
* If the result is the same as the {@code data}, it means that the receiver already has
155157
* materialized CharSXP storage.
156158
*
157159
* @see #materialize(Object)
158160
*/
159-
public Object materializeCharSXPStorage(Object data) {
160-
return null;
161+
public Object materializeCharSXPStorage(Object data) throws UnsupportedMessageException {
162+
throw UnsupportedMessageException.create();
161163
}
162164

163165
/**
@@ -1058,15 +1060,15 @@ public void setString(Object receiver, RandomAccessWriteIterator it, int index,
10581060
}
10591061

10601062
public void setCharSXPAt(Object receiver, int index, CharSXPWrapper value) {
1061-
throw notWriteableError(receiver, "setStringAt");
1063+
throw notWriteableError(receiver, "setCharSXPAt");
10621064
}
10631065

10641066
public void setNextCharSXP(Object receiver, SeqWriteIterator it, CharSXPWrapper value) {
1065-
throw notWriteableError(receiver, "setNextString");
1067+
throw notWriteableError(receiver, "setNextCharSXP");
10661068
}
10671069

10681070
public void setCharSXP(Object receiver, RandomAccessWriteIterator it, int index, CharSXPWrapper value) {
1069-
throw notWriteableError(receiver, "setString");
1071+
throw notWriteableError(receiver, "setCharSXP");
10701072
}
10711073

10721074
private final ConditionProfile emptyStringProfile = ConditionProfile.createBinaryProfile();
@@ -1699,9 +1701,11 @@ public Object materialize(Object data) {
16991701
@Override
17001702
public Object materializeCharSXPStorage(Object data) {
17011703
verifyIfSlowAssertsEnabled(data);
1702-
Object result = delegate.materializeCharSXPStorage(data);
1703-
if (result == null) {
1704-
throw RInternalError.shouldNotReachHere("materializeCharSXPStorage message not implemented for " + delegate.toString());
1704+
Object result = null;
1705+
try {
1706+
result = delegate.materializeCharSXPStorage(data);
1707+
} catch (UnsupportedMessageException e) {
1708+
throw RInternalError.shouldNotReachHere(e);
17051709
}
17061710
assert result != null;
17071711
return result;

0 commit comments

Comments
 (0)