Skip to content

Commit 021e2e7

Browse files
committed
fix two invalid identity profiles in multi-context mode
1 parent 30f1108 commit 021e2e7

File tree

2 files changed

+36
-20
lines changed

2 files changed

+36
-20
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/PythonAbstractObject.java

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2104,28 +2104,39 @@ public TriState isIdenticalOrUndefined(Object other,
21042104
* {@code tp_iter} for every user class.
21052105
*/
21062106
@ExportMessage
2107-
public Object getIteratorWithState(ThreadState state,
2108-
@Cached("createIdentityProfile()") ValueProfile iterMethodProfile,
2109-
@CachedLibrary("this") PythonObjectLibrary plib,
2110-
@CachedLibrary(limit = "2") PythonObjectLibrary methodLib,
2111-
@Cached IteratorNodes.IsIteratorObjectNode isIteratorObjectNode,
2112-
@Cached PythonObjectFactory factory,
2113-
@Shared("raise") @Cached PRaiseNode raise) {
2114-
Object v = plib.getDelegatedValue(this);
2115-
Object iterMethod = iterMethodProfile.profile(plib.lookupAttributeOnType(this, __ITER__));
2116-
if (iterMethod != PNone.NONE) {
2117-
if (iterMethod != PNone.NO_VALUE) {
2118-
Object iterObj = methodLib.callUnboundMethodIgnoreGetExceptionWithState(iterMethod, state, v);
2119-
if (iterObj != PNone.NO_VALUE && isIteratorObjectNode.execute(iterObj)) {
2120-
return iterObj;
2121-
}
2107+
public static class GetIteratorWithState {
2108+
public static final ValueProfile createIterMethodProfile() {
2109+
if (singleContextAssumption().isValid()) {
2110+
return ValueProfile.createIdentityProfile();
21222111
} else {
2123-
Object getItemAttrObj = plib.lookupAttributeOnType(this, __GETITEM__);
2124-
if (getItemAttrObj != PNone.NO_VALUE) {
2125-
return factory.createSequenceIterator(v);
2112+
return ValueProfile.createClassProfile();
2113+
}
2114+
}
2115+
2116+
@Specialization
2117+
public static Object getIteratorWithState(PythonAbstractObject self, ThreadState state,
2118+
@Cached("createIterMethodProfile()") ValueProfile iterMethodProfile,
2119+
@CachedLibrary("self") PythonObjectLibrary plib,
2120+
@CachedLibrary(limit = "2") PythonObjectLibrary methodLib,
2121+
@Cached IteratorNodes.IsIteratorObjectNode isIteratorObjectNode,
2122+
@Cached PythonObjectFactory factory,
2123+
@Shared("raise") @Cached PRaiseNode raise) {
2124+
Object v = plib.getDelegatedValue(self);
2125+
Object iterMethod = iterMethodProfile.profile(plib.lookupAttributeOnType(self, __ITER__));
2126+
if (iterMethod != PNone.NONE) {
2127+
if (iterMethod != PNone.NO_VALUE) {
2128+
Object iterObj = methodLib.callUnboundMethodIgnoreGetExceptionWithState(iterMethod, state, v);
2129+
if (iterObj != PNone.NO_VALUE && isIteratorObjectNode.execute(iterObj)) {
2130+
return iterObj;
2131+
}
2132+
} else {
2133+
Object getItemAttrObj = plib.lookupAttributeOnType(self, __GETITEM__);
2134+
if (getItemAttrObj != PNone.NO_VALUE) {
2135+
return factory.createSequenceIterator(v);
2136+
}
21262137
}
21272138
}
2139+
throw raise.raise(PythonErrorType.TypeError, ErrorMessages.OBJ_NOT_ITERABLE, self);
21282140
}
2129-
throw raise.raise(PythonErrorType.TypeError, ErrorMessages.OBJ_NOT_ITERABLE, this);
21302141
}
21312142
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/function/builtins/WrapTpNew.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
*/
4141
package com.oracle.graal.python.nodes.function.builtins;
4242

43+
import com.oracle.graal.python.PythonLanguage;
4344
import com.oracle.graal.python.builtins.Builtin;
4445
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
4546
import com.oracle.graal.python.builtins.objects.function.PArguments;
@@ -130,7 +131,11 @@ public Object execute(VirtualFrame frame) {
130131
if (newMethod instanceof PBuiltinFunction) {
131132
if (builtinProfile == null) {
132133
CompilerDirectives.transferToInterpreterAndInvalidate();
133-
builtinProfile = ValueProfile.createIdentityProfile();
134+
if (lookupLanguageReference(PythonLanguage.class).get().singleContextAssumption.isValid()) {
135+
builtinProfile = ValueProfile.createIdentityProfile();
136+
} else {
137+
builtinProfile = ValueProfile.getUncached();
138+
}
134139
}
135140
NodeFactory<? extends PythonBuiltinBaseNode> factory = ((PBuiltinFunction) builtinProfile.profile(newMethod)).getBuiltinNodeFactory();
136141
if (factory != null) {

0 commit comments

Comments
 (0)