Skip to content

Commit 98d791a

Browse files
committed
Convert HashCastResultNode to DSL inlinable
1 parent dbb0091 commit 98d791a

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

src/main/java/org/truffleruby/core/hash/HashingNodes.java

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ public static ToHashByHashCode create() {
6969

7070
public abstract int execute(Node node, Object key);
7171

72+
public final int executeCached(Object key) {
73+
return execute(this, key);
74+
}
75+
7276
@Specialization
7377
protected static int hashBoolean(Node node, boolean value) {
7478
return (int) HashOperations.hashBoolean(value, getContext(node), node);
@@ -113,10 +117,10 @@ protected static int hashSymbol(RubySymbol value,
113117
}
114118

115119
@Fallback
116-
protected static int hashOther(Object value,
120+
protected static int hashOther(Node node, Object value,
117121
@Cached DispatchNode callHash,
118122
@Cached HashCastResultNode cast) {
119-
return cast.execute(callHash.call(value, "hash"));
123+
return cast.execute(node, callHash.call(value, "hash"));
120124
}
121125
}
122126

@@ -133,35 +137,41 @@ public static ToHashByIdentity getUncached() {
133137
protected int toHashByIdentity(Object hashed,
134138
@Cached ObjectIDNode objectIDNode,
135139
@Cached HashCastResultNode hashCastResultNode) {
136-
return hashCastResultNode.execute(objectIDNode.execute(hashed));
140+
return hashCastResultNode.execute(this, objectIDNode.execute(hashed));
137141
}
138142
}
139143

140144
@GenerateUncached
145+
@GenerateInline(inlineByDefault = true)
141146
public abstract static class HashCastResultNode extends RubyBaseNode {
142147

143-
public abstract int execute(Object key);
148+
public abstract int execute(Node node, Object key);
149+
150+
public final int executeCached(Object key) {
151+
return execute(null, key);
152+
}
144153

145154
@Specialization
146-
protected int castInt(int hashed) {
155+
protected static int castInt(int hashed) {
147156
return hashed;
148157
}
149158

150159
@Specialization
151-
protected int castLong(long hashed) {
160+
protected static int castLong(long hashed) {
152161
return (int) hashed;
153162
}
154163

155164
@Specialization
156-
protected int castBignum(RubyBignum hashed) {
165+
protected static int castBignum(RubyBignum hashed) {
157166
return BigIntegerOps.hashCode(hashed);
158167
}
159168

160169
@Specialization(guards = "!isRubyInteger(hashed)")
161-
protected int castOther(Object hashed,
170+
protected static int castOther(Object hashed,
162171
@Cached ToRubyIntegerNode toRubyInteger,
163-
@Cached HashCastResultNode hashCastResult) {
164-
return hashCastResult.execute(toRubyInteger.execute(hashed));
172+
//recursive inlining is not supported
173+
@Cached(inline = false) HashCastResultNode hashCastResult) {
174+
return hashCastResult.executeCached(toRubyInteger.execute(hashed));
165175
}
166176
}
167177
}

src/main/java/org/truffleruby/core/hash/library/PackedHashStoreLibrary.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ private int hash(Object key) {
538538
CompilerDirectives.transferToInterpreterAndInvalidate();
539539
hashNode = insert(HashingNodes.ToHashByHashCode.create());
540540
}
541-
return hashNode.execute(this, key);
541+
return hashNode.executeCached(key);
542542
}
543543

544544
private boolean callEqual(Object receiver, Object key) {

0 commit comments

Comments
 (0)