Skip to content

Commit c3e47ae

Browse files
committed
Fix specialization inconsistency in foreign.__bool__
1 parent dd8bac6 commit c3e47ae

File tree

1 file changed

+14
-41
lines changed

1 file changed

+14
-41
lines changed

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

Lines changed: 14 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -141,54 +141,27 @@ protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFa
141141
@Builtin(name = __BOOL__, minNumOfPositionalArgs = 1)
142142
@GenerateNodeFactory
143143
abstract static class BoolNode extends PythonUnaryBuiltinNode {
144-
@Specialization(guards = "lib.isBoolean(receiver)", limit = "getCallSiteInlineCacheMaxDepth()")
144+
@Specialization(limit = "getCallSiteInlineCacheMaxDepth()")
145145
static boolean bool(Object receiver,
146146
@CachedLibrary("receiver") InteropLibrary lib) {
147147
try {
148-
return lib.asBoolean(receiver);
149-
} catch (UnsupportedMessageException e) {
150-
throw CompilerDirectives.shouldNotReachHere(e);
151-
}
152-
}
153-
154-
@Specialization(guards = "lib.fitsInLong(receiver)", limit = "getCallSiteInlineCacheMaxDepth()")
155-
static boolean integer(Object receiver,
156-
@CachedLibrary("receiver") InteropLibrary lib) {
157-
try {
158-
return lib.asLong(receiver) != 0;
159-
} catch (UnsupportedMessageException e) {
160-
throw CompilerDirectives.shouldNotReachHere(e);
161-
}
162-
}
163-
164-
@Specialization(guards = "lib.fitsInDouble(receiver)", limit = "getCallSiteInlineCacheMaxDepth()")
165-
static boolean floatingPoint(Object receiver,
166-
@CachedLibrary("receiver") InteropLibrary lib) {
167-
try {
168-
return lib.asDouble(receiver) != 0.0;
169-
} catch (UnsupportedMessageException e) {
170-
throw CompilerDirectives.shouldNotReachHere(e);
171-
}
172-
}
173-
174-
@Specialization(guards = "lib.hasArrayElements(receiver)", limit = "getCallSiteInlineCacheMaxDepth()")
175-
static boolean array(Object receiver,
176-
@CachedLibrary("receiver") InteropLibrary lib) {
177-
try {
178-
return lib.getArraySize(receiver) > 0;
148+
if (lib.isBoolean(receiver)) {
149+
return lib.asBoolean(receiver);
150+
}
151+
if (lib.fitsInLong(receiver)) {
152+
return lib.asLong(receiver) != 0;
153+
}
154+
if (lib.fitsInDouble(receiver)) {
155+
return lib.asDouble(receiver) != 0.0;
156+
}
157+
if (lib.hasArrayElements(receiver)) {
158+
return lib.getArraySize(receiver) != 0;
159+
}
160+
return !lib.isNull(receiver);
179161
} catch (UnsupportedMessageException e) {
180162
throw CompilerDirectives.shouldNotReachHere(e);
181163
}
182164
}
183-
184-
@Specialization(guards = {
185-
"!lib.isBoolean(receiver)", "!lib.fitsInLong(receiver)",
186-
"!lib.fitsInDouble(receiver)", "!lib.hasArrayElements(receiver)"
187-
}, limit = "getCallSiteInlineCacheMaxDepth()")
188-
static boolean generic(Object receiver,
189-
@CachedLibrary("receiver") InteropLibrary lib) {
190-
return !lib.isNull(receiver);
191-
}
192165
}
193166

194167
static Object[] unpackForeignArray(Object left, InteropLibrary lib, PForeignToPTypeNode convert) {

0 commit comments

Comments
 (0)