Skip to content

Commit bcb6846

Browse files
committed
Use the correct guards to account for implicit casts in RubyTypes
1 parent 84659b9 commit bcb6846

File tree

11 files changed

+30
-37
lines changed

11 files changed

+30
-37
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import static org.truffleruby.cext.ValueWrapperManager.isMallocAligned;
1313

14+
import com.oracle.truffle.api.dsl.Fallback;
1415
import org.truffleruby.language.RubyBaseNode;
1516

1617
import com.oracle.truffle.api.dsl.GenerateUncached;
@@ -29,7 +30,7 @@ protected boolean isNativeObjectTaggedObject(long handle) {
2930
return isMallocAligned(handle) && handle < ValueWrapperManager.ALLOCATION_BASE;
3031
}
3132

32-
@Specialization(guards = "!isLong(handle)")
33+
@Fallback
3334
protected boolean isNativeObjectFallback(Object handle) {
3435
return false;
3536
}

src/main/java/org/truffleruby/core/array/ArrayNodes.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ protected RubyArray mulEmpty(RubyArray array, long count) {
212212
0);
213213
}
214214

215-
@Specialization(guards = { "!isInteger(count)", "!isLong(count)" })
215+
@Specialization(guards = { "!isImplicitLong(count)" })
216216
protected Object fallback(RubyArray array, Object count) {
217217
return FAILURE;
218218
}
@@ -284,7 +284,7 @@ protected Object indexRange(RubyArray array, RubyRange range, NotProvided length
284284
return readSlice.executeReadSlice(array, startLength[0], len);
285285
}
286286

