Skip to content

Commit 40638ed

Browse files
committed
TranslateInteropExceptionNode supports DSL inlining
1 parent 9fe7929 commit 40638ed

22 files changed

+405
-354
lines changed

src/main/java/org/truffleruby/cext/CExtNodes.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ protected Object callWithCExtLockAndFrame(
200200
MutexOperations.lockInternal(getContext(), lock, this);
201201
}
202202
try {
203-
return InteropNodes.execute(receiver, args, receivers, translateInteropExceptionNode);
203+
return InteropNodes.execute(this, receiver, args, receivers, translateInteropExceptionNode);
204204
} finally {
205205
runMarksNode.execute(extensionStack);
206206
if (!owned) {
@@ -209,7 +209,7 @@ protected Object callWithCExtLockAndFrame(
209209
}
210210
} else {
211211
try {
212-
return InteropNodes.execute(receiver, args, receivers, translateInteropExceptionNode);
212+
return InteropNodes.execute(this, receiver, args, receivers, translateInteropExceptionNode);
213213
} finally {
214214
runMarksNode.execute(extensionStack);
215215
}
@@ -252,7 +252,7 @@ protected Object callWithCExtLockAndFrame(
252252
}
253253
try {
254254
return unwrapNode.execute(this,
255-
InteropNodes.execute(receiver, args, receivers, translateInteropExceptionNode));
255+
InteropNodes.execute(this, receiver, args, receivers, translateInteropExceptionNode));
256256
} finally {
257257
runMarksNode.execute(extensionStack);
258258
if (!owned) {
@@ -262,7 +262,7 @@ protected Object callWithCExtLockAndFrame(
262262
} else {
263263
try {
264264
return unwrapNode.execute(this,
265-
InteropNodes.execute(receiver, args, receivers, translateInteropExceptionNode));
265+
InteropNodes.execute(this, receiver, args, receivers, translateInteropExceptionNode));
266266
} finally {
267267
runMarksNode.execute(extensionStack);
268268
}
@@ -299,14 +299,14 @@ protected Object callWithCExtLock(Object receiver, RubyArray argsArray,
299299
MutexOperations.lockInternal(getContext(), lock, this);
300300
}
301301
try {
302-
return InteropNodes.execute(receiver, args, receivers, translateInteropExceptionNode);
302+
return InteropNodes.execute(this, receiver, args, receivers, translateInteropExceptionNode);
303303
} finally {
304304
if (!owned) {
305305
MutexOperations.unlockInternal(lock);
306306
}
307307
}
308308
} else {
309-
return InteropNodes.execute(receiver, args, receivers, translateInteropExceptionNode);
309+
return InteropNodes.execute(this, receiver, args, receivers, translateInteropExceptionNode);
310310
}
311311

312312
}
@@ -1613,12 +1613,13 @@ protected Object raiseException(CapturedException captured,
16131613
public abstract static class RbTrMbcCaseFoldNode extends CoreMethodArrayArgumentsNode {
16141614

16151615
@Specialization(guards = "strings.isRubyString(string)", limit = "getCacheLimit()")
1616-
protected Object rbTrEncMbcCaseFold(int flags, Object string, Object advance_p, Object p,
1616+
protected static Object rbTrEncMbcCaseFold(int flags, Object string, Object advance_p, Object p,
16171617
@Cached RubyStringLibrary strings,
16181618
@CachedLibrary("advance_p") InteropLibrary receivers,
16191619
@Cached TranslateInteropExceptionNode translateInteropExceptionNode,
16201620
@Cached TruffleString.FromByteArrayNode fromByteArrayNode,
1621-
@Cached TruffleString.GetInternalByteArrayNode byteArrayNode) {
1621+
@Cached TruffleString.GetInternalByteArrayNode byteArrayNode,
1622+
@Bind("this") Node node) {
16221623
var tstring = strings.getTString(string);
16231624
var encoding = strings.getEncoding(string);
16241625
var bytes = TStringUtils.getBytesOrFail(tstring, encoding, byteArrayNode);
@@ -1629,15 +1630,15 @@ protected Object rbTrEncMbcCaseFold(int flags, Object string, Object advance_p,
16291630

16301631
final int resultLength = encoding.jcoding.mbcCaseFold(flags, bytes, intHolder, bytes.length, to);
16311632

1632-
InteropNodes.execute(advance_p, new Object[]{ p, intHolder.value }, receivers,
1633+
InteropNodes.execute(node, advance_p, new Object[]{ p, intHolder.value }, receivers,
16331634
translateInteropExceptionNode);
16341635

16351636
final byte[] result = new byte[resultLength];
16361637
if (resultLength > 0) {
16371638
System.arraycopy(to, 0, result, 0, resultLength);
16381639
}
16391640

1640-
return createString(fromByteArrayNode, result, Encodings.US_ASCII);
1641+
return createString(node, fromByteArrayNode, result, Encodings.US_ASCII);
16411642
}
16421643

16431644
protected int getCacheLimit() {

src/main/java/org/truffleruby/cext/DataHolder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ protected String toDisplayString(boolean allowSideEffects) {
8383
try {
8484
return "DATA_HOLDER: " + interop.asString(interop.toDisplayString(pointer, allowSideEffects));
8585
} catch (UnsupportedMessageException e) {
86-
throw TranslateInteropExceptionNode.getUncached().execute(e);
86+
throw TranslateInteropExceptionNode.executeUncached(e);
8787
}
8888
}
8989
}

src/main/java/org/truffleruby/cext/ValueWrapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ protected String toDisplayString(boolean allowSideEffects) {
8989
try {
9090
return "VALUE: " + interop.asString(interop.toDisplayString(object, allowSideEffects));
9191
} catch (UnsupportedMessageException e) {
92-
throw TranslateInteropExceptionNode.getUncached().execute(e);
92+
throw TranslateInteropExceptionNode.executeUncached(e);
9393
}
9494
} else {
9595
return "VALUE: " + toString();

src/main/java/org/truffleruby/core/VMPrimitiveNodes.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import java.util.stream.Stream;
4343

4444
import com.oracle.truffle.api.TruffleStackTrace;
45+
import com.oracle.truffle.api.dsl.Bind;
4546
import com.oracle.truffle.api.interop.InteropLibrary;
4647
import com.oracle.truffle.api.interop.UnsupportedMessageException;
4748
import com.oracle.truffle.api.library.CachedLibrary;
@@ -235,13 +236,14 @@ protected Object vmRaiseException(RubyException exception,
235236
}
236237

237238
@Specialization(guards = "!isRubyException(exception)", limit = "getInteropCacheLimit()")
238-
protected Object foreignException(Object exception,
239+
protected static Object foreignException(Object exception,
239240
@CachedLibrary("exception") InteropLibrary interopLibrary,
240-
@Cached TranslateInteropExceptionNode translateInteropExceptionNode) {
241+
@Cached TranslateInteropExceptionNode translateInteropExceptionNode,
242+
@Bind("this") Node node) {
241243
try {
242244
throw interopLibrary.throwException(exception);
243245
} catch (UnsupportedMessageException e) {
244-
throw translateInteropExceptionNode.execute(e);
246+
throw translateInteropExceptionNode.execute(node, e);
245247
}
246248
}
247249

src/main/java/org/truffleruby/core/basicobject/BasicObjectNodes.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,15 @@ protected long objectID(RubyDynamicObject object,
238238
}
239239

240240
@Specialization(guards = "isForeignObject(value)", limit = "getInteropCacheLimit()")
241-
protected int objectIDForeign(Object value,
241+
protected static int objectIDForeign(Object value,
242242
@CachedLibrary("value") InteropLibrary interop,
243-
@Cached TranslateInteropExceptionNode translateInteropException) {
243+
@Cached TranslateInteropExceptionNode translateInteropException,
244+
@Bind("this") Node node) {
244245
if (interop.hasIdentity(value)) {
245246
try {
246247
return interop.identityHashCode(value);
247248
} catch (UnsupportedMessageException e) {
248-
throw translateInteropException.execute(e);
249+
throw translateInteropException.execute(node, e);
249250
}
250251
} else {
251252
return System.identityHashCode(value);

src/main/java/org/truffleruby/core/cast/NameToJavaStringNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ protected static String nameToJavaString(String value) {
6161
@Specialization(guards = { "!isString(object)", "!isRubySymbol(object)", "isNotRubyString(object)" })
6262
protected static String nameToJavaString(Node node, Object object,
6363
@Cached InlinedBranchProfile errorProfile,
64-
@Cached DispatchNode toStr,
64+
@Cached(inline = false) DispatchNode toStr,
6565
@Cached @Exclusive RubyStringLibrary libString,
6666
@Cached @Exclusive ToJavaStringNode toJavaStringNode) {
6767
final Object coerced;

src/main/java/org/truffleruby/core/format/read/array/ReadCStringNode.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ protected Object read(Object pointer,
3838
@Cached TranslateInteropExceptionNode translateInteropExceptionNode,
3939
@CachedLibrary("stringReader") InteropLibrary stringReaders) {
4040
Object string = unwrapNode.execute(this, InteropNodes.execute(
41+
this,
4142
stringReader,
4243
new Object[]{ pointer },
4344
stringReaders,

src/main/java/org/truffleruby/core/kernel/KernelNodes.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -916,14 +916,15 @@ protected int hashRubyDynamicObject(RubyDynamicObject value) {
916916
}
917917

918918
@Specialization(guards = "isForeignObject(value)", limit = "getInteropCacheLimit()")
919-
protected int hashForeign(Object value,
919+
protected static int hashForeign(Object value,
920920
@CachedLibrary("value") InteropLibrary interop,
921-
@Cached TranslateInteropExceptionNode translateInteropException) {
921+
@Cached TranslateInteropExceptionNode translateInteropException,
922+
@Bind("this") Node node) {
922923
if (interop.hasIdentity(value)) {
923924
try {
924925
return interop.identityHashCode(value);
925926
} catch (UnsupportedMessageException e) {
926-
throw translateInteropException.execute(e);
927+
throw translateInteropException.execute(node, e);
927928
}
928929
} else {
929930
return System.identityHashCode(value);

src/main/java/org/truffleruby/core/module/ModuleNodes.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,7 +1159,7 @@ public abstract static class ConstSourceLocationNode extends RubyBaseNode {
11591159
@Specialization(guards = "strings.isRubyString(name)", limit = "1")
11601160
@TruffleBoundary
11611161
protected static Object constSourceLocation(Node node, RubyModule module, Object name, boolean inherit,
1162-
@Cached @Shared TruffleString.FromJavaStringNode fromJavaStringNode,
1162+
@Cached(inline = false) @Shared TruffleString.FromJavaStringNode fromJavaStringNode,
11631163
@Cached RubyStringLibrary strings) {
11641164
final ConstantLookupResult lookupResult = ModuleOperations
11651165
.lookupScopedConstant(getContext(node), module, RubyGuards.getJavaString(name), inherit, node,
@@ -1171,7 +1171,7 @@ protected static Object constSourceLocation(Node node, RubyModule module, Object
11711171
@Specialization
11721172
@TruffleBoundary
11731173
protected static Object constSourceLocation(Node node, RubyModule module, RubySymbol name, boolean inherit,
1174-
@Cached @Shared TruffleString.FromJavaStringNode fromJavaStringNode) {
1174+
@Cached(inline = false) @Shared TruffleString.FromJavaStringNode fromJavaStringNode) {
11751175
final ConstantLookupResult lookupResult = ModuleOperations
11761176
.lookupConstantWithInherit(getContext(node), module, name.getString(), inherit, node, true);
11771177

src/main/java/org/truffleruby/core/regexp/TRegexCache.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import org.truffleruby.core.string.TStringBuilder;
2525
import org.truffleruby.core.string.TStringWithEncoding;
2626
import org.truffleruby.interop.InteropNodes;
27-
import org.truffleruby.interop.TranslateInteropExceptionNode;
27+
import org.truffleruby.interop.TranslateInteropExceptionNodeGen;
2828
import org.truffleruby.language.Nil;
2929
import org.truffleruby.language.control.DeferredRaiseException;
3030

@@ -116,10 +116,11 @@ public Object compile(RubyContext context, RubyRegexp regexp, boolean atStart, R
116116

117117
private static boolean isBacktracking(Object tregex) {
118118
return (boolean) InteropNodes.readMember(
119+
null,
119120
InteropLibrary.getUncached(),
120121
tregex,
121122
"isBacktracking",
122-
TranslateInteropExceptionNode.getUncached());
123+
TranslateInteropExceptionNodeGen.getUncached());
123124
}
124125

125126
public static String toTRegexEncoding(RubyEncoding encoding) {

0 commit comments

Comments
 (0)