Skip to content

Commit 6f78546

Browse files
committed
ReferenceEqualNode is DSL inlinable node
1 parent dc9809e commit 6f78546

File tree

12 files changed

+57
-44
lines changed

12 files changed

+57
-44
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ protected Object doCatch(Object tag, RubyProc block,
119119
return yieldNode.yield(block, tag);
120120
} catch (ThrowException e) {
121121
catchProfile.enter(this);
122-
if (matchProfile.profile(this, referenceEqualNode.execute(e.getTag(), tag))) {
122+
if (matchProfile.profile(this, referenceEqualNode.execute(this, e.getTag(), tag))) {
123123
return e.getValue();
124124
} else {
125125
throw e;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public abstract static class BasicObjectEqualNode extends CoreMethodArrayArgumen
128128
@Specialization
129129
protected boolean equal(Object a, Object b,
130130
@Cached ReferenceEqualNode referenceEqualNode) {
131-
return referenceEqualNode.execute(a, b);
131+
return referenceEqualNode.execute(this, a, b);
132132
}
133133
}
134134

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

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,62 +9,71 @@
99
*/
1010
package org.truffleruby.core.basicobject;
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.Specialization;
1416
import com.oracle.truffle.api.interop.InteropLibrary;
1517
import com.oracle.truffle.api.library.CachedLibrary;
18+
import com.oracle.truffle.api.nodes.Node;
1619
import org.truffleruby.language.ImmutableRubyObject;
1720
import org.truffleruby.language.RubyBaseNode;
1821
import org.truffleruby.language.RubyDynamicObject;
1922
import org.truffleruby.language.RubyGuards;
2023

2124
@GenerateUncached
25+
@GenerateCached(false)
26+
@GenerateInline
2227
public abstract class ReferenceEqualNode extends RubyBaseNode {
2328

24-
public abstract boolean execute(Object a, Object b);
29+
public static boolean executeUncached(Object a, Object b) {
30+
return ReferenceEqualNodeGen.getUncached().execute(null, a, b);
31+
}
32+
33+
public abstract boolean execute(Node node, Object a, Object b);
2534

2635
@Specialization
27-
protected boolean equal(boolean a, boolean b) {
36+
protected static boolean equal(boolean a, boolean b) {
2837
return a == b;
2938
}
3039

3140
@Specialization
32-
protected boolean equal(int a, int b) {
41+
protected static boolean equal(int a, int b) {
3342
return a == b;
3443
}
3544

3645
@Specialization
37-
protected boolean equal(long a, long b) {
46+
protected static boolean equal(long a, long b) {
3847
return a == b;
3948
}
4049

4150
@Specialization
42-
protected boolean equal(double a, double b) {
51+
protected static boolean equal(double a, double b) {
4352
return Double.doubleToRawLongBits(a) == Double.doubleToRawLongBits(b);
4453
}
4554

4655
@Specialization(guards = { "isNonPrimitiveRubyObject(a)", "isNonPrimitiveRubyObject(b)" })
47-
protected boolean equalRubyObjects(Object a, Object b) {
56+
protected static boolean equalRubyObjects(Object a, Object b) {
4857
return a == b;
4958
}
5059

5160
@Specialization(guards = { "isNonPrimitiveRubyObject(a)", "isPrimitive(b)" })
52-
protected boolean rubyObjectPrimitive(Object a, Object b) {
61+
protected static boolean rubyObjectPrimitive(Object a, Object b) {
5362
return false;
5463
}
5564

5665
@Specialization(guards = { "isPrimitive(a)", "isNonPrimitiveRubyObject(b)" })
57-
protected boolean primitiveRubyObject(Object a, Object b) {
66+
protected static boolean primitiveRubyObject(Object a, Object b) {
5867
return false;
5968
}
6069

6170
@Specialization(guards = { "isPrimitive(a)", "isPrimitive(b)", "!comparablePrimitives(a, b)" })
62-
protected boolean nonComparablePrimitives(Object a, Object b) {
71+
protected static boolean nonComparablePrimitives(Object a, Object b) {
6372
return false;
6473
}
6574

6675
@Specialization(guards = "isForeignObject(a) || isForeignObject(b)", limit = "getInteropCacheLimit()")
67-
protected boolean equalForeign(Object a, Object b,
76+
protected static boolean equalForeign(Object a, Object b,
6877
@CachedLibrary("a") InteropLibrary lhsInterop,
6978
@CachedLibrary("b") InteropLibrary rhsInterop) {
7079
if (lhsInterop.hasIdentity(a)) {

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010
package org.truffleruby.core.hash;
1111

12-
import org.truffleruby.core.basicobject.ReferenceEqualNodeGen;
12+
import org.truffleruby.core.basicobject.ReferenceEqualNode;
1313
import org.truffleruby.core.hash.HashingNodes.ToHashByIdentity;
1414

1515
/** Wraps a value so that it will compared and hashed according to Ruby identity semantics. These semantics differ from
@@ -31,8 +31,6 @@ public int hashCode() {
3131
@Override
3232
public boolean equals(Object obj) {
3333
return obj instanceof CompareByRubyIdentityWrapper &&
34-
ReferenceEqualNodeGen
35-
.getUncached()
36-
.execute(value, ((CompareByRubyIdentityWrapper) obj).value);
34+
ReferenceEqualNode.executeUncached(value, ((CompareByRubyIdentityWrapper) obj).value);
3735
}
3836
}

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.oracle.truffle.api.dsl.Cached;
1313
import com.oracle.truffle.api.dsl.GenerateUncached;
1414
import com.oracle.truffle.api.dsl.Specialization;
15+
import com.oracle.truffle.api.nodes.Node;
1516
import org.truffleruby.core.basicobject.ReferenceEqualNode;
1617
import org.truffleruby.core.kernel.KernelNodes.SameOrEqlNode;
1718
import org.truffleruby.language.RubyBaseNode;
@@ -28,17 +29,17 @@ public abstract boolean execute(boolean compareByIdentity, Object key, int hashe
2829

2930
/** Checks if the two keys are the same object, which is used by both modes (by identity or not) of lookup. Enables
3031
* to check if the two keys are the same without a method call. */
31-
public static boolean referenceEqualKeys(ReferenceEqualNode refEqual, boolean compareByIdentity, Object key,
32-
int hashed, Object otherKey, int otherHashed) {
32+
public static boolean referenceEqualKeys(Node node, ReferenceEqualNode refEqual, boolean compareByIdentity,
33+
Object key, int hashed, Object otherKey, int otherHashed) {
3334
return compareByIdentity
34-
? refEqual.execute(key, otherKey)
35-
: hashed == otherHashed && refEqual.execute(key, otherKey);
35+
? refEqual.execute(node, key, otherKey)
36+
: hashed == otherHashed && refEqual.execute(node, key, otherKey);
3637
}
3738

3839
@Specialization(guards = "compareByIdentity")
3940
protected boolean refEquals(boolean compareByIdentity, Object key, int hashed, Object otherKey, int otherHashed,
4041
@Cached ReferenceEqualNode refEqual) {
41-
return refEqual.execute(key, otherKey);
42+
return refEqual.execute(this, key, otherKey);
4243
}
4344

4445
@Specialization(guards = "!compareByIdentity")

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -406,46 +406,48 @@ public abstract static class LookupPackedEntryNode extends RubyBaseNode {
406406
"isCompareByIdentity(hash) == cachedByIdentity",
407407
"cachedIndex >= 0",
408408
"cachedIndex < hash.size",
409-
"sameKeysAtIndex(refEqual, hash, key, hashed, cachedIndex, cachedByIdentity)" },
409+
"sameKeysAtIndex(node, refEqual, hash, key, hashed, cachedIndex, cachedByIdentity)" },
410410
limit = "1")
411-
protected Object getConstantIndexPackedArray(
411+
protected static Object getConstantIndexPackedArray(
412412
RubyHash hash, Object key, int hashed, PEBiFunction defaultValueNode,
413413
@Cached ReferenceEqualNode refEqual,
414414
@Cached("isCompareByIdentity(hash)") boolean cachedByIdentity,
415-
@Cached("index(refEqual, hash, key, hashed, cachedByIdentity)") int cachedIndex) {
415+
@Bind("this") Node node,
416+
@Cached("index(node, refEqual, hash, key, hashed, cachedByIdentity)") int cachedIndex) {
416417

417418
final Object[] store = (Object[]) hash.store;
418419
return getValue(store, cachedIndex);
419420
}
420421

421-
protected int index(ReferenceEqualNode refEqual, RubyHash hash, Object key, int hashed,
422+
protected static int index(Node node, ReferenceEqualNode refEqual, RubyHash hash, Object key, int hashed,
422423
boolean compareByIdentity) {
423424

424425
final Object[] store = (Object[]) hash.store;
425426
final int size = hash.size;
426427
for (int n = 0; n < size; n++) {
427428
final int otherHashed = getHashed(store, n);
428429
final Object otherKey = getKey(store, n);
429-
if (sameKeys(refEqual, compareByIdentity, key, hashed, otherKey, otherHashed)) {
430+
if (sameKeys(node, refEqual, compareByIdentity, key, hashed, otherKey, otherHashed)) {
430431
return n;
431432
}
432433
}
433434
return -1;
434435
}
435436

436-
protected boolean sameKeysAtIndex(ReferenceEqualNode refEqual, RubyHash hash, Object key, int hashed,
437+
protected static boolean sameKeysAtIndex(Node node, ReferenceEqualNode refEqual, RubyHash hash, Object key,
438+
int hashed,
437439
int cachedIndex, boolean cachedByIdentity) {
438440

439441
final Object[] store = (Object[]) hash.store;
440442
final Object otherKey = getKey(store, cachedIndex);
441443
final int otherHashed = getHashed(store, cachedIndex);
442-
return sameKeys(refEqual, cachedByIdentity, key, hashed, otherKey, otherHashed);
444+
return sameKeys(node, refEqual, cachedByIdentity, key, hashed, otherKey, otherHashed);
443445
}
444446

445-
private boolean sameKeys(ReferenceEqualNode refEqual, boolean compareByIdentity, Object key, int hashed,
446-
Object otherKey, int otherHashed) {
447+
private static boolean sameKeys(Node node, ReferenceEqualNode refEqual, boolean compareByIdentity, Object key,
448+
int hashed, Object otherKey, int otherHashed) {
447449
return CompareHashKeysNode
448-
.referenceEqualKeys(refEqual, compareByIdentity, key, hashed, otherKey, otherHashed);
450+
.referenceEqualKeys(node, refEqual, compareByIdentity, key, hashed, otherKey, otherHashed);
449451
}
450452

451453
@ExplodeLoop(kind = LoopExplosionKind.FULL_UNROLL_UNTIL_RETURN)

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ protected static boolean sameOrEqual(Node node, Object a, Object b,
197197
@Cached BooleanCastNode booleanCastNode,
198198
@Cached InlinedConditionProfile sameProfile,
199199
@Cached ReferenceEqualNode referenceEqualNode) {
200-
if (sameProfile.profile(node, referenceEqualNode.execute(a, b))) {
200+
if (sameProfile.profile(node, referenceEqualNode.execute(node, a, b))) {
201201
return true;
202202
} else {
203203
final var equalNode = lazyEqualNode.get(node);
@@ -232,7 +232,7 @@ public static SameOrEqlNode getUncached() {
232232

233233
public abstract boolean execute(Object a, Object b);
234234

235-
@Specialization(guards = "referenceEqual.execute(a, b)", limit = "1")
235+
@Specialization(guards = "referenceEqual.execute(this, a, b)", limit = "1")
236236
protected boolean refEqual(Object a, Object b,
237237
@Cached @Shared ReferenceEqualNode referenceEqual) {
238238
return true;
@@ -243,7 +243,7 @@ protected boolean refEqualOrEql(Object a, Object b,
243243
@Cached @Shared ReferenceEqualNode referenceEqual,
244244
@Cached DispatchNode eql,
245245
@Cached BooleanCastNode booleanCast) {
246-
return referenceEqual.execute(a, b) || booleanCast.execute(this, eql.call(a, "eql?", b));
246+
return referenceEqual.execute(this, a, b) || booleanCast.execute(this, eql.call(a, "eql?", b));
247247
}
248248
}
249249

@@ -925,14 +925,14 @@ protected static int hashForeign(Object value,
925925
@CoreMethod(names = "initialize_copy", required = 1, alwaysInlined = true)
926926
public abstract static class InitializeCopyNode extends AlwaysInlinedMethodNode {
927927

928-
@Specialization(guards = "equalNode.execute(self, from)", limit = "1")
928+
@Specialization(guards = "equalNode.execute(this, self, from)", limit = "1")
929929
protected Object initializeCopySame(Frame callerFrame, Object self, Object[] rubyArgs, RootCallTarget target,
930930
@Bind("getArgument(rubyArgs, 0)") Object from,
931931
@Cached @Shared ReferenceEqualNode equalNode) {
932932
return self;
933933
}
934934

935-
@Specialization(guards = "!equalNode.execute(self, from)", limit = "1")
935+
@Specialization(guards = "!equalNode.execute(this, self, from)", limit = "1")
936936
protected Object initializeCopy(Frame callerFrame, Object self, Object[] rubyArgs, RootCallTarget target,
937937
@Bind("getArgument(rubyArgs, 0)") Object from,
938938
@Cached @Shared ReferenceEqualNode equalNode,

src/main/java/org/truffleruby/core/method/MethodNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public abstract static class EqualNode extends CoreMethodArrayArgumentsNode {
103103
protected boolean equal(RubyMethod a, RubyMethod b,
104104
@Cached ReferenceEqualNode referenceEqualNode) {
105105
return referenceEqualNode
106-
.execute(a.receiver, b.receiver) &&
106+
.execute(this, a.receiver, b.receiver) &&
107107
a.method.getDeclaringModule() == b.method.getDeclaringModule() &&
108108
MethodNodes.areInternalMethodEqual(a.method, b.method);
109109
}

src/main/java/org/truffleruby/core/support/TypeNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public abstract static class EqualPrimitiveNode extends PrimitiveArrayArgumentsN
115115
@Specialization
116116
protected boolean equal(Object a, Object b,
117117
@Cached ReferenceEqualNode referenceEqualNode) {
118-
return referenceEqualNode.execute(a, b);
118+
return referenceEqualNode.execute(this, a, b);
119119
}
120120
}
121121

src/main/java/org/truffleruby/extra/AtomicReferenceNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ protected boolean compareAndSetPrimitive(RubyAtomicReference self, Object expect
100100
final Object currentValue = self.value.get();
101101

102102
if (RubyGuards.isPrimitive(currentValue) &&
103-
equalNode.execute(expectedValue, currentValue)) {
103+
equalNode.execute(this, expectedValue, currentValue)) {
104104
if (self.value.compareAndSet(currentValue, newValue)) {
105105
return true;
106106
}

0 commit comments

Comments
 (0)