Skip to content

Commit 0f6d969

Browse files
committed
[GR-9150][GR-9138][GR-9151] Revert outdated stdlib and test patches
PullRequest: graalpython/1364
2 parents 6cff59f + 1d6bf60 commit 0f6d969

File tree

15 files changed

+121
-59
lines changed

15 files changed

+121
-59
lines changed

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

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
import com.oracle.graal.python.builtins.CoreFunctions;
107107
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
108108
import com.oracle.graal.python.builtins.PythonBuiltins;
109+
import com.oracle.graal.python.builtins.modules.WarningsModuleBuiltins.WarnNode;
109110
import com.oracle.graal.python.builtins.modules.WeakRefModuleBuiltins.GetWeakRefsNode;
110111
import com.oracle.graal.python.builtins.objects.PEllipsis;
111112
import com.oracle.graal.python.builtins.objects.PNone;
@@ -354,7 +355,9 @@ public abstract static class ComplexNode extends PythonBuiltinNode {
354355

355356
@Child private IsBuiltinClassProfile isPrimitiveProfile = IsBuiltinClassProfile.create();
356357
@Child private IsBuiltinClassProfile isComplexTypeProfile;
358+
@Child private IsBuiltinClassProfile isResultComplexTypeProfile;
357359
@Child private LookupAndCallUnaryNode callReprNode;
360+
@Child private WarnNode warnNode;
358361

359362
private PComplex createComplex(Object cls, double real, double imaginary) {
360363
if (isPrimitiveProfile.profileClass(cls, PythonBuiltinClassType.PComplex)) {
@@ -562,6 +565,22 @@ private IsBuiltinClassProfile getIsComplexTypeProfile() {
562565
return isComplexTypeProfile;
563566
}
564567

568+
private IsBuiltinClassProfile getIsResultComplexTypeProfile() {
569+
if (isResultComplexTypeProfile == null) {
570+
CompilerDirectives.transferToInterpreterAndInvalidate();
571+
isResultComplexTypeProfile = insert(IsBuiltinClassProfile.create());
572+
}
573+
return isResultComplexTypeProfile;
574+
}
575+
576+
private WarnNode getWarnNode() {
577+
if (warnNode == null) {
578+
CompilerDirectives.transferToInterpreterAndInvalidate();
579+
warnNode = insert(WarnNode.create());
580+
}
581+
return warnNode;
582+
}
583+
565584
private PException raiseFirstArgError(Object x) {
566585
throw raise(PythonBuiltinClassType.TypeError, ErrorMessages.ARG_MUST_BE_STRING_OR_NUMBER, "complex() first", x);
567586
}
@@ -578,14 +597,14 @@ private PComplex getComplexNumberFromObject(VirtualFrame frame, Object object, P
578597
if (complexCallable != PNone.NO_VALUE) {
579598
Object result = methodLib.callUnboundMethod(complexCallable, frame, object);
580599
if (result instanceof PComplex) {
581-
// TODO we need pass here deprecation warning
582-
// DeprecationWarning: __complex__ returned non-complex (type %p).
583-
// The ability to return an instance of a strict subclass of complex is
584-
// deprecated,
585-
// and may be removed in a future version of Python.
600+
if (!getIsResultComplexTypeProfile().profileObject(result, PythonBuiltinClassType.PComplex)) {
601+
getWarnNode().warnFormat(frame, null, PythonBuiltinClassType.DeprecationWarning, 1,
602+
ErrorMessages.P_RETURNED_NON_P,
603+
object, "__complex__", "complex", result, "complex");
604+
}
586605
return (PComplex) result;
587606
} else {
588-
throw raise(TypeError, ErrorMessages.COMPLEX_SHOULD_RETURN_COMPLEX);
607+
throw raise(TypeError, ErrorMessages.COMPLEX_RETURNED_NON_COMPLEX, result);
589608
}
590609
}
591610
if (object instanceof PComplex) {
@@ -966,6 +985,7 @@ static boolean isHandledType(PythonObjectLibrary lib, Object o) {
966985
@Specialization(guards = {"isPrimitiveFloat(cls)", "!isHandledType(objectLib, obj)"}, limit = "1")
967986
double doubleFromObject(VirtualFrame frame, @SuppressWarnings("unused") Object cls, Object obj,
968987
@CachedLibrary("obj") PythonObjectLibrary objectLib,
988+
@Cached WarnNode warnNode,
969989
@CachedLibrary(limit = "1") PythonObjectLibrary methodLib,
970990
@CachedLibrary(limit = "1") PythonObjectLibrary indexLib) {
971991
// Follows logic from PyNumber_Float:
@@ -981,7 +1001,9 @@ static boolean isHandledType(PythonObjectLibrary lib, Object o) {
9811001
}
9821002
if (PGuards.isPFloat(result)) {
9831003
if (!isPrimitiveProfile.profileObject(result, PythonBuiltinClassType.PFloat)) {
984-
// TODO deprecation warning
1004+
warnNode.warnFormat(frame, null, PythonBuiltinClassType.DeprecationWarning, 1,
1005+
ErrorMessages.P_RETURNED_NON_P,
1006+
obj, "__float__", "float", result, "float");
9851007
}
9861008
return ((PFloat) result).getValue();
9871009
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,9 @@ public boolean doString(String arg1, String arg2) {
185185
@GenerateNodeFactory
186186
abstract static class IndexNode extends PythonUnaryBuiltinNode {
187187
@Specialization(limit = "getCallSiteInlineCacheMaxDepth()")
188-
Object asIndex(Object value,
188+
Object asIndex(VirtualFrame frame, Object value,
189189
@CachedLibrary(value = "value") PythonObjectLibrary pol) {
190-
return pol.asIndex(value);
190+
return pol.asIndexWithFrame(value, frame);
191191
}
192192
}
193193
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
import com.oracle.truffle.api.nodes.UnexpectedResultException;
106106
import com.oracle.truffle.api.object.DynamicObjectLibrary;
107107
import com.oracle.truffle.api.object.HiddenKey;
108+
import com.oracle.truffle.api.profiles.BranchProfile;
108109

109110
@CoreFunctions(defineModule = "_warnings")
110111
public class WarningsModuleBuiltins extends PythonBuiltins {
@@ -942,12 +943,18 @@ public final void warn(Frame frame, Object category, String message) {
942943
protected abstract void execute(Frame frame, Object source, Object category, String format, int stackLevel, Object... formatArgs);
943944

944945
private static final class WarnNodeCached extends WarnNode {
946+
@CompilationFinal BranchProfile noFrame = BranchProfile.create();
945947
@CompilationFinal ContextReference<PythonContext> ctxRef;
946948
@Child PythonObjectLibrary lib;
947949
@Child WarningsModuleNode moduleFunctionsNode;
948950

949951
@Override
950952
protected void execute(Frame frame, Object source, Object category, String format, int stackLevel, Object... formatArgs) {
953+
if (frame == null) {
954+
noFrame.enter();
955+
UNCACHED.execute(null, source, category, format, stackLevel, formatArgs);
956+
return;
957+
}
951958
assert frame instanceof VirtualFrame;
952959
if (ctxRef == null) {
953960
CompilerDirectives.transferToInterpreterAndInvalidate();
@@ -1006,7 +1013,6 @@ protected void execute(Frame frame, Object source, Object category, String forma
10061013
}
10071014
lib.callObject(warn, null, message, category, stackLevel, source);
10081015
}
1009-
10101016
}
10111017
}
10121018
}

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

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
7979
import com.oracle.graal.python.builtins.modules.BuiltinFunctions;
8080
import com.oracle.graal.python.builtins.modules.MathGuards;
81+
import com.oracle.graal.python.builtins.modules.WarningsModuleBuiltins.WarnNode;
8182
import com.oracle.graal.python.builtins.objects.bytes.PBytes;
8283
import com.oracle.graal.python.builtins.objects.cext.capi.CApiGuards;
8384
import com.oracle.graal.python.builtins.objects.cext.capi.DynamicObjectNativeWrapper;
@@ -238,7 +239,7 @@ public void writeMember(String key, Object value,
238239
@Exclusive @Cached KeyForAttributeAccess getAttributeKey,
239240
@Exclusive @Cached KeyForItemAccess getItemKey,
240241
@Cached PInteropSetAttributeNode writeNode,
241-
@Exclusive @Cached IsBuiltinClassProfile attrErrorProfile) throws UnsupportedMessageException, UnknownIdentifierException {
242+
@Shared("attributeErrorProfile") @Cached IsBuiltinClassProfile attrErrorProfile) throws UnsupportedMessageException, UnknownIdentifierException {
242243
try {
243244
String attrKey = getAttributeKey.execute(key);
244245
if (attrKey != null) {
@@ -490,7 +491,7 @@ public Object invokeMember(String member, Object[] arguments,
490491
@Exclusive @Cached PExecuteNode executeNode,
491492
@Exclusive @Cached ConditionProfile profileGetattribute,
492493
@Exclusive @Cached ConditionProfile profileMember,
493-
@Exclusive @Cached IsBuiltinClassProfile attributeErrorProfile) throws UnknownIdentifierException, UnsupportedMessageException {
494+
@Shared("attributeErrorProfile") @Cached IsBuiltinClassProfile attributeErrorProfile) throws UnknownIdentifierException, UnsupportedMessageException {
494495
Object memberObj;
495496
try {
496497
Object attrGetattribute = lookupGetattributeNode.execute(this, __GETATTRIBUTE__);
@@ -569,7 +570,7 @@ public void removeMember(String member,
569570
@Exclusive @Cached LookupInheritedAttributeNode.Dynamic getDelItemNode,
570571
@Cached PInteropDeleteAttributeNode deleteAttributeNode,
571572
@Exclusive @Cached PInteropDeleteItemNode delItemNode,
572-
@Exclusive @Cached IsBuiltinClassProfile attrErrorProfile) throws UnsupportedMessageException, UnknownIdentifierException {
573+
@Shared("attributeErrorProfile") @Cached IsBuiltinClassProfile attrErrorProfile) throws UnsupportedMessageException, UnknownIdentifierException {
573574
try {
574575
String attrKey = getAttributeKey.execute(member);
575576
if (attrKey != null) {
@@ -825,7 +826,10 @@ public Object asIndexWithState(ThreadState state,
825826
@Shared("raise") @Cached PRaiseNode raise,
826827
@Shared("isSubtypeNode") @Cached IsSubtypeNode isSubtype,
827828
@Exclusive @Cached ConditionProfile noIndex,
828-
@Exclusive @Cached ConditionProfile resultProfile) {
829+
@Exclusive @Cached ConditionProfile resultProfile,
830+
@Shared("gotState") @Cached ConditionProfile gotState,
831+
@Shared("intProfile") @Cached IsBuiltinClassProfile isInt,
832+
@Cached WarnNode warnNode) {
829833
// n.b.: the CPython shortcut "if (PyLong_Check(item)) return item;" is
830834
// implemented in the specific Java classes PInt, PythonNativeVoidPtr,
831835
// and PythonAbstractNativeObject and dispatched polymorphically
@@ -835,10 +839,18 @@ public Object asIndexWithState(ThreadState state,
835839
}
836840

837841
Object result = methodLib.callUnboundMethodWithState(indexMethod, state, this);
838-
839842
if (resultProfile.profile(!isSubtype.execute(resultLib.getLazyPythonClass(result), PythonBuiltinClassType.PInt))) {
840843
throw raise.raise(PythonBuiltinClassType.TypeError, ErrorMessages.INDEX_RETURNED_NON_INT, result);
841844
}
845+
if (!isInt.profileObject(result, PythonBuiltinClassType.PInt)) {
846+
VirtualFrame frame = null;
847+
if (gotState.profile(state != null)) {
848+
frame = PArguments.frameForCall(state);
849+
}
850+
warnNode.warnFormat(frame, null, PythonBuiltinClassType.DeprecationWarning, 1,
851+
ErrorMessages.P_RETURNED_NON_P,
852+
this, "__index__", "int", result, "int");
853+
}
842854
return result;
843855
}
844856

@@ -884,10 +896,9 @@ public static Object asPString(PythonObjectLibrary lib, Object receiver, ThreadS
884896
public int asFileDescriptorWithState(ThreadState state,
885897
@CachedLibrary("this") PythonObjectLibrary lib,
886898
@Shared("methodLib") @CachedLibrary(limit = "2") PythonObjectLibrary methodLib,
887-
@CachedLibrary(limit = "1") PythonObjectLibrary libResult,
888899
@Shared("raise") @Cached PRaiseNode raiseNode,
889900
@Exclusive @Cached BranchProfile noFilenoMethodProfile,
890-
@Exclusive @Cached IsBuiltinClassProfile isIntProfile,
901+
@Shared("intProfile") @Cached IsBuiltinClassProfile isIntProfile,
891902
@Exclusive @Cached CastToJavaIntExactNode castToJavaIntNode,
892903
@Exclusive @Cached IsBuiltinClassProfile isAttrError) {
893904

@@ -898,7 +909,7 @@ public int asFileDescriptorWithState(ThreadState state,
898909
}
899910

900911
Object result = methodLib.callObjectWithState(filenoFunc, state);
901-
if (isIntProfile.profileClass(libResult.getLazyPythonClass(result), PythonBuiltinClassType.PInt)) {
912+
if (isIntProfile.profileObject(result, PythonBuiltinClassType.PInt)) {
902913
try {
903914
return castToJavaIntNode.execute(result);
904915
} catch (PException e) {

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747

4848
import com.oracle.graal.python.PythonLanguage;
4949
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
50+
import com.oracle.graal.python.builtins.modules.WarningsModuleBuiltins.WarnNode;
5051
import com.oracle.graal.python.builtins.objects.PNone;
5152
import com.oracle.graal.python.builtins.objects.PythonAbstractObject;
5253
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.AsPythonObjectNode;
@@ -57,6 +58,7 @@
5758
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodesFactory.AsPythonObjectNodeGen;
5859
import com.oracle.graal.python.builtins.objects.cext.capi.NativeMember;
5960
import com.oracle.graal.python.builtins.objects.dict.PDict;
61+
import com.oracle.graal.python.builtins.objects.function.PArguments;
6062
import com.oracle.graal.python.builtins.objects.function.PArguments.ThreadState;
6163
import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
6264
import com.oracle.graal.python.builtins.objects.type.TypeNodes;
@@ -65,6 +67,7 @@
6567
import com.oracle.graal.python.nodes.ErrorMessages;
6668
import com.oracle.graal.python.nodes.PRaiseNode;
6769
import com.oracle.graal.python.nodes.classes.IsSubtypeNode;
70+
import com.oracle.graal.python.nodes.object.IsBuiltinClassProfile;
6871
import com.oracle.truffle.api.Assumption;
6972
import com.oracle.truffle.api.CompilerAsserts;
7073
import com.oracle.truffle.api.CompilerDirectives;
@@ -75,6 +78,7 @@
7578
import com.oracle.truffle.api.dsl.Fallback;
7679
import com.oracle.truffle.api.dsl.GenerateUncached;
7780
import com.oracle.truffle.api.dsl.Specialization;
81+
import com.oracle.truffle.api.frame.VirtualFrame;
7882
import com.oracle.truffle.api.interop.InteropLibrary;
7983
import com.oracle.truffle.api.interop.TruffleObject;
8084
import com.oracle.truffle.api.interop.UnknownIdentifierException;
@@ -175,11 +179,23 @@ public Object asIndexWithState(ThreadState threadState,
175179
@CachedLibrary(limit = "5") PythonObjectLibrary resultLib,
176180
@Exclusive @Cached PRaiseNode raise,
177181
@Exclusive @Cached ConditionProfile noIndex,
178-
@Exclusive @Cached ConditionProfile resultProfile) {
182+
@Exclusive @Cached ConditionProfile resultProfile,
183+
@Exclusive @Cached ConditionProfile gotState,
184+
@Cached IsBuiltinClassProfile isInt,
185+
@Cached WarnNode warnNode) {
179186
if (isSubtypeNode.execute(plib.getLazyPythonClass(this), PythonBuiltinClassType.PInt)) {
187+
if (!isInt.profileObject(this, PythonBuiltinClassType.PInt)) {
188+
VirtualFrame frame = null;
189+
if (gotState.profile(threadState != null)) {
190+
frame = PArguments.frameForCall(threadState);
191+
}
192+
warnNode.warnFormat(frame, null, PythonBuiltinClassType.DeprecationWarning, 1,
193+
ErrorMessages.P_RETURNED_NON_P,
194+
this, "__index__", "int", this, "int");
195+
}
180196
return this; // subclasses of 'int' should do early return
181197
} else {
182-
return asIndexWithState(threadState, plib, methodLib, resultLib, raise, isSubtypeNode, noIndex, resultProfile);
198+
return asIndexWithState(threadState, plib, methodLib, resultLib, raise, isSubtypeNode, noIndex, resultProfile, gotState, isInt, warnNode);
183199
}
184200
}
185201

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/PInt.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,15 @@
3232
import com.oracle.graal.python.PythonLanguage;
3333
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
3434
import com.oracle.graal.python.builtins.modules.SysModuleBuiltins;
35+
import com.oracle.graal.python.builtins.modules.WarningsModuleBuiltins.WarnNode;
3536
import com.oracle.graal.python.builtins.objects.cext.capi.PythonNativeWrapperLibrary;
37+
import com.oracle.graal.python.builtins.objects.function.PArguments;
3638
import com.oracle.graal.python.builtins.objects.function.PArguments.ThreadState;
3739
import com.oracle.graal.python.builtins.objects.object.PythonBuiltinObject;
3840
import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
3941
import com.oracle.graal.python.nodes.ErrorMessages;
4042
import com.oracle.graal.python.nodes.PRaiseNode;
43+
import com.oracle.graal.python.nodes.object.IsBuiltinClassProfile;
4144
import com.oracle.graal.python.nodes.util.CastToJavaDoubleNode;
4245
import com.oracle.graal.python.nodes.util.CastToJavaIntExactNode;
4346
import com.oracle.graal.python.nodes.util.CastToJavaLongLossyNode;
@@ -50,13 +53,15 @@
5053
import com.oracle.truffle.api.dsl.Cached.Exclusive;
5154
import com.oracle.truffle.api.dsl.Cached.Shared;
5255
import com.oracle.truffle.api.dsl.CachedContext;
56+
import com.oracle.truffle.api.frame.VirtualFrame;
5357
import com.oracle.truffle.api.interop.InteropLibrary;
5458
import com.oracle.truffle.api.interop.UnsupportedMessageException;
5559
import com.oracle.truffle.api.library.CachedLibrary;
5660
import com.oracle.truffle.api.library.ExportLibrary;
5761
import com.oracle.truffle.api.library.ExportMessage;
5862
import com.oracle.truffle.api.library.ExportMessage.Ignore;
5963
import com.oracle.truffle.api.object.Shape;
64+
import com.oracle.truffle.api.profiles.ConditionProfile;
6065

6166
@ExportLibrary(InteropLibrary.class)
6267
public final class PInt extends PythonBuiltinObject {
@@ -224,7 +229,19 @@ public boolean canBeIndex() {
224229
}
225230

226231
@ExportMessage
227-
public Object asIndexWithState(@SuppressWarnings("unused") ThreadState threadState) {
232+
public Object asIndexWithState(@SuppressWarnings("unused") ThreadState threadState,
233+
@Cached ConditionProfile gotState,
234+
@Cached IsBuiltinClassProfile isInt,
235+
@Cached WarnNode warnNode) {
236+
if (!isInt.profileObject(this, PythonBuiltinClassType.PInt)) {
237+
VirtualFrame frame = null;
238+
if (gotState.profile(threadState != null)) {
239+
frame = PArguments.frameForCall(threadState);
240+
}
241+
warnNode.warnFormat(frame, null, PythonBuiltinClassType.DeprecationWarning, 1,
242+
ErrorMessages.P_RETURNED_NON_P,
243+
this, "__index__", "int", this, "int");
244+
}
228245
return this;
229246
}
230247

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/ErrorMessages.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@ public abstract class ErrorMessages {
183183
public static final String COMPLEX_ZERO_TO_NEGATIVE_POWER = "0.0 to a negative or complex power";
184184
public static final String COMPLEX_MODULO = "complex modulo";
185185
public static final String COMPLEX_RETURNED_NON_COMPLEX = "__complex__ returned non-complex (type %p)";
186-
public static final String COMPLEX_SHOULD_RETURN_COMPLEX = "__complex__ should return a complex object";
187186
public static final String CONTIGUOUS_BUFFER = "contiguous buffer";
188187
public static final String CONVERTER_FUNC_FAILED_TO_SET_ERROR = "converter function failed to set an error on failure";
189188
public static final String CORRUPTED_CAPI_LIB_OBJ = "corrupted C API library object: %s";
@@ -620,4 +619,8 @@ public abstract class ErrorMessages {
620619
public static final String EXPECTED_BYTES_P_FOUND = "expected bytes, %p found";
621620
public static final String EMBEDDED_NULL_BYTE = "embedded null byte";
622621
public static final String CANNOT_INTERN_P = "can't intern %p";
622+
623+
public static final String P_RETURNED_NON_P = "%p.%s returned non-%s (type %p). " +
624+
"The ability to return an instance of a strict subclass of %s " +
625+
"is deprecated, and may be removed in a future version of Python.";
623626
}

0 commit comments

Comments
 (0)