Skip to content

Commit 90c75b7

Browse files
committed
Migrate away from canBePInt message
1 parent 5f9113f commit 90c75b7

File tree

5 files changed

+30
-79
lines changed

5 files changed

+30
-79
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinConstructors.java

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import static com.oracle.graal.python.builtins.objects.cext.capi.NativeCAPISymbol.FUN_ADD_NATIVE_SLOTS;
3030
import static com.oracle.graal.python.builtins.objects.cext.capi.NativeCAPISymbol.FUN_PY_OBJECT_NEW;
3131
import static com.oracle.graal.python.builtins.objects.cext.capi.NativeCAPISymbol.FUN_PY_TRUFFLE_MEMORYVIEW_FROM_OBJECT;
32-
import static com.oracle.graal.python.builtins.objects.range.RangeUtils.canBeInt;
3332
import static com.oracle.graal.python.builtins.objects.str.StringUtils.canEncodeUTF8;
3433
import static com.oracle.graal.python.builtins.objects.str.StringUtils.containsNullCharacter;
3534
import static com.oracle.graal.python.builtins.objects.type.TypeBuiltins.TYPE_ITEMSIZE;
@@ -264,7 +263,6 @@
264263
import com.oracle.truffle.api.dsl.ReportPolymorphism.Megamorphic;
265264
import com.oracle.truffle.api.dsl.Specialization;
266265
import com.oracle.truffle.api.frame.VirtualFrame;
267-
import com.oracle.truffle.api.interop.InteropLibrary;
268266
import com.oracle.truffle.api.interop.UnsupportedMessageException;
269267
import com.oracle.truffle.api.library.CachedLibrary;
270268
import com.oracle.truffle.api.nodes.UnexpectedResultException;
@@ -1845,10 +1843,10 @@ Object doGenericStop(VirtualFrame frame, Object cls, Object stop, @SuppressWarni
18451843
@Shared("exceptionProfile") @Cached BranchProfile exceptionProfile,
18461844
@Shared("lenOfRangeNodeExact") @Cached LenOfIntRangeNodeExact lenOfRangeNodeExact,
18471845
@Shared("createBigRangeNode") @Cached RangeNodes.CreateBigRangeNode createBigRangeNode,
1848-
@Shared("asSizeNode") @Cached PyNumberAsSizeNode asSizeNode,
1849-
@Shared("indexNode") @Cached PyNumberIndexNode indexNode,
1850-
@Shared("libGeneric") @CachedLibrary(limit = "3") InteropLibrary lib) {
1851-
return doGeneric(frame, cls, 0, stop, 1, stepZeroProfile, exceptionProfile, lenOfRangeNodeExact, createBigRangeNode, asSizeNode, indexNode, lib);
1846+
@Shared("cast") @Cached CastToJavaIntExactNode cast,
1847+
@Shared("overflowProfile") @Cached IsBuiltinClassProfile overflowProfile,
1848+
@Shared("indexNode") @Cached PyNumberIndexNode indexNode) {
1849+
return doGeneric(frame, cls, 0, stop, 1, stepZeroProfile, exceptionProfile, lenOfRangeNodeExact, createBigRangeNode, cast, overflowProfile, indexNode);
18521850
}
18531851

18541852
// start stop
@@ -1874,10 +1872,10 @@ Object doGenericStartStop(VirtualFrame frame, Object cls, Object start, Object s
18741872
@Shared("exceptionProfile") @Cached BranchProfile exceptionProfile,
18751873
@Shared("lenOfRangeNodeExact") @Cached LenOfIntRangeNodeExact lenOfRangeNodeExact,
18761874
@Shared("createBigRangeNode") @Cached RangeNodes.CreateBigRangeNode createBigRangeNode,
1877-
@Shared("asSizeNode") @Cached PyNumberAsSizeNode asSizeNode,
1878-
@Shared("indexNode") @Cached PyNumberIndexNode indexNode,
1879-
@Shared("libGeneric") @CachedLibrary(limit = "3") InteropLibrary lib) {
1880-
return doGeneric(frame, cls, start, stop, 1, stepZeroProfile, exceptionProfile, lenOfRangeNodeExact, createBigRangeNode, asSizeNode, indexNode, lib);
1875+
@Shared("cast") @Cached CastToJavaIntExactNode cast,
1876+
@Shared("overflowProfile") @Cached IsBuiltinClassProfile overflowProfile,
1877+
@Shared("indexNode") @Cached PyNumberIndexNode indexNode) {
1878+
return doGeneric(frame, cls, start, stop, 1, stepZeroProfile, exceptionProfile, lenOfRangeNodeExact, createBigRangeNode, cast, overflowProfile, indexNode);
18811879
}
18821880

