Skip to content

Commit a66adb0

Browse files
committed
Convert HashSymbolNode to DSL inlinable
1 parent 396f3df commit a66adb0

File tree

4 files changed

+16
-11
lines changed

4 files changed

+16
-11
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ protected static RubyBignum coerceRubyBignum(RubyBignum value) {
4545

4646
@Specialization(guards = "!isRubyInteger(object)")
4747
protected static Object coerceObject(Node node, Object object,
48-
@Cached DispatchNode toIntNode) {
48+
@Cached(inline = false) DispatchNode toIntNode) {
4949
return toIntNode.call(coreLibrary(node).truffleTypeModule, "rb_to_int_fallback", object);
5050
}
5151
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,14 @@ protected static int hashImmutableString(Node node, ImmutableRubyString value,
111111
}
112112

113113
@Specialization
114-
protected static int hashSymbol(RubySymbol value,
114+
protected static int hashSymbol(Node node, RubySymbol value,
115115
@Cached SymbolNodes.HashSymbolNode symbolHashNode) {
116-
return (int) symbolHashNode.execute(value);
116+
return (int) symbolHashNode.execute(node, value);
117117
}
118118

119119
@Fallback
120120
protected static int hashOther(Node node, Object value,
121-
@Cached DispatchNode callHash,
121+
@Cached(inline = false) DispatchNode callHash,
122122
@Cached HashCastResultNode cast) {
123123
return cast.execute(node, callHash.call(value, "hash"));
124124
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,7 @@ protected static long hashImmutableString(ImmutableRubyString value,
896896
@Specialization
897897
protected long hashSymbol(RubySymbol value,
898898
@Cached SymbolNodes.HashSymbolNode symbolHashNode) {
899-
return symbolHashNode.execute(value);
899+
return symbolHashNode.execute(this, value);
900900
}
901901

902902
// Default hash for Kernel#hash, can be overwritten by defining a #hash method

src/main/java/org/truffleruby/core/symbol/SymbolNodes.java

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

12+
import com.oracle.truffle.api.dsl.GenerateCached;
13+
import com.oracle.truffle.api.dsl.GenerateInline;
1214
import com.oracle.truffle.api.dsl.GenerateUncached;
1315
import com.oracle.truffle.api.dsl.ImportStatic;
1416
import com.oracle.truffle.api.frame.Frame;
17+
import com.oracle.truffle.api.nodes.Node;
1518
import org.graalvm.collections.Pair;
1619
import org.truffleruby.RubyContext;
1720
import org.truffleruby.RubyLanguage;
@@ -80,24 +83,26 @@ protected boolean equal(RubySymbol a, Object b) {
8083
}
8184

8285
@GenerateUncached
86+
@GenerateInline
87+
@GenerateCached(false)
8388
public abstract static class HashSymbolNode extends RubyBaseNode {
8489

85-
public abstract long execute(RubySymbol rubySymbol);
90+
public abstract long execute(Node node, RubySymbol rubySymbol);
8691

8792
// Cannot cache a Symbol's hash while pre-initializing, as it will change in SymbolTable#rehash()
8893
@Specialization(
8994
guards = { "isSingleContext()", "symbol == cachedSymbol", "!preInitializing" },
9095
limit = "1")
91-
protected long hashCached(RubySymbol symbol,
96+
protected static long hashCached(Node node, RubySymbol symbol,
9297
@Cached(value = "isPreInitializing(getContext())") boolean preInitializing,
9398
@Cached(value = "symbol") RubySymbol cachedSymbol,
94-
@Cached(value = "hash(cachedSymbol)") long cachedHash) {
99+
@Cached(value = "hash(node, cachedSymbol)") long cachedHash) {
95100
return cachedHash;
96101
}
97102

98103
@Specialization(replaces = "hashCached")
99-
protected long hash(RubySymbol symbol) {
100-
return symbol.computeHashCode(getContext().getHashing());
104+
protected static long hash(Node node, RubySymbol symbol) {
105+
return symbol.computeHashCode(getContext(node).getHashing());
101106
}
102107

103108
protected boolean isPreInitializing(RubyContext context) {
@@ -117,7 +122,7 @@ public static HashNode create() {
117122
@Specialization
118123
protected long hash(RubySymbol symbol,
119124
@Cached HashSymbolNode hash) {
120-
return hash.execute(symbol);
125+
return hash.execute(this, symbol);
121126
}
122127
}
123128

0 commit comments

Comments
 (0)