|
40 | 40 | import com.oracle.graal.python.nodes.object.IsBuiltinClassProfile;
|
41 | 41 | import com.oracle.graal.python.nodes.subscript.SliceLiteralNodeGen.CastToSliceComponentNodeGen;
|
42 | 42 | import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
|
43 |
| -import com.oracle.graal.python.nodes.util.CastToIndexNode; |
| 43 | +import com.oracle.graal.python.runtime.PythonOptions; |
44 | 44 | import com.oracle.graal.python.runtime.exception.PException;
|
45 | 45 | import com.oracle.graal.python.runtime.object.PythonObjectFactory;
|
46 | 46 | import com.oracle.truffle.api.CompilerDirectives;
|
47 | 47 | import com.oracle.truffle.api.dsl.Cached;
|
48 | 48 | import com.oracle.truffle.api.dsl.Fallback;
|
| 49 | +import com.oracle.truffle.api.dsl.ImportStatic; |
49 | 50 | import com.oracle.truffle.api.dsl.NodeChild;
|
50 | 51 | import com.oracle.truffle.api.dsl.Specialization;
|
51 | 52 | import com.oracle.truffle.api.dsl.TypeSystemReference;
|
@@ -118,6 +119,7 @@ public static SliceLiteralNode create() {
|
118 | 119 | return SliceLiteralNodeGen.create(null, null, null);
|
119 | 120 | }
|
120 | 121 |
|
| 122 | + @ImportStatic(PythonOptions.class) |
121 | 123 | abstract static class CastToSliceComponentNode extends PNodeWithContext {
|
122 | 124 |
|
123 | 125 | @Child private PRaiseNode raiseNode;
|
@@ -174,28 +176,19 @@ int doPInt(PInt i) {
|
174 | 176 |
|
175 | 177 | @Specialization(replaces = {"doBoolean", "doInt", "doLong", "doPInt"}, limit = "getCallSiteInlineCacheMaxDepth()")
|
176 | 178 | int doGeneric(VirtualFrame frame, Object i,
|
| 179 | + @Cached PRaiseNode raise, |
177 | 180 | @CachedLibrary("i") PythonObjectLibrary lib,
|
178 | 181 | @Cached IsBuiltinClassProfile errorProfile) {
|
179 |
| - try { |
180 |
| - return lib.asIndexWithState(i, PArguments.getThreadState(frame)); |
181 |
| - } catch (PException e) { |
182 |
| - e.expect(PythonBuiltinClassType.OverflowError, errorProfile); |
183 |
| - return overflowValue; |
184 |
| - } |
185 |
| - } |
186 |
| - |
187 |
| - protected CastToIndexNode createCastToIndex() { |
188 |
| - return CastToIndexNode.create(PythonBuiltinClassType.OverflowError, val -> { |
189 |
| - throw getRaiseNode().raise(PythonBuiltinClassType.TypeError, "slice indices must be integers or None or have an __index__ method"); |
190 |
| - }); |
191 |
| - } |
192 |
| - |
193 |
| - private PRaiseNode getRaiseNode() { |
194 |
| - if (raiseNode == null) { |
195 |
| - CompilerDirectives.transferToInterpreterAndInvalidate(); |
196 |
| - raiseNode = insert(PRaiseNode.create()); |
| 182 | + if (lib.canBeIndex(i)) { |
| 183 | + try { |
| 184 | + return lib.asIndexWithState(i, PArguments.getThreadState(frame)); |
| 185 | + } catch (PException e) { |
| 186 | + e.expect(PythonBuiltinClassType.OverflowError, errorProfile); |
| 187 | + return overflowValue; |
| 188 | + } |
| 189 | + } else { |
| 190 | + throw raise.raise(PythonBuiltinClassType.TypeError, "slice indices must be integers or None or have an __index__ method"); |
197 | 191 | }
|
198 |
| - return raiseNode; |
199 | 192 | }
|
200 | 193 |
|
201 | 194 | public static CastToSliceComponentNode create(int defaultValue, int overflowValue) {
|
|
0 commit comments