Skip to content

Commit d04c2cb

Browse files
committed
Remove code handling reversible builtins (now dead code)
1 parent ecbf638 commit d04c2cb

File tree

14 files changed

+61
-231
lines changed

14 files changed

+61
-231
lines changed

graalpython/com.oracle.graal.python.test/src/tests/test_dict.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
22
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
33
#
44
# The Universal Permissive License (UPL), Version 1.0
@@ -1267,3 +1267,11 @@ def test_dict_values_eq():
12671267
d1 = {1: 1, 2: 2, 4: 4}
12681268
assert d1.values() != d1.values()
12691269

1270+
1271+
def test_missing_and_not_implemented():
1272+
class MyDict(dict):
1273+
def __missing__(self, key):
1274+
return NotImplemented
1275+
1276+
d = MyDict()
1277+
assert d['bogus_key'] == NotImplemented

graalpython/com.oracle.graal.python.test/src/tests/test_isinstance.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
22
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
33
#
44
# The Universal Permissive License (UPL), Version 1.0
@@ -271,4 +271,24 @@ def call_isinstance(expected, tpl):
271271

272272
called_instancecheck = 0
273273
assert isinstance(expected_other, tpl) is True
274-
assert called_instancecheck == 190
274+
assert called_instancecheck == 190
275+
276+
277+
def test_instancecheck_and_subclass_returns_not_iplemented():
278+
class MyMetaType(type):
279+
def __instancecheck__(cls, instance):
280+
return NotImplemented
281+
def __subclasscheck__(cls, instance):
282+
return NotImplemented
283+
284+
class MyMetaTypeInstance(metaclass=MyMetaType):
285+
pass
286+
287+
class UnrelatedClass():
288+
pass
289+
290+
o = UnrelatedClass
291+
# gives: DeprecationWarning: NotImplemented should not be used in a boolean context
292+
# but should still treat NotImplemented as True
293+
assert isinstance(o, MyMetaTypeInstance)
294+
assert issubclass(UnrelatedClass, MyMetaTypeInstance)

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/Builtin.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2024, Oracle and/or its affiliates.
2+
* Copyright (c) 2017, 2025, Oracle and/or its affiliates.
33
* Copyright (c) 2013, Regents of the University of California
44
*
55
* All rights reserved.
@@ -97,15 +97,6 @@
9797
*/
9898
boolean declaresExplicitSelf() default false;
9999

100-
/**
101-
* Declares that this builtin needs to reverse the first and second argument it receives. This
102-
* implements the reverse operation wrappers from CPython. This only applies to binary and
103-
* ternary nodes.
104-
*
105-
* @see com.oracle.graal.python.nodes.function.BuiltinFunctionRootNode BuiltinFunctionRootNode
106-
*/
107-
boolean reverseOperation() default false;
108-
109100
String raiseErrorName() default StringLiterals.J_EMPTY_STRING;
110101