287-
@Specialization(guards = { "!isInteger(index)", "!isRubyRange(index)" })
287+
@Specialization(guards = { "!isImplicitInteger(index)", "!isRubyRange(index)" })
288288
protected Object indexFallback(RubyArray array, Object index, NotProvided length,
289289
@Cached AtNode accessWithIndexConversion) {
290290
return accessWithIndexConversion.executeAt(array, index);
@@ -303,7 +303,7 @@ protected Object slice(RubyArray array, int start, int length,
303303
return readSliceNode.executeReadSlice(array, start, length);
304304
}
305305

306-
@Specialization(guards = { "wasProvided(length)", "!isInteger(start) || !isInteger(length)" })
306+
@Specialization(guards = { "wasProvided(length)", "!isImplicitInteger(start) || !isImplicitInteger(length)" })
307307
protected Object sliceFallback(RubyArray array, Object start, Object length,
308308
@Cached ToIntNode indexToInt,
309309
@Cached ToIntNode lengthToInt) {
@@ -359,7 +359,7 @@ protected Object setRange(RubyArray array, RubyRange range, Object value, NotPro
359359
return executeIntIndices(array, start, length, value);
360360
}
361361

362-
@Specialization(guards = { "!isInteger(start)", "!isRubyRange(start)" })
362+
@Specialization(guards = { "!isImplicitInteger(start)", "!isRubyRange(start)" })
363363
protected Object fallbackBinary(RubyArray array, Object start, Object value, NotProvided unused,
364364
@Cached ToIntNode toInt) {
365365
return executeIntIndex(array, toInt.execute(start), value, unused);
@@ -423,7 +423,8 @@ protected Object setTernary(RubyArray array, int start, int length, Object repla
423423
return replacement;
424424
}
425425

426-
@Specialization(guards = { "!isInteger(start) || !isInteger(length)", "wasProvided(replacement)" })
426+
@Specialization(
427+
guards = { "!isImplicitInteger(start) || !isImplicitInteger(length)", "wasProvided(replacement)" })
427428
protected Object fallbackTernary(RubyArray array, Object start, Object length, Object replacement,
428429
@Cached ToIntNode startToInt,
429430
@Cached ToIntNode lengthToInt) {
@@ -1133,7 +1134,7 @@ protected RubyArray initializeWithSizeAndValue(RubyArray array, int size, Object
11331134
}
11341135

11351136
@Specialization(
1136-
guards = { "wasProvided(size)", "!isInteger(size)", "!isLong(size)", "wasProvided(fillingValue)" })
1137+
guards = { "wasProvided(size)", "!isImplicitLong(size)", "wasProvided(fillingValue)" })
11371138
protected RubyArray initializeSizeOther(RubyArray array, Object size, Object fillingValue, Nil block) {
11381139
int intSize = toInt(size);
11391140
return executeInitialize(array, intSize, fillingValue, block);
@@ -1173,7 +1174,7 @@ protected RubyArray initializeFromArray(
11731174
}
11741175

11751176
@Specialization(
1176-
guards = { "!isInteger(object)", "!isLong(object)", "wasProvided(object)", "!isRubyArray(object)" })
1177+
guards = { "!isImplicitLong(object)", "wasProvided(object)", "!isRubyArray(object)" })
11771178
protected RubyArray initialize(RubyArray array, Object object, NotProvided unusedValue, Nil block) {
11781179
RubyArray copy = null;
11791180
if (respondToToAry(getLanguage(), object)) {
@@ -1608,7 +1609,7 @@ protected RubyArray popNotEmptyUnsharedStorage(RubyArray array, int n,
16081609
return createArray(popped, numPop);
16091610
}
16101611

1611-
@Specialization(guards = { "wasProvided(n)", "!isInteger(n)", "!isLong(n)" })
1612+
@Specialization(guards = { "wasProvided(n)", "!isImplicitInteger(n)" })
16121613
protected Object popNToInt(RubyArray array, Object n,
16131614
@Cached ToIntNode toIntNode) {
16141615
return executePop(array, toIntNode.execute(n));
@@ -2038,7 +2039,7 @@ protected Object shiftMany(RubyArray array, int n,
20382039
return createArray(result, numShift);
20392040
}
20402041

2041-
@Specialization(guards = { "wasProvided(n)", "!isInteger(n)", "!isLong(n)" })
2042+
@Specialization(guards = { "wasProvided(n)", "!isImplicitInteger(n)" })
20422043
protected Object shiftNToInt(RubyArray array, Object n,
20432044
@Cached ToIntNode toIntNode) {
20442045
return executeShift(array, toIntNode.execute(n));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ protected long coerceNil(Nil value) {
107107
coreExceptions().typeError("no implicit conversion from nil to integer", this));
108108
}
109109

110-
@Specialization(guards = { "!isRubyInteger(object)", "!isDouble(object)", "!isNil(object)" })
110+
@Specialization(guards = { "!isRubyInteger(object)", "!isImplicitDouble(object)", "!isNil(object)" })
111111
protected int coerceObject(Object object,
112112
@Cached DispatchNode toIntNode,
113113
@Cached ToIntNode fitNode) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ protected long coerceNil(Nil nil) {
7777
coreExceptions().typeError("no implicit conversion from nil to integer", this));
7878
}
7979

80-
@Specialization(guards = { "!isRubyInteger(object)", "!isDouble(object)", "!isNil(object)" })
80+
@Specialization(guards = { "!isRubyInteger(object)", "!isImplicitDouble(object)", "!isNil(object)" })
8181
protected long coerceObject(Object object,
8282
@Cached DispatchNode toIntNode,
8383
@Cached ToLongNode fitNode) {

src/main/java/org/truffleruby/core/format/format/FormatFloatHumanReadableNode.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@
2020
public abstract class FormatFloatHumanReadableNode extends FormatNode {
2121

2222
@TruffleBoundary
23-
@Specialization(guards = "isInteger(value)")
23+
@Specialization(guards = "isIntegerValue(value)")
2424
protected byte[] formatInteger(double value) {
2525
return RopeOperations.encodeAsciiBytes(String.valueOf((long) value));
2626
}
2727

2828
@TruffleBoundary
29-
@Specialization(guards = "!isInteger(value)")
29+
@Specialization(guards = "!isIntegerValue(value)")
3030
protected byte[] format(double value) {
3131
return RopeOperations.encodeAsciiBytes(String.valueOf(value));
3232
}
3333

34-
protected boolean isInteger(double value) {
34+
protected boolean isIntegerValue(double value) {
3535
/** General approach taken from StackOverflow:
3636
* http://stackoverflow.com/questions/703396/how-to-nicely-format-floating-numbers-to-string-without-unnecessary
3737
* -decimal-0 Answers provided by JasonD (http://stackoverflow.com/users/1288598/jasond) and Darthenius

src/main/java/org/truffleruby/core/numeric/FixnumLowerNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ protected long lowerFails(long value) {
5151
return value;
5252
}
5353

54-
@Specialization(guards = { "!isInteger(value)", "!isLong(value)" })
54+
@Specialization(guards = "!isImplicitLong(value)")
5555
protected Object passThrough(Object value) {
5656
return value;
5757
}

src/main/java/org/truffleruby/core/numeric/FloatNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ protected boolean eql(double a, double b) {
345345
return a == b;
346346
}
347347

348-
@Specialization(guards = { "!isDouble(b)" })
348+
@Specialization(guards = { "!isImplicitDouble(b)" })
349349
protected boolean eqlGeneral(double a, Object b) {
350350
return false;
351351
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ protected Object getIndexString(RubyMatchData matchData, Object index, NotProvid
315315

316316
@Specialization(
317317
guards = {
318-
"!isInteger(index)",
318+
"!isImplicitInteger(index)",
319319
"!isRubySymbol(index)",
320320
"isNotRubyString(index)",
321321
"!isIntRange(index)" })

src/main/java/org/truffleruby/core/string/StringNodes.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2611,10 +2611,7 @@ protected Object sum(Object string, NotProvided bits,
26112611
return sum(string, 16, strings);
26122612
}
26132613

2614-
@Specialization(guards = {
2615-
"!isInteger(bits)",
2616-
"!isLong(bits)",
2617-
"wasProvided(bits)" })
2614+
@Specialization(guards = { "!isImplicitLong(bits)", "wasProvided(bits)" })
26182615
protected Object sum(Object string, Object bits,
26192616
@Cached ToLongNode toLongNode,
26202617
@Cached SumNode sumNode) {

src/main/java/org/truffleruby/core/time/TimeNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ protected RubyTime timeSFromArray(
483483
return buildTime(language, timeClass, sec, min, hour, mday, month, year, nsec, isdst, isutc, utcoffset);
484484
}
485485

486-
@Specialization(guards = "!isInteger(sec) || !isInteger(nsec)")
486+
@Specialization(guards = "!isImplicitInteger(sec) || !isImplicitInteger(nsec)")
487487
protected Object timeSFromArrayFallback(
488488
RubyClass timeClass,
489489
Object sec,

0 commit comments

Comments
 (0)