|
58 | 58 | import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
|
59 | 59 | import com.oracle.graal.python.builtins.objects.type.PythonAbstractClass;
|
60 | 60 | import com.oracle.graal.python.nodes.PRaiseNode;
|
| 61 | +import com.oracle.graal.python.nodes.attributes.LookupInheritedAttributeNode; |
| 62 | +import com.oracle.graal.python.nodes.call.CallNode; |
61 | 63 | import com.oracle.graal.python.nodes.classes.IsSubtypeNode;
|
| 64 | +import com.oracle.graal.python.nodes.object.GetLazyClassNode; |
62 | 65 | import com.oracle.truffle.api.Assumption;
|
63 | 66 | import com.oracle.truffle.api.CompilerAsserts;
|
64 | 67 | import com.oracle.truffle.api.CompilerDirectives;
|
|
77 | 80 | import com.oracle.truffle.api.library.ExportLibrary;
|
78 | 81 | import com.oracle.truffle.api.library.ExportMessage;
|
79 | 82 | import com.oracle.truffle.api.object.Shape;
|
| 83 | +import com.oracle.truffle.api.profiles.ConditionProfile; |
80 | 84 | import com.oracle.truffle.api.profiles.ValueProfile;
|
81 | 85 | import com.oracle.truffle.llvm.spi.ReferenceLibrary;
|
82 | 86 |
|
@@ -160,18 +164,22 @@ public void setDict(PHashingCollection value) throws UnsupportedMessageException
|
160 | 164 | }
|
161 | 165 |
|
162 | 166 | @ExportMessage
|
163 |
| - public boolean canBeIndex(@Exclusive @Cached IsSubtypeNode isSubtypeNode) { |
164 |
| - return isSubtypeNode.execute(this, PythonBuiltinClassType.PInt); |
165 |
| - } |
166 |
| - |
167 |
| - @ExportMessage |
168 |
| - public Object asIndexWithState(@SuppressWarnings("unused") ThreadState threadState, |
| 167 | + public Object asIndexWithState(ThreadState threadState, |
| 168 | + @Exclusive @Cached GetLazyClassNode getClass, |
169 | 169 | @Exclusive @Cached IsSubtypeNode isSubtypeNode,
|
170 |
| - @Exclusive @Cached PRaiseNode raise) { |
171 |
| - if (canBeIndex(isSubtypeNode)) { |
172 |
| - return this; |
| 170 | + // arguments for super-implementation call |
| 171 | + @CachedLibrary(limit = "1") PythonObjectLibrary lib, |
| 172 | + @Exclusive @Cached PRaiseNode raise, |
| 173 | + @Exclusive @Cached CallNode callNode, |
| 174 | + @Exclusive @Cached IsSubtypeNode isSubtype, |
| 175 | + @Exclusive @Cached LookupInheritedAttributeNode.Dynamic lookupIndex, |
| 176 | + @Exclusive @Cached("createBinaryProfile()") ConditionProfile noIndex, |
| 177 | + @Exclusive @Cached("createBinaryProfile()") ConditionProfile resultProfile, |
| 178 | + @Exclusive @Cached("createBinaryProfile()") ConditionProfile gotState) { |
| 179 | + if (isSubtypeNode.execute(getClass.execute(this), PythonBuiltinClassType.PInt)) { |
| 180 | + return this; // subclasses of 'int' should do early return |
173 | 181 | } else {
|
174 |
| - throw raise.raiseIntegerInterpretationError(this); |
| 182 | + return asIndexWithState(threadState, lib, raise, callNode, isSubtype, lookupIndex, noIndex, resultProfile, gotState); |
175 | 183 | }
|
176 | 184 | }
|
177 | 185 |
|
|
0 commit comments