Skip to content

Commit 2581f8f

Browse files
committed
Workaround Truffle bug in fallback guard in IntBuiltins#AddNode
1 parent 13c5df9 commit 2581f8f

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

graalpython/com.oracle.graal.python.cext/src/tupleobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1361,7 +1361,7 @@ PyObject **
13611361
PyTruffleTuple_GetItems(PyObject *op)
13621362
{
13631363
#ifdef GRAALVM_PYTHON_LLVM_MANAGED
1364-
return GraalPy_get_PyTupleObject_ob_item(op);
1364+
return GraalPy_get_PyTupleObject_ob_item((PyTupleObject*) op);
13651365
#else /* GRAALVM_PYTHON_LLVM_MANAGED */
13661366
PyObject *res;
13671367
PyObject **ob_item;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/foreign/ForeignObjectBuiltins.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,7 @@ Object doBool(Object obj, @SuppressWarnings("unused") boolean doArray,
423423
try {
424424
return lib.asBoolean(obj);
425425
} catch (UnsupportedMessageException e) {
426-
CompilerDirectives.transferToInterpreterAndInvalidate();
427-
throw new IllegalStateException("object does not unpack to boolean as it claims to");
426+
throw CompilerDirectives.shouldNotReachHere(e);
428427
} finally {
429428
gil.acquire();
430429
}
@@ -439,8 +438,7 @@ Object doLong(Object obj, @SuppressWarnings("unused") boolean doArray,
439438
try {
440439
return lib.asLong(obj);
441440
} catch (UnsupportedMessageException e) {
442-
CompilerDirectives.transferToInterpreterAndInvalidate();
443-
throw new IllegalStateException("object does not unpack to long as it claims to");
441+
throw CompilerDirectives.shouldNotReachHere(e);
444442
} finally {
445443
gil.acquire();
446444
}
@@ -456,8 +454,7 @@ Object doBigInt(Object obj, @SuppressWarnings("unused") boolean doArray,
456454
try {
457455
return factory.createInt(lib.asBigInteger(obj));
458456
} catch (UnsupportedMessageException e) {
459-
CompilerDirectives.transferToInterpreterAndInvalidate();
460-
throw new IllegalStateException("object does not unpack to BigInteger as it claims to");
457+
throw CompilerDirectives.shouldNotReachHere(e);
461458
} finally {
462459
gil.acquire();
463460
}
@@ -472,8 +469,7 @@ Object doDouble(Object obj, @SuppressWarnings("unused") boolean doArray,
472469
try {
473470
return lib.asDouble(obj);
474471
} catch (UnsupportedMessageException e) {
475-
CompilerDirectives.transferToInterpreterAndInvalidate();
476-
throw new IllegalStateException("object does not unpack to double as it claims to");
472+
throw CompilerDirectives.shouldNotReachHere(e);
477473
} finally {
478474
gil.acquire();
479475
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/IntBuiltins.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,8 +454,14 @@ static BigInteger op(BigInteger left, BigInteger right) {
454454
return left.add(right);
455455
}
456456

457+
static boolean isNotImplemented(Object x) {
458+
return !(x instanceof Long || x instanceof Integer || x instanceof Boolean || x instanceof PInt);
459+
}
460+
461+
// There is a Truffle bug (GR-57305) that constructs a wrong fallback guard in the presence
462+
// of implicit casts, so we cannot use @Fallback for now
457463
@SuppressWarnings("unused")
458-
@Fallback
464+
@Specialization(guards = {"isNotImplemented(left) || isNotImplemented(right)"})
459465
static PNotImplemented doGeneric(Object left, Object right) {
460466
return PNotImplemented.NOT_IMPLEMENTED;
461467
}

0 commit comments

Comments
 (0)