18831881
// start stop step
@@ -1916,19 +1914,20 @@ Object doGeneric(VirtualFrame frame, @SuppressWarnings("unused") Object cls, Obj
19161914
@Shared("exceptionProfile") @Cached BranchProfile exceptionProfile,
19171915
@Shared("lenOfRangeNodeExact") @Cached LenOfIntRangeNodeExact lenOfRangeNodeExact,
19181916
@Shared("createBigRangeNode") @Cached RangeNodes.CreateBigRangeNode createBigRangeNode,
1919-
@Shared("asSizeNode") @Cached PyNumberAsSizeNode asSizeNode,
1920-
@Shared("indexNode") @Cached PyNumberIndexNode indexNode,
1921-
@Shared("libGeneric") @CachedLibrary(limit = "3") InteropLibrary lib) {
1917+
@Shared("cast") @Cached CastToJavaIntExactNode cast,
1918+
@Shared("overflowProfile") @Cached IsBuiltinClassProfile overflowProfile,
1919+
@Shared("indexNode") @Cached PyNumberIndexNode indexNode) {
19221920
Object lstart = indexNode.execute(frame, start);
19231921
Object lstop = indexNode.execute(frame, stop);
19241922
Object lstep = indexNode.execute(frame, step);
19251923

1926-
if (canBeInt(lstart, lstop, lstep, lib)) {
1927-
int istart = asSizeNode.executeExact(frame, lstart);
1928-
int istop = asSizeNode.executeExact(frame, lstop);
1929-
int istep = asSizeNode.executeExact(frame, lstep);
1924+
try {
1925+
int istart = cast.execute(lstart);
1926+
int istop = cast.execute(lstop);
1927+
int istep = cast.execute(lstep);
19301928
return doInt(cls, istart, istop, istep, stepZeroProfile, exceptionProfile, lenOfRangeNodeExact, createBigRangeNode);
1931-
} else {
1929+
} catch (PException e) {
1930+
e.expect(OverflowError, overflowProfile);
19321931
return createBigRangeNode.execute(lstart, lstop, lstep, factory());
19331932
}
19341933
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/FileIOBuiltins.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@
115115
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes;
116116
import com.oracle.graal.python.builtins.objects.exception.OSErrorEnum;
117117
import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
118+
import com.oracle.graal.python.lib.PyIndexCheckNode;
118119
import com.oracle.graal.python.lib.PyLongAsLongNode;
119120
import com.oracle.graal.python.lib.PyNumberAsSizeNode;
120121
import com.oracle.graal.python.nodes.PConstructAndRaiseNode;
@@ -284,7 +285,7 @@ public void doInit(VirtualFrame frame, PFileIO self, Object nameobj, IONodes.IOM
284285
@CachedContext(PythonLanguage.class) PythonContext ctxt,
285286
@CachedLibrary("ctxt.getPosixSupport()") PosixSupportLibrary posixLib,
286287
@CachedLibrary("opener") PythonObjectLibrary libOpener,
287-
@CachedLibrary(limit = "1") PythonObjectLibrary lib,
288+
@Cached PyIndexCheckNode indexCheckNode,
288289
@Cached PyNumberAsSizeNode asSizeNode,
289290
@Cached IONodes.CastOpenNameNode castOpenNameNode,
290291
@Cached PosixModuleBuiltins.CloseNode posixClose,
@@ -326,7 +327,7 @@ public void doInit(VirtualFrame frame, PFileIO self, Object nameobj, IONodes.IOM
326327
self.setFD(open(frame, name, flags, 0666, ctxt, posixLib, exceptionProfile), ctxt);
327328
} else {
328329
Object fdobj = libOpener.callObject(opener, frame, nameobj, flags);
329-
if (!lib.canBePInt(fdobj)) {
330+
if (!indexCheckNode.execute(fdobj)) {
330331
throw raise(TypeError, EXPECTED_INT_FROM_OPENER);
331332
}
332333

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/IONodes.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
import com.oracle.graal.python.builtins.objects.object.PythonObject;
6060
import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
6161
import com.oracle.graal.python.builtins.objects.str.PString;
62+
import com.oracle.graal.python.lib.PyIndexCheckNode;
6263
import com.oracle.graal.python.lib.PyNumberAsSizeNode;
6364
import com.oracle.graal.python.nodes.ErrorMessages;
6465
import com.oracle.graal.python.nodes.PGuards;
@@ -339,13 +340,13 @@ static int fast(long fd) {
339340
return (int) fd;
340341
}
341342

342-
@Specialization(guards = "!isInteger(nameobj)", limit = "2")
343+
@Specialization(guards = "!isInteger(nameobj)")
343344
Object generic(VirtualFrame frame, Object nameobj,
344345
@Cached BytesNodes.DecodeUTF8FSPathNode fspath,
345346
@Cached ConditionProfile errorProfile,
346-
@Cached PyNumberAsSizeNode asSizeNode,
347-
@CachedLibrary("nameobj") PythonObjectLibrary asInt) {
348-
if (asInt.canBePInt(nameobj)) {
347+
@Cached PyIndexCheckNode indexCheckNode,
348+
@Cached PyNumberAsSizeNode asSizeNode) {
349+
if (indexCheckNode.execute(nameobj)) {
349350
int fd = asSizeNode.executeExact(frame, nameobj);
350351
if (errorProfile.profile(fd < 0)) {
351352
err(fd);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyContextFunctions.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
import static com.oracle.graal.python.builtins.objects.cext.hpy.GraalHPyNativeSymbol.GRAAL_HPY_MODULE_GET_DEFINES;
5959
import static com.oracle.graal.python.builtins.objects.cext.hpy.GraalHPyNativeSymbol.GRAAL_HPY_MODULE_GET_LEGACY_METHODS;
6060
import static com.oracle.graal.python.builtins.objects.cext.hpy.GraalHPyNativeSymbol.GRAAL_HPY_WRITE_PTR;
61+
import static com.oracle.graal.python.nodes.SpecialMethodNames.__INT__;
6162

6263
import java.io.PrintWriter;
6364
import java.nio.charset.StandardCharsets;
@@ -120,6 +121,7 @@
120121
import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
121122
import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetNameNode;
122123
import com.oracle.graal.python.builtins.objects.type.TypeNodes.IsTypeNode;
124+
import com.oracle.graal.python.lib.PyIndexCheckNode;
123125
import com.oracle.graal.python.lib.PyNumberIndexNode;
124126
import com.oracle.graal.python.nodes.BuiltinNames;
125127
import com.oracle.graal.python.nodes.ErrorMessages;
@@ -1799,13 +1801,15 @@ public static final class GraalHPyIsNumber extends GraalHPyContextFunction {
17991801
Object execute(Object[] arguments,
18001802
@Cached HPyAsContextNode asContextNode,
18011803
@Cached HPyAsPythonObjectNode asPythonObjectNode,
1804+
@Cached PyIndexCheckNode indexCheckNode,
1805+
@Cached LookupInheritedAttributeNode.Dynamic lookup,
18021806
@CachedLibrary(limit = "3") PythonObjectLibrary lib,
18031807
@Cached HPyTransformExceptionToNativeNode transformExceptionToNativeNode) throws ArityException {
18041808
checkArity(arguments, 2);
18051809
GraalHPyContext nativeContext = asContextNode.execute(arguments[0]);
18061810
Object receiver = asPythonObjectNode.execute(nativeContext, arguments[1]);
18071811
try {
1808-
return lib.canBePInt(receiver) || lib.canBeJavaDouble(receiver);
1812+
return indexCheckNode.execute(receiver) || lib.canBeJavaDouble(receiver) || lookup.execute(receiver, __INT__) != PNone.NO_VALUE;
18091813
} catch (PException e) {
18101814
transformExceptionToNativeNode.execute(nativeContext, e);
18111815
return nativeContext.getNullHandle();

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/range/RangeUtils.java

Lines changed: 0 additions & 54 deletions
This file was deleted.

0 commit comments

Comments
 (0)