Skip to content

Commit 5106fbc

Browse files
committed
Convert HashCastNode to DSL inlinable
1 parent 59e8390 commit 5106fbc

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ Object sendWithoutCExtLock(VirtualFrame frame, Object receiver, RubySymbol metho
386386
Object[] args = unwrapCArrayNode.execute(argv);
387387

388388
// Remove empty kwargs in the caller, so the callee does not need to care about this special case
389-
final RubyHash keywords = hashCastNode.execute(ArrayUtils.getLast(args));
389+
final RubyHash keywords = hashCastNode.execute(this, ArrayUtils.getLast(args));
390390
if (emptyProfile.profile(this, keywords.empty())) {
391391
args = LiteralCallNode.removeEmptyKeywordArguments(args);
392392
return sendWithoutCExtLock(frame, receiver, method, block, EmptyArgumentsDescriptor.INSTANCE, args,
@@ -424,7 +424,7 @@ Object sendWithoutCExtLock(VirtualFrame frame, Object receiver, RubySymbol metho
424424
Object[] args = unwrapCArrayNode.execute(argv);
425425

426426
// Remove empty kwargs in the caller, so the callee does not need to care about this special case
427-
final RubyHash keywords = hashCastNode.execute(ArrayUtils.getLast(args));
427+
final RubyHash keywords = hashCastNode.execute(this, ArrayUtils.getLast(args));
428428
if (emptyProfile.profile(this, keywords.empty())) {
429429
args = LiteralCallNode.removeEmptyKeywordArguments(args);
430430
return sendWithoutCExtLock(frame, receiver, method, block, EmptyArgumentsDescriptor.INSTANCE, args,

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

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
*/
1010
package org.truffleruby.core.cast;
1111

12+
import com.oracle.truffle.api.dsl.GenerateCached;
13+
import com.oracle.truffle.api.dsl.GenerateInline;
14+
import com.oracle.truffle.api.nodes.Node;
1215
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
1316
import org.truffleruby.core.hash.RubyHash;
1417
import org.truffleruby.language.RubyBaseNode;
@@ -25,33 +28,35 @@
2528

2629
import static org.truffleruby.language.dispatch.DispatchConfiguration.PRIVATE_RETURN_MISSING;
2730

31+
@GenerateCached(false)
32+
@GenerateInline
2833
public abstract class HashCastNode extends RubyBaseNode {
2934

30-
public abstract RubyHash execute(Object value);
35+
public abstract RubyHash execute(Node node, Object value);
3136

3237
@Specialization
33-
RubyHash castHash(RubyHash hash) {
38+
static RubyHash castHash(RubyHash hash) {
3439
return hash;
3540
}
3641

3742
@Specialization(guards = "!isRubyHash(object)")
38-
RubyHash cast(Object object,
43+
static RubyHash cast(Node node, Object object,
3944
@Cached InlinedBranchProfile errorProfile,
40-
@Cached DispatchNode toHashNode) {
45+
@Cached(inline = false) DispatchNode toHashNode) {
4146
final Object result = toHashNode.call(PRIVATE_RETURN_MISSING, object, "to_hash");
4247

4348
if (result == DispatchNode.MISSING) {
44-
errorProfile.enter(this);
49+
errorProfile.enter(node);
4550
throw new RaiseException(
46-
getContext(),
47-
coreExceptions().typeErrorNoImplicitConversion(object, "Hash", this));
51+
getContext(node),
52+
coreExceptions(node).typeErrorNoImplicitConversion(object, "Hash", node));
4853
}
4954

5055
if (!RubyGuards.isRubyHash(result)) {
51-
errorProfile.enter(this);
56+
errorProfile.enter(node);
5257
throw new RaiseException(
53-
getContext(),
54-
coreExceptions().typeErrorCantConvertTo(object, "Hash", "to_hash", result, this));
58+
getContext(node),
59+
coreExceptions(node).typeErrorCantConvertTo(object, "Hash", "to_hash", result, node));
5560
}
5661

5762
return (RubyHash) result;
@@ -66,7 +71,7 @@ public abstract static class HashCastASTNode extends RubyContextSourceNode {
6671
@Specialization
6772
RubyHash cast(Object object,
6873
@Cached HashCastNode hashCastNode) {
69-
return hashCastNode.execute(object);
74+
return hashCastNode.execute(this, object);
7075

7176
}
7277

0 commit comments

Comments
 (0)