111102
boolean forceSplitDirectCalls() default false;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/dict/DictBuiltins.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,20 @@
7272
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotLen.LenBuiltinNode;
7373
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotMpAssSubscript.MpAssSubscriptBuiltinNode;
7474
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotRichCompare.RichCmpBuiltinNode;
75-
import com.oracle.graal.python.lib.RichCmpOp;
7675
import com.oracle.graal.python.builtins.objects.type.slots.TpSlotSqContains.SqContainsBuiltinNode;
7776
import com.oracle.graal.python.lib.IteratorExhausted;
7877
import com.oracle.graal.python.lib.PyDictCheckNode;
7978
import com.oracle.graal.python.lib.PyDictSetDefault;
8079
import com.oracle.graal.python.lib.PyIterNextNode;
8180
import com.oracle.graal.python.lib.PyObjectGetIter;
8281
import com.oracle.graal.python.lib.PyObjectSetItem;
82+
import com.oracle.graal.python.lib.RichCmpOp;
8383
import com.oracle.graal.python.nodes.ErrorMessages;
8484
import com.oracle.graal.python.nodes.PGuards;
8585
import com.oracle.graal.python.nodes.PRaiseNode;
8686
import com.oracle.graal.python.nodes.call.CallNode;
87-
import com.oracle.graal.python.nodes.call.special.LookupAndCallBinaryNode;
87+
import com.oracle.graal.python.nodes.call.special.CallBinaryMethodNode;
88+
import com.oracle.graal.python.nodes.call.special.LookupSpecialMethodSlotNode;
8889
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
8990
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
9091
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
@@ -93,6 +94,7 @@
9394
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
9495
import com.oracle.graal.python.nodes.function.builtins.PythonVarargsBuiltinNode;
9596
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
97+
import com.oracle.graal.python.nodes.object.GetClassNode;
9698
import com.oracle.graal.python.runtime.object.PFactory;
9799
import com.oracle.truffle.api.CompilerDirectives;
98100
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
@@ -339,13 +341,15 @@ protected abstract static class DispatchMissingNode extends Node {
339341
@Specialization
340342
static Object missing(VirtualFrame frame, Object self, Object key,
341343
@Bind("this") Node inliningTarget,
342-
@Cached("create(Missing)") LookupAndCallBinaryNode callMissing,
344+
@Cached GetClassNode getClassNode,
345+
@Cached("create(Missing)") LookupSpecialMethodSlotNode lookupMissingNode,
346+
@Cached CallBinaryMethodNode callMissingNode,
343347
@Cached PRaiseNode raiseNode) {
344-
Object result = callMissing.executeObject(frame, self, key);
345-
if (result == PNotImplemented.NOT_IMPLEMENTED) {
348+
Object missingFun = lookupMissingNode.execute(frame, getClassNode.execute(inliningTarget, self), self);
349+
if (PGuards.isNoValue(missingFun)) {
346350
throw raiseNode.raise(inliningTarget, KeyError, new Object[]{key});
347351
}
348-
return result;
352+
return callMissingNode.executeObject(frame, missingFun, self, key);
349353
}
350354
}
351355

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/BuiltinMethodDescriptor.java

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -230,11 +230,6 @@ public boolean declaresExplicitSelf() {
230230
return false;
231231
}
232232

233-
@Override
234-
public boolean reverseOperation() {
235-
return false;
236-
}
237-
238233
@Override
239234
public String raiseErrorName() {
240235
return null;
@@ -309,7 +304,6 @@ private static Builtin findBuiltinAnnotation(String name, NodeFactory<? extends
309304
private final Builtin builtinAnnotation;
310305
// Shortcuts for fields of builtinAnnotation that are accessed on a fast-path
311306
private final String name;
312-
private final boolean isReverseOperation;
313307
private final int minNumOfPositionalArgs;
314308

315309
private BuiltinMethodDescriptor(String name, NodeFactory<? extends PythonBuiltinBaseNode> factory, PythonBuiltinClassType type, Builtin builtinAnnotation) {
@@ -318,7 +312,6 @@ private BuiltinMethodDescriptor(String name, NodeFactory<? extends PythonBuiltin
318312
this.factory = factory;
319313
this.type = type;
320314
this.builtinAnnotation = builtinAnnotation;
321-
this.isReverseOperation = builtinAnnotation.reverseOperation();
322315
this.minNumOfPositionalArgs = builtinAnnotation.minNumOfPositionalArgs();
323316
}
324317

@@ -338,10 +331,6 @@ public final String getName() {
338331
return name;
339332
}
340333

341-
public final boolean isReverseOperation() {
342-
return isReverseOperation;
343-
}
344-
345334
public final int minNumOfPositionalArgs() {
346335
return minNumOfPositionalArgs;
347336
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/PBuiltinFunction.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,6 @@ public NodeFactory<? extends PythonBuiltinBaseNode> getBuiltinNodeFactory() {
158158
}
159159
}
160160

161-
public static boolean isReverseOperationSlot(RootCallTarget ct) {
162-
RootNode functionRootNode = ct.getRootNode();
163-
if (functionRootNode instanceof BuiltinFunctionRootNode) {
164-
return ((BuiltinFunctionRootNode) functionRootNode).getBuiltin().reverseOperation();
165-
} else {
166-
return false;
167-
}
168-
}
169-
170161
public int getFlags() {
171162
return flags;
172163
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/SpecialMethodSlot.java

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@
103103
import com.oracle.graal.python.runtime.sequence.storage.MroSequenceStorage;
104104
import com.oracle.graal.python.util.PythonUtils;
105105
import com.oracle.truffle.api.CompilerAsserts;
106-
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
107106
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
108107
import com.oracle.truffle.api.dsl.Idempotent;
109108
import com.oracle.truffle.api.dsl.NodeFactory;
@@ -177,7 +176,6 @@ static class Flags {
177176
public static final SpecialMethodSlot[] VALUES = values();
178177

179178
private final TruffleString name;
180-
@CompilationFinal private SpecialMethodSlot reverse;
181179
/**
182180
* Indicates if given slot may or must not store context independent (AST cacheable)
183181
* {@link BuiltinMethodDescriptor} objects.
@@ -217,17 +215,12 @@ static class Flags {
217215

218216
static {
219217
assert checkFind();
220-
assert checkReverseSlots();
221218
}
222219

223220
public TruffleString getName() {
224221
return name;
225222
}
226223

227-
public SpecialMethodSlot getReverse() {
228-
return reverse;
229-
}
230-
231224
public long getMethodsFlag() {
232225
return methodsFlag;
233226
}
@@ -820,24 +813,6 @@ public static SpecialMethodSlot findSpecialSlot(TruffleString name, TruffleStrin
820813
return null;
821814
}
822815

823-
private static boolean checkReverseSlots() {
824-
TruffleString prefix = tsLiteral("__");
825-
TruffleString rPrefix = tsLiteral("__r");
826-
for (SpecialMethodSlot slot : VALUES) {
827-
TruffleString slotName = slot.getName();
828-
if (rPrefix.regionEqualsUncached(0, slotName, 0, 3, TS_ENCODING)) {
829-
int slotNameLen = slotName.codePointLengthUncached(TS_ENCODING);
830-
TruffleString slotNamePart = slotName.substringUncached(3, slotNameLen - 3, TS_ENCODING, true);
831-
SpecialMethodSlot rslot = findSpecialSlotUncached(prefix.concatUncached(slotNamePart, TS_ENCODING, false));
832-
if (rslot != null && rslot.reverse != slot) {
833-
assert false : slotName;
834-
return false;
835-
}
836-
}
837-
}
838-
return true;
839-
}
840-
841816
private static boolean checkFind() {
842817
for (SpecialMethodSlot slot : VALUES) {
843818
if (findSpecialSlotUncached(slot.getName()) != slot) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/Slot2Builtin.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -177,11 +177,6 @@ public boolean declaresExplicitSelf() {
177177
return false;
178178
}
179179

180-
@Override
181-
public boolean reverseOperation() {
182-
return false;
183-
}
184-
185180
@Override
186181
public String raiseErrorName() {
187182
return annotation != null ? annotation.raiseErrorName() : "";

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/CallBinaryMethodNode.java

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -73,7 +73,7 @@
7373
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
7474

7575
@GenerateUncached
76-
public abstract class CallBinaryMethodNode extends CallReversibleMethodNode {
76+
public abstract class CallBinaryMethodNode extends AbstractCallMethodNode {
7777
@NeverDefault
7878
public static CallBinaryMethodNode create() {
7979
return CallBinaryMethodNodeGen.create();
@@ -99,11 +99,7 @@ public final Object executeObject(Object callable, Object arg1, Object arg2) {
9999
static Object callBinarySpecialMethodSlotInlined(VirtualFrame frame, @SuppressWarnings("unused") BinaryBuiltinDescriptor info, Object arg1, Object arg2,
100100
@SuppressWarnings("unused") @Cached("info") BinaryBuiltinDescriptor cachedInfo,
101101
@Cached("getBuiltin(cachedInfo)") PythonBinaryBuiltinNode node) {
102-
if (cachedInfo.isReverseOperation()) {
103-
return node.execute(frame, arg2, arg1);
104-
} else {
105-
return node.execute(frame, arg1, arg2);
106-
}
102+
return node.execute(frame, arg1, arg2);
107103
}
108104

109105
protected static boolean hasAllowedArgsNum(BuiltinMethodDescriptor descr) {
@@ -116,9 +112,6 @@ Object callTernarySpecialMethodSlotInlined(VirtualFrame frame, @SuppressWarnings
116112
@Cached("hasAllowedArgsNum(cachedInfo)") boolean hasValidArgsNum,
117113
@Cached("getBuiltin(cachedInfo)") PythonTernaryBuiltinNode node) {
118114
raiseInvalidArgsNumUncached(hasValidArgsNum, cachedInfo);
119-
if (cachedInfo.isReverseOperation()) {
120-
return node.execute(frame, arg2, arg1, PNone.NO_VALUE);
121-
}
122115
return node.execute(frame, arg1, arg2, PNone.NO_VALUE);
123116
}
124117

@@ -143,26 +136,16 @@ Object callSpecialMethodSlotCallTarget(VirtualFrame frame, BuiltinMethodDescript
143136
@Specialization(guards = {"isSingleContext()", "func == cachedFunc", "builtinNode != null"}, limit = "getCallSiteInlineCacheMaxDepth()")
144137
static Object callObjectSingleContext(VirtualFrame frame, @SuppressWarnings("unused") PBuiltinFunction func, Object arg1, Object arg2,
145138
@SuppressWarnings("unused") @Cached("func") PBuiltinFunction cachedFunc,
146-
@SuppressWarnings("unused") @Cached("isForReverseBinaryOperation(func.getCallTarget())") boolean isReverse,
147139
@Cached("getBuiltin(frame, func, 2)") PythonBuiltinBaseNode builtinNode) {
148-
if (isReverse) {
149-
return callBinaryBuiltin(frame, builtinNode, arg2, arg1);
150-
} else {
151-
return callBinaryBuiltin(frame, builtinNode, arg1, arg2);
152-
}
140+
return callBinaryBuiltin(frame, builtinNode, arg1, arg2);
153141
}
154142

155143
@Specialization(guards = {"func.getCallTarget() == ct", "builtinNode != null"}, //
156144
limit = "getCallSiteInlineCacheMaxDepth()")
157145
static Object callObject(VirtualFrame frame, @SuppressWarnings("unused") PBuiltinFunction func, Object arg1, Object arg2,
158146
@SuppressWarnings("unused") @Cached("func.getCallTarget()") RootCallTarget ct,
159-
@SuppressWarnings("unused") @Cached("isForReverseBinaryOperation(func.getCallTarget())") boolean isReverse,
160147
@Cached("getBuiltin(frame, func, 2)") PythonBuiltinBaseNode builtinNode) {
161-
if (isReverse) {
162-
return callBinaryBuiltin(frame, builtinNode, arg2, arg1);
163-
} else {
164-
return callBinaryBuiltin(frame, builtinNode, arg1, arg2);
165-
}
148+
return callBinaryBuiltin(frame, builtinNode, arg1, arg2);
166149
}
167150

168151
@Specialization(guards = {"isSingleContext()", "func == cachedFunc", "builtinNode != null", "!takesSelfArg"}, limit = "getCallSiteInlineCacheMaxDepth()")

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/CallReversibleMethodNode.java

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

0 commit comments

Comments
 (0)