diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/ExternalFunctionNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/ExternalFunctionNodes.java index 29769da5a9..18d2331c48 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/ExternalFunctionNodes.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/ExternalFunctionNodes.java @@ -55,6 +55,7 @@ import static com.oracle.graal.python.builtins.objects.cext.capi.transitions.ArgDescriptor.PyObjectTransfer; import static com.oracle.graal.python.builtins.objects.cext.capi.transitions.ArgDescriptor.PyTypeObject; import static com.oracle.graal.python.builtins.objects.cext.capi.transitions.ArgDescriptor.Py_ssize_t; +import static com.oracle.graal.python.nodes.StringLiterals.T_EMPTY_STRING; import static com.oracle.graal.python.util.PythonUtils.TS_ENCODING; import static com.oracle.graal.python.util.PythonUtils.tsArray; import static com.oracle.graal.python.util.PythonUtils.tsLiteral; @@ -807,8 +808,16 @@ public String getSignature() { } } + private static Signature createSignature(boolean takesVarKeywordArgs, int varArgIndex, TruffleString[] parameters, boolean checkEnclosingType, boolean hidden) { + return new Signature(-1, takesVarKeywordArgs, varArgIndex, false, parameters, KEYWORDS_HIDDEN_CALLABLE, checkEnclosingType, T_EMPTY_STRING, hidden); + } + + private static Signature createSignatureWithClosure(boolean takesVarKeywordArgs, int varArgIndex, TruffleString[] parameters, boolean checkEnclosingType, boolean hidden) { + return new Signature(-1, takesVarKeywordArgs, varArgIndex, false, parameters, KEYWORDS_HIDDEN_CALLABLE_AND_CLOSURE, checkEnclosingType, T_EMPTY_STRING, hidden); + } + static final class MethDirectRoot extends MethodDescriptorRoot { - private static final Signature SIGNATURE = new Signature(-1, true, 0, false, null, KEYWORDS_HIDDEN_CALLABLE); + private static final Signature SIGNATURE = createSignature(true, 0, null, false, true); private MethDirectRoot(PythonLanguage lang, TruffleString name, PExternalFunctionWrapper provider) { super(lang, name, true, provider); @@ -1117,7 +1126,7 @@ protected final Object readSelf(VirtualFrame frame) { } public static final class MethKeywordsRoot extends MethodDescriptorRoot { - private static final Signature SIGNATURE = new Signature(-1, true, 1, false, tsArray("self"), KEYWORDS_HIDDEN_CALLABLE, true); + private static final Signature SIGNATURE = createSignature(true, 1, tsArray("self"), true, true); @Child private PythonObjectFactory factory; @Child private ReadVarArgsNode readVarargsNode; @Child private ReadVarKeywordsNode readKwargsNode; @@ -1165,7 +1174,7 @@ public Signature getSignature() { } public static final class MethVarargsRoot extends MethodDescriptorRoot { - private static final Signature SIGNATURE = new Signature(-1, false, 1, false, tsArray("self"), KEYWORDS_HIDDEN_CALLABLE, true); + private static final Signature SIGNATURE = createSignature(false, 1, tsArray("self"), true, true); @Child private PythonObjectFactory factory; @Child private ReadVarArgsNode readVarargsNode; @Child private CreateArgsTupleNode createArgsTupleNode; @@ -1259,7 +1268,7 @@ public Signature getSignature() { } public static final class MethInquiryRoot extends MethodDescriptorRoot { - private static final Signature SIGNATURE = new Signature(-1, false, -1, false, tsArray("self"), KEYWORDS_HIDDEN_CALLABLE, true); + private static final Signature SIGNATURE = createSignature(false, -1, tsArray("self"), true, false); public MethInquiryRoot(PythonLanguage language, TruffleString name, boolean isStatic) { super(language, name, isStatic); @@ -1286,7 +1295,7 @@ public Signature getSignature() { } public static final class MethNoargsRoot extends MethodDescriptorRoot { - private static final Signature SIGNATURE = new Signature(-1, false, -1, false, tsArray("self"), KEYWORDS_HIDDEN_CALLABLE, true); + private static final Signature SIGNATURE = createSignature(false, -1, tsArray("self"), true, true); public MethNoargsRoot(PythonLanguage language, TruffleString name, boolean isStatic) { super(language, name, isStatic); @@ -1313,7 +1322,7 @@ public Signature getSignature() { } public static final class MethORoot extends MethodDescriptorRoot { - private static final Signature SIGNATURE = new Signature(-1, false, -1, false, tsArray("self", "arg"), KEYWORDS_HIDDEN_CALLABLE, true); + private static final Signature SIGNATURE = createSignature(false, -1, tsArray("self", "arg"), true, true); @Child private ReadIndexedArgumentNode readArgNode; public MethORoot(PythonLanguage language, TruffleString name, boolean isStatic) { @@ -1346,7 +1355,7 @@ public Signature getSignature() { } public static final class MethFastcallWithKeywordsRoot extends MethodDescriptorRoot { - private static final Signature SIGNATURE = new Signature(-1, true, 1, false, tsArray("self"), KEYWORDS_HIDDEN_CALLABLE, true); + private static final Signature SIGNATURE = createSignature(true, 1, tsArray("self"), true, true); @Child private PythonObjectFactory factory; @Child private ReadVarArgsNode readVarargsNode; @Child private ReadVarKeywordsNode readKwargsNode; @@ -1393,7 +1402,7 @@ public Signature getSignature() { } public static final class MethMethodRoot extends MethodDescriptorRoot { - private static final Signature SIGNATURE = new Signature(-1, true, 1, false, tsArray("self", "cls"), KEYWORDS_HIDDEN_CALLABLE, true); + private static final Signature SIGNATURE = createSignature(true, 1, tsArray("self", "cls"), true, true); @Child private PythonObjectFactory factory; @Child private ReadIndexedArgumentNode readClsNode; @Child private ReadVarArgsNode readVarargsNode; @@ -1444,7 +1453,7 @@ public Signature getSignature() { } public static final class MethFastcallRoot extends MethodDescriptorRoot { - private static final Signature SIGNATURE = new Signature(-1, false, 1, false, tsArray("self"), KEYWORDS_HIDDEN_CALLABLE, true); + private static final Signature SIGNATURE = createSignature(false, 1, tsArray("self"), true, true); @Child private ReadVarArgsNode readVarargsNode; public MethFastcallRoot(PythonLanguage language, TruffleString name, boolean isStatic) { @@ -1481,7 +1490,7 @@ public Signature getSignature() { * Wrapper root node for C function type {@code allocfunc} and {@code ssizeargfunc}. */ static class AllocFuncRootNode extends MethodDescriptorRoot { - private static final Signature SIGNATURE = new Signature(-1, false, -1, false, tsArray("self", "nitems"), KEYWORDS_HIDDEN_CALLABLE, true); + private static final Signature SIGNATURE = createSignature(false, -1, tsArray("self", "nitems"), true, false); @Child private ReadIndexedArgumentNode readArgNode; @Child private ConvertPIntToPrimitiveNode asSsizeTNode; @@ -1521,7 +1530,7 @@ public Signature getSignature() { * Wrapper root node for a get attribute function (C type {@code getattrfunc}). */ static final class GetAttrFuncRootNode extends MethodDescriptorRoot { - private static final Signature SIGNATURE = new Signature(-1, false, -1, false, tsArray("self", "key"), KEYWORDS_HIDDEN_CALLABLE, true); + private static final Signature SIGNATURE = createSignature(false, -1, tsArray("self", "key"), true, false); @Child private ReadIndexedArgumentNode readArgNode; @Child private CExtNodes.AsCharPointerNode asCharPointerNode; @Child private CStructAccess.FreeNode free; @@ -1562,7 +1571,7 @@ public Signature getSignature() { * Wrapper root node for a set attribute function (C type {@code setattrfunc}). */ static final class SetAttrFuncRootNode extends MethodDescriptorRoot { - private static final Signature SIGNATURE = new Signature(-1, false, -1, false, tsArray("self", "key", "value"), KEYWORDS_HIDDEN_CALLABLE, true); + private static final Signature SIGNATURE = createSignature(false, -1, tsArray("self", "key", "value"), true, false); @Child private ReadIndexedArgumentNode readArg1Node; @Child private ReadIndexedArgumentNode readArg2Node; @Child private CExtNodes.AsCharPointerNode asCharPointerNode; @@ -1608,7 +1617,7 @@ public Signature getSignature() { * Wrapper root node for a rich compare function (C type {@code richcmpfunc}). */ static final class RichCmpFuncRootNode extends MethodDescriptorRoot { - private static final Signature SIGNATURE = new Signature(-1, false, -1, false, tsArray("self", "other", "op"), KEYWORDS_HIDDEN_CALLABLE, true); + private static final Signature SIGNATURE = createSignature(false, -1, tsArray("self", "other", "op"), true, false); @Child private ReadIndexedArgumentNode readArg1Node; @Child private ReadIndexedArgumentNode readArg2Node; @Child private ConvertPIntToPrimitiveNode asSsizeTNode; @@ -1653,7 +1662,7 @@ public Signature getSignature() { * Implements semantics of {@code typeobject.c: wrap_sq_item}. */ static final class GetItemRootNode extends MethodDescriptorRoot { - private static final Signature SIGNATURE = new Signature(-1, false, -1, false, tsArray("self", "i"), KEYWORDS_HIDDEN_CALLABLE, true); + private static final Signature SIGNATURE = createSignature(false, -1, tsArray("self", "i"), true, false); @Child private ReadIndexedArgumentNode readArg1Node; @Child private GetIndexNode getIndexNode; @@ -1689,7 +1698,7 @@ public Signature getSignature() { * Implements semantics of {@code typeobject.c: wrap_sq_setitem}. */ static final class SetItemRootNode extends MethodDescriptorRoot { - private static final Signature SIGNATURE = new Signature(-1, false, -1, false, tsArray("self", "i", "value"), KEYWORDS_HIDDEN_CALLABLE, true); + private static final Signature SIGNATURE = createSignature(false, -1, tsArray("self", "i", "value"), true, false); @Child private ReadIndexedArgumentNode readArg1Node; @Child private ReadIndexedArgumentNode readArg2Node; @Child private GetIndexNode getIndexNode; @@ -1730,7 +1739,7 @@ public Signature getSignature() { * Implements semantics of {@code typeobject.c:wrap_descr_get} */ public static final class DescrGetRootNode extends MethodDescriptorRoot { - private static final Signature SIGNATURE = new Signature(-1, false, -1, false, tsArray("self", "obj", "type"), KEYWORDS_HIDDEN_CALLABLE, true); + private static final Signature SIGNATURE = createSignature(false, -1, tsArray("self", "obj", "type"), true, false); @Child private ReadIndexedArgumentNode readObj; @Child private ReadIndexedArgumentNode readType; @@ -1770,7 +1779,7 @@ public Signature getSignature() { * Implements semantics of {@code typeobject.c:wrap_descr_delete} */ public static final class DescrDeleteRootNode extends MethodDescriptorRoot { - private static final Signature SIGNATURE = new Signature(-1, false, -1, false, tsArray("self", "obj"), KEYWORDS_HIDDEN_CALLABLE, true); + private static final Signature SIGNATURE = createSignature(false, -1, tsArray("self", "obj"), true, false); @Child private ReadIndexedArgumentNode readObj; public DescrDeleteRootNode(PythonLanguage language, TruffleString name) { @@ -1806,7 +1815,7 @@ public Signature getSignature() { * Implements semantics of {@code typeobject.c:wrap_delattr} */ public static final class DelAttrRootNode extends MethodDescriptorRoot { - private static final Signature SIGNATURE = new Signature(-1, false, -1, false, tsArray("self", "obj"), KEYWORDS_HIDDEN_CALLABLE, true); + private static final Signature SIGNATURE = createSignature(false, -1, tsArray("self", "obj"), true, false); @Child private ReadIndexedArgumentNode readObj; public DelAttrRootNode(PythonLanguage language, TruffleString name) { @@ -1844,7 +1853,7 @@ public Signature getSignature() { * NULL 3rd argument. */ static final class MpDelItemRootNode extends MethodDescriptorRoot { - private static final Signature SIGNATURE = new Signature(-1, false, -1, false, tsArray("self", "i"), KEYWORDS_HIDDEN_CALLABLE, true); + private static final Signature SIGNATURE = createSignature(false, -1, tsArray("self", "i"), true, false); @Child private ReadIndexedArgumentNode readArg1Node; MpDelItemRootNode(PythonLanguage language, TruffleString name) { @@ -1881,7 +1890,7 @@ public Signature getSignature() { * Wrapper root node for reverse binary operations. */ static final class MethReverseRootNode extends MethodDescriptorRoot { - private static final Signature SIGNATURE = new Signature(-1, false, -1, false, tsArray("self", "obj"), KEYWORDS_HIDDEN_CALLABLE, true); + private static final Signature SIGNATURE = createSignature(false, -1, tsArray("self", "obj"), true, false); @Child private ReadIndexedArgumentNode readArg0Node; @Child private ReadIndexedArgumentNode readArg1Node; @@ -1928,7 +1937,7 @@ public Signature getSignature() { * Wrapper root node for native power function (with an optional third argument). */ static class MethPowRootNode extends MethodDescriptorRoot { - private static final Signature SIGNATURE = new Signature(false, 0, false, tsArray("args"), KEYWORDS_HIDDEN_CALLABLE); + private static final Signature SIGNATURE = createSignature(false, 0, tsArray("args"), false, false); @Child private ReadVarArgsNode readVarargsNode; @@ -1995,7 +2004,7 @@ Object[] getArguments(Object arg0, Object arg1, Object arg2) { * Wrapper root node for native power function (with an optional third argument). */ static final class MethRichcmpOpRootNode extends MethodDescriptorRoot { - private static final Signature SIGNATURE = new Signature(-1, false, -1, false, tsArray("self", "other"), KEYWORDS_HIDDEN_CALLABLE, true); + private static final Signature SIGNATURE = createSignature(false, -1, tsArray("self", "other"), true, false); @Child private ReadIndexedArgumentNode readArgNode; private final int op; @@ -2093,7 +2102,7 @@ protected final Object readClosure(VirtualFrame frame) { * Wrapper root node for C function type {@code getter}. */ public static class GetterRoot extends GetSetRootNode { - private static final Signature SIGNATURE = new Signature(-1, false, -1, false, tsArray("self"), KEYWORDS_HIDDEN_CALLABLE_AND_CLOSURE, true); + private static final Signature SIGNATURE = createSignatureWithClosure(false, -1, tsArray("self"), true, false); public GetterRoot(PythonLanguage language, TruffleString name, PExternalFunctionWrapper provider) { super(language, name, provider); @@ -2120,7 +2129,7 @@ public Signature getSignature() { * Wrapper root node for C function type {@code setter}. */ public static class SetterRoot extends GetSetRootNode { - private static final Signature SIGNATURE = new Signature(-1, false, -1, false, tsArray("self", "value"), KEYWORDS_HIDDEN_CALLABLE_AND_CLOSURE, true); + private static final Signature SIGNATURE = createSignatureWithClosure(false, -1, tsArray("self", "value"), true, false); @Child private ReadIndexedArgumentNode readArgNode; diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/AbstractFunctionBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/AbstractFunctionBuiltins.java index f237e0d69c..0582591478 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/AbstractFunctionBuiltins.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/AbstractFunctionBuiltins.java @@ -301,8 +301,13 @@ static Object setFunction(PFunction self, Object value, } @Specialization(guards = "isNoValue(none)") - static TruffleString getBuiltin(PBuiltinFunction self, @SuppressWarnings("unused") PNone none) { + @TruffleBoundary + static TruffleString getBuiltin(PBuiltinFunction self, @SuppressWarnings("unused") PNone none, + @Bind("this") Node inliningTarget) { Signature signature = self.getSignature(); + if (signature.isHidden()) { + throw PRaiseNode.raiseUncached(inliningTarget, AttributeError, ErrorMessages.HAS_NO_ATTR, self, T___TEXT_SIGNATURE__); + } return signatureToText(signature, false); } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/BuiltinFunctionBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/BuiltinFunctionBuiltins.java index 67451cec94..2a98c32ba2 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/BuiltinFunctionBuiltins.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/BuiltinFunctionBuiltins.java @@ -26,10 +26,12 @@ package com.oracle.graal.python.builtins.objects.function; +import static com.oracle.graal.python.builtins.PythonBuiltinClassType.AttributeError; import static com.oracle.graal.python.nodes.BuiltinNames.T_GETATTR; import static com.oracle.graal.python.nodes.SpecialAttributeNames.J___NAME__; import static com.oracle.graal.python.nodes.SpecialAttributeNames.J___QUALNAME__; import static com.oracle.graal.python.nodes.SpecialAttributeNames.J___SIGNATURE__; +import static com.oracle.graal.python.nodes.SpecialAttributeNames.T__SIGNATURE__; import static com.oracle.graal.python.nodes.SpecialMethodNames.J___OBJCLASS__; import static com.oracle.graal.python.nodes.SpecialMethodNames.J___REDUCE__; import static com.oracle.graal.python.nodes.function.BuiltinFunctionRootNode.T_DOLLAR_DECL_TYPE; @@ -144,8 +146,13 @@ Object doBuiltinFunc(VirtualFrame frame, PBuiltinFunction func, public abstract static class SignatureNode extends PythonUnaryBuiltinNode { @Specialization - public Object doIt(PBuiltinFunction fun) { - return createInspectSignagure(fun.getSignature(), false); + @TruffleBoundary + static Object doIt(PBuiltinFunction fun, + @Bind("this") Node inliningTarget) { + if (fun.getSignature().isHidden()) { + throw PRaiseNode.raiseUncached(inliningTarget, AttributeError, ErrorMessages.HAS_NO_ATTR, fun, T__SIGNATURE__); + } + return createInspectSignature(fun.getSignature(), false); } private enum ParameterKinds { @@ -166,7 +173,7 @@ Object get(Object[] kinds, Object inspectParameter) { } @TruffleBoundary - public static Object createInspectSignagure(Signature signature, boolean skipSelf) { + public static Object createInspectSignature(Signature signature, boolean skipSelf) { PythonModule inspect = ImportNode.importModule(tsLiteral("inspect")); Object inspectSignature = PyObjectGetAttr.executeUncached(inspect, tsLiteral("Signature")); Object inspectParameter = PyObjectGetAttr.executeUncached(inspect, tsLiteral("Parameter")); diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/Signature.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/Signature.java index 2e1be13233..cfa9c1edca 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/Signature.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/Signature.java @@ -25,7 +25,6 @@ */ package com.oracle.graal.python.builtins.objects.function; -import static com.oracle.graal.python.nodes.BuiltinNames.T_SELF; import static com.oracle.graal.python.nodes.StringLiterals.T_EMPTY_STRING; import static com.oracle.graal.python.util.PythonUtils.TS_ENCODING; @@ -45,6 +44,8 @@ public final class Signature { private final boolean isVarArgsMarker; private final boolean takesVarKeywordArgs; private final boolean checkEnclosingType; + // See javadoc for isHidden + private final boolean hidden; @CompilationFinal(dimensions = 1) private final TruffleString[] positionalParameterNames; @CompilationFinal(dimensions = 1) private final TruffleString[] keywordOnlyNames; @@ -68,6 +69,11 @@ public Signature(int positionOnlyArgIndex, boolean takesVarKeywordArgs, int take public Signature(int positionOnlyArgIndex, boolean takesVarKeywordArgs, int takesVarArgs, boolean varArgsMarker, TruffleString[] parameterIds, TruffleString[] keywordNames, boolean checkEnclosingType, TruffleString raiseErrorName) { + this(positionOnlyArgIndex, takesVarKeywordArgs, takesVarArgs, varArgsMarker, parameterIds, keywordNames, checkEnclosingType, raiseErrorName, false); + } + + public Signature(int positionOnlyArgIndex, boolean takesVarKeywordArgs, int takesVarArgs, boolean varArgsMarker, + TruffleString[] parameterIds, TruffleString[] keywordNames, boolean checkEnclosingType, TruffleString raiseErrorName, boolean hidden) { this.positionalOnlyArgIndex = positionOnlyArgIndex; this.takesVarKeywordArgs = takesVarKeywordArgs; this.varArgIndex = takesVarArgs; @@ -76,26 +82,18 @@ public Signature(int positionOnlyArgIndex, boolean takesVarKeywordArgs, int take this.keywordOnlyNames = (keywordNames != null) ? keywordNames : PythonUtils.EMPTY_TRUFFLESTRING_ARRAY; this.checkEnclosingType = checkEnclosingType; this.raiseErrorName = raiseErrorName; + this.hidden = hidden; } public static Signature createVarArgsAndKwArgsOnly() { return new Signature(-1, true, 0, false, null, null); } - public Signature createWithSelf() { - TruffleString[] parameterIdsWithSelf = new TruffleString[getParameterIds().length + 1]; - parameterIdsWithSelf[0] = T_SELF; - PythonUtils.arraycopy(getParameterIds(), 0, parameterIdsWithSelf, 1, parameterIdsWithSelf.length - 1); - - return new Signature(-1, takesVarKeywordArgs, varArgIndex, isVarArgsMarker, - parameterIdsWithSelf, keywordOnlyNames); - } - - public final int getNumOfRequiredKeywords() { + public int getNumOfRequiredKeywords() { return keywordOnlyNames.length; } - public final int getMaxNumOfPositionalArgs() { + public int getMaxNumOfPositionalArgs() { return positionalParameterNames.length; } @@ -104,31 +102,31 @@ public final int getMaxNumOfPositionalArgs() { * @return The index to the positional only argument marker ('/'). Which means that all * positional only argument have index smaller than this. */ - public final int getPositionalOnlyArgIndex() { + public int getPositionalOnlyArgIndex() { return positionalOnlyArgIndex; } - public final int getVarargsIdx() { + public int getVarargsIdx() { return varArgIndex; } - public final boolean takesVarArgs() { + public boolean takesVarArgs() { return varArgIndex != -1; } - public final boolean isVarArgsMarker() { + public boolean isVarArgsMarker() { return isVarArgsMarker; } - public final boolean takesVarKeywordArgs() { + public boolean takesVarKeywordArgs() { return takesVarKeywordArgs; } - public final TruffleString[] getParameterIds() { + public TruffleString[] getParameterIds() { return positionalParameterNames; } - public final TruffleString[] getKeywordNames() { + public TruffleString[] getKeywordNames() { return keywordOnlyNames; } @@ -147,31 +145,32 @@ public TruffleString[] getVisibleKeywordNames() { return visibleKeywordNames.toArray(TruffleString[]::new); } - public final boolean takesKeywordArgs() { + public boolean takesKeywordArgs() { return keywordOnlyNames.length > 0 || takesVarKeywordArgs; } - public final boolean takesRequiredKeywordArgs() { - return this.keywordOnlyNames.length > 0; - } - - public final boolean takesPositionalOnly() { + public boolean takesPositionalOnly() { return !takesVarArgs() && !takesVarKeywordArgs && !isVarArgsMarker && keywordOnlyNames.length == 0; } - public final boolean takesNoArguments() { + public boolean takesNoArguments() { return positionalParameterNames.length == 0 && takesPositionalOnly(); } - public final boolean takesOneArgument() { - return positionalParameterNames.length == 1 && takesPositionalOnly(); - } - - public final boolean checkEnclosingType() { + public boolean checkEnclosingType() { return checkEnclosingType; } - public final TruffleString getRaiseErrorName() { + public TruffleString getRaiseErrorName() { return raiseErrorName; } + + /** + * Hidden signatures won't be shown to python as {@code __signature__} or + * {@code __text_signature__}. This is done to hide generic C function signatures, because it + * breaks assumptions of some packages, namely {@code pythran} + */ + public boolean isHidden() { + return hidden; + } } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/BuiltinFunctionOrMethodBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/BuiltinFunctionOrMethodBuiltins.java index 0170afc5b4..b0c80b9bc1 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/BuiltinFunctionOrMethodBuiltins.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/BuiltinFunctionOrMethodBuiltins.java @@ -40,7 +40,9 @@ */ package com.oracle.graal.python.builtins.objects.method; +import static com.oracle.graal.python.builtins.PythonBuiltinClassType.AttributeError; import static com.oracle.graal.python.nodes.SpecialAttributeNames.J___SIGNATURE__; +import static com.oracle.graal.python.nodes.SpecialAttributeNames.T__SIGNATURE__; import static com.oracle.graal.python.nodes.SpecialAttributeNames.T___NAME__; import static com.oracle.graal.python.nodes.SpecialMethodNames.J___REPR__; @@ -54,9 +56,12 @@ import com.oracle.graal.python.builtins.objects.PythonAbstractObject; import com.oracle.graal.python.builtins.objects.function.BuiltinFunctionBuiltins; import com.oracle.graal.python.builtins.objects.function.PFunction; +import com.oracle.graal.python.builtins.objects.function.Signature; import com.oracle.graal.python.builtins.objects.module.PythonModule; import com.oracle.graal.python.builtins.objects.str.StringUtils.SimpleTruffleStringFormatNode; import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetNameNode; +import com.oracle.graal.python.nodes.ErrorMessages; +import com.oracle.graal.python.nodes.PRaiseNode; import com.oracle.graal.python.nodes.attributes.GetAttributeNode; import com.oracle.graal.python.nodes.builtins.FunctionNodes.GetSignatureNode; import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode; @@ -143,8 +148,13 @@ protected static GetAttributeNode createGetAttributeNode() { abstract static class SignatureNode extends PythonUnaryBuiltinNode { @Specialization @TruffleBoundary - public Object doIt(Object fun) { - return BuiltinFunctionBuiltins.SignatureNode.createInspectSignagure(GetSignatureNode.executeUncached(fun), true); + public Object doIt(Object fun, + @Bind("this") Node inliningTarget) { + Signature signature = GetSignatureNode.executeUncached(fun); + if (signature.isHidden()) { + throw PRaiseNode.raiseUncached(inliningTarget, AttributeError, ErrorMessages.HAS_NO_ATTR, fun, T__SIGNATURE__); + } + return BuiltinFunctionBuiltins.SignatureNode.createInspectSignature(signature, true); } } } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/SpecialAttributeNames.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/SpecialAttributeNames.java index b36a62b532..9b53e57fc4 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/SpecialAttributeNames.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/SpecialAttributeNames.java @@ -120,6 +120,7 @@ public abstract class SpecialAttributeNames { public static final TruffleString T___TEXT_SIGNATURE__ = tsLiteral(J___TEXT_SIGNATURE__); public static final String J___SIGNATURE__ = "__signature__"; + public static final TruffleString T__SIGNATURE__ = tsLiteral(J___SIGNATURE__); public static final String J___TRACEBACK__ = "__traceback__"; public static final TruffleString T___TRACEBACK__ = tsLiteral(J___TRACEBACK__); diff --git a/graalpython/lib-graalpython/patches/meson/meson-1.0.0.patch b/graalpython/lib-graalpython/patches/meson/meson-1.0.0.patch deleted file mode 100644 index b4d263ece8..0000000000 --- a/graalpython/lib-graalpython/patches/meson/meson-1.0.0.patch +++ /dev/null @@ -1,92 +0,0 @@ -diff --git a/mesonbuild/compilers/detect.py b/mesonbuild/compilers/detect.py -index 367bcf9..3c5faa3 100644 ---- a/mesonbuild/compilers/detect.py -+++ b/mesonbuild/compilers/detect.py -@@ -56,7 +56,7 @@ if is_windows(): - defaults['c'] = ['icl', 'cl', 'cc', 'gcc', 'clang', 'clang-cl', 'pgcc'] - # There is currently no pgc++ for Windows, only for Mac and Linux. - defaults['cpp'] = ['icl', 'cl', 'c++', 'g++', 'clang++', 'clang-cl'] -- defaults['fortran'] = ['ifort', 'gfortran', 'flang', 'pgfortran', 'g95'] -+ defaults['fortran'] = ['ifort', 'gfortran', 'flang-new', 'flang', 'pgfortran', 'g95'] - # Clang and clang++ are valid, but currently unsupported. - defaults['objc'] = ['cc', 'gcc'] - defaults['objcpp'] = ['c++', 'g++'] -@@ -72,7 +72,7 @@ else: - defaults['cpp'] = ['c++', 'g++', 'clang++', 'nvc++', 'pgc++', 'icpc', 'icpx'] - defaults['objc'] = ['cc', 'gcc', 'clang'] - defaults['objcpp'] = ['c++', 'g++', 'clang++'] -- defaults['fortran'] = ['gfortran', 'flang', 'nvfortran', 'pgfortran', 'ifort', 'ifx', 'g95'] -+ defaults['fortran'] = ['gfortran', 'flang-new', 'flang', 'nvfortran', 'pgfortran', 'ifort', 'ifx', 'g95'] - defaults['cs'] = ['mcs', 'csc'] - defaults['d'] = ['ldc2', 'ldc', 'gdc', 'dmd'] - defaults['java'] = ['javac'] -@@ -743,6 +743,14 @@ def detect_fortran_compiler(env: 'Environment', for_machine: MachineChoice) -> C - compiler, version, for_machine, is_cross, info, exe_wrap, - full_version=full_version, linker=linker) - -+ if 'flang-new' in out: -+ cls = fortran.FlangNewFortranCompiler -+ linker = guess_nix_linker(env, -+ compiler, cls, version, for_machine) -+ return cls( -+ compiler, version, for_machine, is_cross, info, -+ exe_wrap, full_version=full_version, linker=linker) -+ - if 'flang' in out or 'clang' in out: - cls = fortran.FlangFortranCompiler - linker = guess_nix_linker(env, -diff --git a/mesonbuild/compilers/fortran.py b/mesonbuild/compilers/fortran.py -index 90ca010..1b01913 100644 ---- a/mesonbuild/compilers/fortran.py -+++ b/mesonbuild/compilers/fortran.py -@@ -544,3 +544,50 @@ class NAGFortranCompiler(FortranCompiler): - - def openmp_flags(self) -> T.List[str]: - return ['-openmp'] -+ -+ -+class FlangNewFortranCompiler(ClangCompiler, FortranCompiler): -+ -+ id = 'flang-new' -+ -+ def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool, -+ info: 'MachineInfo', exe_wrapper: T.Optional['ExternalProgram'] = None, -+ linker: T.Optional['DynamicLinker'] = None, -+ full_version: T.Optional[str] = None): -+ FortranCompiler.__init__(self, exelist, version, for_machine, -+ is_cross, info, exe_wrapper, linker=linker, -+ full_version=full_version) -+ ClangCompiler.__init__(self, {}) -+ default_warn_args = ['-Wall'] -+ self.warn_args = {'0': [], -+ '1': default_warn_args, -+ '2': default_warn_args + ['-Wextra'], -+ '3': default_warn_args + ['-Wextra', '-pedantic', '-fimplicit-none'], -+ 'everything': default_warn_args + ['-Wextra', '-pedantic', '-fimplicit-none']} -+ -+ def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]: -+ args = [] -+ key = OptionKey('std', machine=self.for_machine, lang=self.language) -+ std = options[key] -+ if std.value != 'none': -+ args.append('-std=' + std.value) -+ return args -+ -+ def get_module_outdir_args(self, path: str) -> T.List[str]: -+ return ['-module-dir', path] -+ -+ def get_dependency_gen_args(self, outtarget: str, outfile: str) -> T.List[str]: -+ # Disabled until this is fixed: -+ # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62162 -+ # return ['-cpp', '-MD', '-MQ', outtarget] -+ return [] -+ -+ def language_stdlib_only_link_flags(self, env: 'Environment') -> T.List[str]: -+ # We need to apply the search prefix here, as these link arguments may -+ # be passed to a different compiler with a different set of default -+ # search paths, such as when using Clang for C/C++ and gfortran for -+ # fortran, -+ search_dirs: T.List[str] = [] -+ for d in self.get_compiler_dirs(env, 'libraries'): -+ search_dirs.append(f'-L{d}') -+ return search_dirs + ['-lm'] diff --git a/graalpython/lib-graalpython/patches/meson/metadata.toml b/graalpython/lib-graalpython/patches/meson/metadata.toml index 4ab3818206..afdf080d80 100644 --- a/graalpython/lib-graalpython/patches/meson/metadata.toml +++ b/graalpython/lib-graalpython/patches/meson/metadata.toml @@ -1,8 +1,2 @@ [[rules]] -version = '== 1.0.0' -patch = 'meson-1.0.0.patch' -license = 'Apache-2.0' - -[[rules]] -install-priority = 10 version = '== 1.2.2' diff --git a/graalpython/lib-graalpython/patches/scipy/metadata.toml b/graalpython/lib-graalpython/patches/scipy/metadata.toml index fa2ad018a5..6d505789c0 100644 --- a/graalpython/lib-graalpython/patches/scipy/metadata.toml +++ b/graalpython/lib-graalpython/patches/scipy/metadata.toml @@ -1,9 +1,3 @@ -[[rules]] -version = '== 1.9.3' -patch = 'scipy-1.9.3.patch' -license = 'BSD-3-Clause' -dist-type = 'sdist' - [[rules]] version = '== 1.10.1' patch = 'scipy-1.10.1.patch' diff --git a/graalpython/lib-graalpython/patches/scipy/scipy-1.10.1.patch b/graalpython/lib-graalpython/patches/scipy/scipy-1.10.1.patch index 8425eb8795..96c6c36ec6 100644 --- a/graalpython/lib-graalpython/patches/scipy/scipy-1.10.1.patch +++ b/graalpython/lib-graalpython/patches/scipy/scipy-1.10.1.patch @@ -1,139 +1,13 @@ -diff --git a/meson.build b/meson.build -index ad18b245..24108760 100644 ---- a/meson.build -+++ b/meson.build -@@ -11,7 +11,7 @@ project( - 'buildtype=debugoptimized', - 'c_std=c99', - 'cpp_std=c++14', -- 'fortran_std=legacy', -+ 'fortran_std=none', - 'blas=openblas', - 'lapack=openblas' - ], -@@ -66,6 +66,10 @@ if ff.has_argument('-Wno-conversion') - add_project_arguments('-Wno-conversion', language: 'fortran') - endif - -+if ff.has_argument('-fallow-argument-mismatch') -+ add_project_arguments('-fallow-argument-mismatch', language: 'fortran') -+endif -+ - is_windows = host_machine.system() == 'windows' - - # Intel compilers default to fast-math, so disable it if we detect Intel -diff --git a/mesonpy_wrapper.py b/mesonpy_wrapper.py -new file mode 100644 -index 00000000..afa33ecc ---- /dev/null -+++ b/mesonpy_wrapper.py -@@ -0,0 +1,86 @@ -+import mesonpy -+import os -+import sys -+from contextlib import contextmanager -+import subprocess -+ -+ -+def get_flang_new_lib_dir(): -+ if sys.implementation.name == "graalpy" and __graalpython__.use_system_toolchain: -+ return None, None -+ try: -+ output = subprocess.check_output(['flang-new', '--version']) -+ flang_dir = output.splitlines()[-1].split()[-1].strip().decode("utf-8") -+ return os.path.join(flang_dir, "flang-new"), os.path.normpath(os.path.join(flang_dir, '..', 'lib')) -+ except Exception as e: -+ print(f"INFO: flang-new not detected, could not find library path. Reason: {e}") -+ return None, None -+ -+ -+def append_env_var(env, var, value): -+ env[var] = '{} {}'.format(env.get(var, ''), value) -+ -+ -+def get_build_env(): -+ env = {} -+ flang_new, flang_lib_dir = get_flang_new_lib_dir() -+ if flang_new: -+ # until flang-new can compile propack we disable it (during runtime) -+ env["USE_PROPACK"] = "0" -+ env['CC'] = 'clang' -+ env['CXX'] = 'clang++' -+ # env['FC'] = flang_new -+ env['FC'] = "flang-new" -+ if sys.implementation.name == "graalpy": -+ cflags = "-flto=full" -+ else: -+ ld = 'lld' -+ cflags = "-flto=full -fuse-ld=lld -Wl,--mllvm=-lto-embed-bitcode=optimized,--lto-O0" -+ env['CC_LD'] = ld -+ env['CXX_LD'] = ld -+ env['FC_LD'] = ld -+ env['CFLAGS'] = cflags -+ env['CXXFLAGS'] = cflags -+ env['FFLAGS'] = cflags -+ append_env_var(env, 'LDFLAGS', f'-L{flang_lib_dir}') -+ return env -+ -+ -+@contextmanager -+def env_vars(env): -+ # save and set -+ prev = {} -+ for k, v in env.items(): -+ prev[k] = os.environ.get(k, None) -+ os.environ[k] = v -+ -+ yield -+ -+ # restore -+ for k, v in prev.items(): -+ if v is None: -+ del os.environ[k] -+ else: -+ os.environ[k] = v -+ -+ -+def get_config_settings(config_settings=None): -+ if config_settings is None: -+ config_settings = {} -+ config_settings['compile-args'] = '-j4' -+ config_settings['builddir'] = f'mesonbuild-{sys.implementation.name}' -+ return config_settings -+ -+ -+def build_wheel(wheel_directory, config_settings=None, metadata_directory=None): -+ config_settings = get_config_settings(config_settings) -+ scipy_build_env = get_build_env() -+ with env_vars(scipy_build_env): -+ return mesonpy.build_wheel(wheel_directory, config_settings=config_settings, metadata_directory=metadata_directory) -+ -+ -+def build_sdist(sdist_directory, config_settings=None): -+ config_settings = get_config_settings(config_settings) -+ scipy_build_env = get_build_env() -+ with env_vars(scipy_build_env): -+ return mesonpy.build_sdist(sdist_directory, config_settings=config_settings) diff --git a/pyproject.toml b/pyproject.toml -index 454a3c2e..94a754aa 100644 +index 454a3c2e..7c96eb11 100644 --- a/pyproject.toml +++ b/pyproject.toml -@@ -8,55 +8,21 @@ - # "pybind11>=2.4.3,<2.5.0", - - [build-system] --build-backend = 'mesonpy' -+# build-backend = 'mesonpy' -+build-backend = 'mesonpy_wrapper' -+backend-path = ["."] - requires = [ - "meson-python>=0.11.0,<0.13.0", - "Cython>=0.29.32,<3.0", +@@ -15,48 +15,11 @@ requires = [ # conservatively avoid issues from # https://github.com/pybind/pybind11/issues/4420 "pybind11==2.10.1", - "pythran>=0.12.0,<0.13.0", -+ "pythran>=0.13.0", ++ "pythran==0.13.1", # `wheel` is needed for non-isolated builds, given that `meson-python` # doesn't list it as a runtime requirement (at least in 0.5.0) "wheel<0.39.0", @@ -176,159 +50,6 @@ index 454a3c2e..94a754aa 100644 - "numpy; python_version>='3.12'", - "numpy; python_version>='3.8' and platform_python_implementation=='PyPy'", + "numpy==1.23.5", -+ "ninja", ] [project] -diff --git a/scipy/_lib/_ccallback_c.pyx b/scipy/_lib/_ccallback_c.pyx -index 0704acc6..beb2bc72 100644 ---- a/scipy/_lib/_ccallback_c.pyx -+++ b/scipy/_lib/_ccallback_c.pyx -@@ -210,15 +210,15 @@ cdef double sine(double x, void *user_data) nogil except *: - import ctypes - - plus1_t = ctypes.CFUNCTYPE(ctypes.c_double, ctypes.c_double, ctypes.POINTER(ctypes.c_int), ctypes.c_void_p) --plus1_ctypes = ctypes.cast(&plus1_cython, plus1_t) -+# plus1_ctypes = ctypes.cast(&plus1_cython, plus1_t) - - plus1b_t = ctypes.CFUNCTYPE(ctypes.c_double, ctypes.c_double, ctypes.c_double, - ctypes.POINTER(ctypes.c_int), ctypes.c_void_p) --plus1b_ctypes = ctypes.cast(&plus1b_cython, plus1b_t) -+# plus1b_ctypes = ctypes.cast(&plus1b_cython, plus1b_t) - - plus1bc_t = ctypes.CFUNCTYPE(ctypes.c_double, ctypes.c_double, ctypes.c_double, ctypes.c_double, - ctypes.POINTER(ctypes.c_int), ctypes.c_void_p) --plus1bc_ctypes = ctypes.cast(&plus1bc_cython, plus1bc_t) -+# plus1bc_ctypes = ctypes.cast(&plus1bc_cython, plus1bc_t) - - sine_t = ctypes.CFUNCTYPE(ctypes.c_double, ctypes.c_double, ctypes.c_void_p) --sine_ctypes = ctypes.cast(&sine, sine_t) -+# sine_ctypes = ctypes.cast(&sine, sine_t) -diff --git a/scipy/_lib/setup.py b/scipy/_lib/setup.py -index 6fca8a66..95000399 100644 ---- a/scipy/_lib/setup.py -+++ b/scipy/_lib/setup.py -@@ -55,8 +55,6 @@ def configuration(parent_package='',top_path=None): - # Generate a header file containing defines - config_cmd = config.get_config_cmd() - defines = [] -- if config_cmd.check_func('open_memstream', decl=True, call=True): -- defines.append(('HAVE_OPEN_MEMSTREAM', '1')) - target = os.path.join(os.path.dirname(__file__), 'src', - 'messagestream_config.h') - with open(target, 'w') as f: -diff --git a/scipy/_lib/src/messagestream_config.h.in b/scipy/_lib/src/messagestream_config.h.in -index fe2a3876..1cdf6c79 100644 ---- a/scipy/_lib/src/messagestream_config.h.in -+++ b/scipy/_lib/src/messagestream_config.h.in -@@ -1 +1 @@ --#define HAVE_OPEN_MEMSTREAM @has_openmemstream@ -+#define HAVE_OPEN_MEMSTREAM 0 // @has_openmemstream@ -\ No newline at end of file -diff --git a/scipy/sparse/linalg/meson.build b/scipy/sparse/linalg/meson.build -index 946cac0c..96852886 100644 ---- a/scipy/sparse/linalg/meson.build -+++ b/scipy/sparse/linalg/meson.build -@@ -15,7 +15,7 @@ py3.install_sources([ - subdir: 'scipy/sparse/linalg' - ) - --subdir('_propack') -+# subdir('_propack') - subdir('_isolve') - subdir('_dsolve') - subdir('_eigen') -diff --git a/scipy/special/meson.build b/scipy/special/meson.build -index f92183f5..b1443aad 100644 ---- a/scipy/special/meson.build -+++ b/scipy/special/meson.build -@@ -427,24 +427,24 @@ py3.extension_module('_test_internal', - # Must use `custom_target`, because `py3.install_sources` does not work with - # generated sources - see https://github.com/mesonbuild/meson/issues/7372 - npz_files = [ -- [ -- '_data_boost', -- 'tests/data/boost/assoc_legendre_p_ipp/assoc_legendre_p.txt', -- 'boost', -- 'boost.npz' -- ], -- [ -- '_data_gsl', -- 'tests/data/gsl/mathieu_ab.txt', -- 'gsl', -- 'gsl.npz' -- ], -- [ -- '_data_local', -- 'tests/data/local/ellipkm1.txt', -- 'local', -- 'local.npz' -- ], -+ # [ -+ # '_data_boost', -+ # 'tests/data/boost/assoc_legendre_p_ipp/assoc_legendre_p.txt', -+ # 'boost', -+ # 'boost.npz' -+ # ], -+ # [ -+ # '_data_gsl', -+ # 'tests/data/gsl/mathieu_ab.txt', -+ # 'gsl', -+ # 'gsl.npz' -+ # ], -+ # [ -+ # '_data_local', -+ # 'tests/data/local/ellipkm1.txt', -+ # 'local', -+ # 'local.npz' -+ # ], - ] - - foreach npz_file: npz_files -diff --git a/tools/cythonize.py b/tools/cythonize.py -index 402824cb..b6aba959 100755 ---- a/tools/cythonize.py -+++ b/tools/cythonize.py -@@ -95,21 +95,19 @@ def process_pyx(fromfile, tofile, cwd): - if tofile.endswith('.cxx'): - flags += ['--cplus'] - -- try: -+ try: -+ from Cython.Compiler.Main import setuptools_main -+ prev_argv = sys.argv[1:] - try: -- r = subprocess.call(['cython'] + flags + ["-o", tofile, fromfile], cwd=cwd) -- if r != 0: -- raise Exception('Cython failed') -- except OSError as e: -- # There are ways of installing Cython that don't result in a cython -- # executable on the path, see gh-2397. -- r = subprocess.call([sys.executable, '-c', -- 'import sys; from Cython.Compiler.Main import ' -- 'setuptools_main as main; sys.exit(main())'] + flags + -- ["-o", tofile, fromfile], -- cwd=cwd) -- if r != 0: -- raise Exception("Cython either isn't installed or it failed.") from e -+ oldcwd = os.getcwd() -+ os.chdir(cwd) -+ sys.argv[1:] = flags + ["-o", tofile, fromfile] -+ retcode = setuptools_main() -+ if retcode: -+ sys.exit(retcode) -+ finally: -+ sys.argv[1:] = prev_argv -+ os.chdir(oldcwd) - except OSError as e: - raise OSError('Cython needs to be installed') from e - -@@ -253,7 +251,7 @@ def find_process_files(root_dir): - lock = Lock() - - try: -- num_proc = int(os.environ.get('SCIPY_NUM_CYTHONIZE_JOBS', cpu_count())) -+ num_proc = int(os.environ.get('SCIPY_NUM_CYTHONIZE_JOBS', 1)) - pool = Pool(processes=num_proc) - except ImportError as e: - # Allow building (single-threaded) on GNU/Hurd, which does not diff --git a/graalpython/lib-graalpython/patches/scipy/scipy-1.9.3.patch b/graalpython/lib-graalpython/patches/scipy/scipy-1.9.3.patch deleted file mode 100644 index 9419fb38ec..0000000000 --- a/graalpython/lib-graalpython/patches/scipy/scipy-1.9.3.patch +++ /dev/null @@ -1,318 +0,0 @@ -diff --git a/meson.build b/meson.build -index 5b4a1d52..c29ec297 100644 ---- a/meson.build -+++ b/meson.build -@@ -11,7 +11,7 @@ project( - 'buildtype=debugoptimized', - 'c_std=c99', - 'cpp_std=c++14', -- 'fortran_std=legacy', -+ 'fortran_std=none', - 'blas=openblas', - 'lapack=openblas' - ], -diff --git a/mesonpy_wrapper.py b/mesonpy_wrapper.py -new file mode 100644 -index 00000000..21cceae0 ---- /dev/null -+++ b/mesonpy_wrapper.py -@@ -0,0 +1,82 @@ -+import mesonpy -+import os -+import sys -+from contextlib import contextmanager -+import subprocess -+ -+ -+def get_flang_new_lib_dir(): -+ if sys.implementation.name == "graalpy" and __graalpython__.use_system_toolchain: -+ return None, None -+ try: -+ output = subprocess.check_output(['flang-new', '--version']) -+ flang_dir = output.splitlines()[-1].split()[-1].strip().decode("utf-8") -+ return os.path.join(flang_dir, "flang-new"), os.path.normpath(os.path.join(flang_dir, '..', 'lib')) -+ except Exception as e: -+ print(f"INFO: flang-new not detected, could not find library path. Reason: {e}") -+ return None, None -+ -+ -+def append_env_var(env, var, value): -+ env[var] = '{} {}'.format(env.get(var, ''), value) -+ -+ -+def get_build_env(): -+ env = {} -+ flang_new, flang_lib_dir = get_flang_new_lib_dir() -+ if flang_new: -+ # until flang-new can compile propack we disable it (during runtime) -+ env["USE_PROPACK"] = "0" -+ env['CC'] = 'clang' -+ env['CXX'] = 'clang++' -+ # env['FC'] = flang_new -+ env['FC'] = "flang-new" -+ if sys.implementation.name == "graalpy": -+ cflags = "-flto=full" -+ else: -+ ld = 'lld' -+ cflags = "-flto=full -fuse-ld=lld -Wl,--mllvm=-lto-embed-bitcode=optimized,--lto-O0" -+ env['CC_LD'] = ld -+ env['CXX_LD'] = ld -+ env['FC_LD'] = ld -+ env['CFLAGS'] = cflags -+ env['CXXFLAGS'] = cflags -+ env['FFLAGS'] = cflags -+ append_env_var(env, 'LDFLAGS', f'-L{flang_lib_dir}') -+ return env -+ -+ -+@contextmanager -+def env_vars(env): -+ # save and set -+ prev = {} -+ for k, v in env.items(): -+ prev[k] = os.environ.get(k, None) -+ os.environ[k] = v -+ -+ yield -+ -+ # restore -+ for k, v in prev.items(): -+ if v is None: -+ del os.environ[k] -+ else: -+ os.environ[k] = v -+ -+ -+def build_wheel(wheel_directory, config_settings=None, metadata_directory=None): -+ if config_settings is None: -+ config_settings = {} -+ config_settings['compile-args'] = '-j4' -+ scipy_build_env = get_build_env() -+ with env_vars(scipy_build_env): -+ return mesonpy.build_wheel(wheel_directory, config_settings=config_settings, metadata_directory=metadata_directory) -+ -+ -+def build_sdist(sdist_directory, config_settings=None): -+ if config_settings is None: -+ config_settings = {} -+ config_settings['compile-args'] = '-j4' -+ scipy_build_env = get_build_env() -+ with env_vars(scipy_build_env): -+ return mesonpy.build_sdist(sdist_directory, config_settings=config_settings) -diff --git a/pyproject.toml b/pyproject.toml -index 6dc1d407..da3e4e6d 100644 ---- a/pyproject.toml -+++ b/pyproject.toml -@@ -8,54 +8,19 @@ - # "pybind11>=2.4.3,<2.5.0", - - [build-system] --build-backend = 'mesonpy' -+# build-backend = 'mesonpy' -+build-backend = 'mesonpy_wrapper' -+backend-path = ["."] - requires = [ - "meson-python>=0.9.0", # we need more fixes in meson-python, so no upper bound now - "Cython>=0.29.32,<3.0", - "pybind11>=2.4.3,<2.11.0", -- "pythran>=0.9.12,<0.13.0", -+ "pythran>=0.13.0", - # `wheel` is needed for non-isolated builds, given that `meson-python` - # doesn't list it as a runtime requirement (at least in 0.5.0) - "wheel<0.38.0", -- -- # NumPy dependencies - to update these, sync from -- # https://github.com/scipy/oldest-supported-numpy/, and then -- # update minimum version to match our install_requires min version -- # ---------------------------------------------------------------- -- -- # numpy 1.19 was the first minor release to provide aarch64 wheels, but -- # wheels require fixes contained in numpy 1.19.2 -- "numpy==1.19.2; python_version=='3.8' and platform_machine=='aarch64' and platform_python_implementation != 'PyPy'", -- # aarch64 for py39 is covered by default requirement below -- -- # arm64 on Darwin supports Python 3.8 and above requires numpy>=1.21.0 -- # (first version with arm64 wheels available) -- "numpy==1.21.0; python_version=='3.8' and platform_machine=='arm64' and platform_system=='Darwin'", -- "numpy==1.21.0; python_version=='3.9' and platform_machine=='arm64' and platform_system=='Darwin'", -- -- # loongarch64 requires numpy>=1.22.0 -- "numpy==1.22.0; platform_machine=='loongarch64'", -- -- # On Windows we need to avoid 1.21.6, 1.22.0 and 1.22.1 because they were -- # built with vc142. 1.22.3 is the first version that has 32-bit Windows -- # wheels *and* was built with vc141. So use that: -- "numpy==1.22.3; python_version=='3.10' and platform_system=='Windows' and platform_python_implementation != 'PyPy'", -- -- # default numpy requirements -- "numpy==1.18.5; python_version=='3.8' and (platform_machine!='arm64' or platform_system!='Darwin') and platform_machine!='aarch64' and platform_machine!='loongarch64' and platform_python_implementation != 'PyPy'", -- "numpy==1.19.3; python_version=='3.9' and (platform_machine!='arm64' or platform_system!='Darwin') and platform_machine!='loongarch64' and platform_python_implementation != 'PyPy'", -- # Note that 1.21.3 was the first version with a complete set of 3.10 wheels, -- # however macOS was broken and it's safe C API/ABI-wise to build against 1.21.6 -- # (see oldest-supported-numpy issues gh-28 and gh-45) -- "numpy==1.21.6; python_version=='3.10' and (platform_system!='Windows' and platform_machine!='loongarch64') and platform_python_implementation != 'PyPy'", -- "numpy==1.23.2; python_version=='3.11' and platform_python_implementation != 'PyPy'", -- -- # For Python versions which aren't yet officially supported, -- # we specify an unpinned NumPy which allows source distributions -- # to be used and allows wheels to be used as soon as they -- # become available. -- "numpy; python_version>='3.12'", -- "numpy; python_version>='3.8' and platform_python_implementation=='PyPy'", -+ "numpy", -+ "ninja", - ] - - [project] -diff --git a/scipy/_lib/_ccallback_c.pyx b/scipy/_lib/_ccallback_c.pyx -index 871fb5d3..864656f4 100644 ---- a/scipy/_lib/_ccallback_c.pyx -+++ b/scipy/_lib/_ccallback_c.pyx -@@ -210,15 +210,15 @@ cdef double sine(double x, void *user_data) nogil except *: - import ctypes - - plus1_t = ctypes.CFUNCTYPE(ctypes.c_double, ctypes.c_double, ctypes.POINTER(ctypes.c_int), ctypes.c_void_p) --plus1_ctypes = ctypes.cast(&plus1_cython, plus1_t) -+# plus1_ctypes = ctypes.cast(&plus1_cython, plus1_t) - - plus1b_t = ctypes.CFUNCTYPE(ctypes.c_double, ctypes.c_double, ctypes.c_double, - ctypes.POINTER(ctypes.c_int), ctypes.c_void_p) --plus1b_ctypes = ctypes.cast(&plus1b_cython, plus1b_t) -+# plus1b_ctypes = ctypes.cast(&plus1b_cython, plus1b_t) - - plus1bc_t = ctypes.CFUNCTYPE(ctypes.c_double, ctypes.c_double, ctypes.c_double, ctypes.c_double, - ctypes.POINTER(ctypes.c_int), ctypes.c_void_p) --plus1bc_ctypes = ctypes.cast(&plus1bc_cython, plus1bc_t) -+# plus1bc_ctypes = ctypes.cast(&plus1bc_cython, plus1bc_t) - - sine_t = ctypes.CFUNCTYPE(ctypes.c_double, ctypes.c_double, ctypes.c_void_p) --sine_ctypes = ctypes.cast(&sine, sine_t) -+# sine_ctypes = ctypes.cast(&sine, sine_t) -diff --git a/scipy/_lib/setup.py b/scipy/_lib/setup.py -index 6fca8a66..95000399 100644 ---- a/scipy/_lib/setup.py -+++ b/scipy/_lib/setup.py -@@ -55,8 +55,6 @@ def configuration(parent_package='',top_path=None): - # Generate a header file containing defines - config_cmd = config.get_config_cmd() - defines = [] -- if config_cmd.check_func('open_memstream', decl=True, call=True): -- defines.append(('HAVE_OPEN_MEMSTREAM', '1')) - target = os.path.join(os.path.dirname(__file__), 'src', - 'messagestream_config.h') - with open(target, 'w') as f: -diff --git a/scipy/_lib/src/messagestream_config.h.in b/scipy/_lib/src/messagestream_config.h.in -index fe2a3876..1cdf6c79 100644 ---- a/scipy/_lib/src/messagestream_config.h.in -+++ b/scipy/_lib/src/messagestream_config.h.in -@@ -1 +1 @@ --#define HAVE_OPEN_MEMSTREAM @has_openmemstream@ -+#define HAVE_OPEN_MEMSTREAM 0 // @has_openmemstream@ -\ No newline at end of file -diff --git a/scipy/sparse/linalg/meson.build b/scipy/sparse/linalg/meson.build -index db2f199d..763e1ef6 100644 ---- a/scipy/sparse/linalg/meson.build -+++ b/scipy/sparse/linalg/meson.build -@@ -16,7 +16,7 @@ py3.install_sources([ - subdir: 'scipy/sparse/linalg' - ) - --subdir('_propack') -+# subdir('_propack') - subdir('_isolve') - subdir('_dsolve') - subdir('_eigen') -diff --git a/scipy/special/meson.build b/scipy/special/meson.build -index 8fe534be..133be12b 100644 ---- a/scipy/special/meson.build -+++ b/scipy/special/meson.build -@@ -459,24 +459,24 @@ py3.extension_module('_test_round', - # Must use `custom_target`, because `py3.install_sources` does not work with - # generated sources - see https://github.com/mesonbuild/meson/issues/7372 - npz_files = [ -- [ -- '_data_boost', -- 'tests/data/boost/acosh_data_ipp/acosh_data.txt', -- 'boost', -- 'boost.npz' -- ], -- [ -- '_data_gsl', -- 'tests/data/gsl/mathieu_ab.txt', -- 'gsl', -- 'gsl.npz' -- ], -- [ -- '_data_local', -- 'tests/data/local/ellipkm1.txt', -- 'local', -- 'local.npz' -- ], -+ # [ -+ # '_data_boost', -+ # 'tests/data/boost/acosh_data_ipp/acosh_data.txt', -+ # 'boost', -+ # 'boost.npz' -+ # ], -+ # [ -+ # '_data_gsl', -+ # 'tests/data/gsl/mathieu_ab.txt', -+ # 'gsl', -+ # 'gsl.npz' -+ # ], -+ # [ -+ # '_data_local', -+ # 'tests/data/local/ellipkm1.txt', -+ # 'local', -+ # 'local.npz' -+ # ], - ] - - foreach npz_file: npz_files -diff --git a/tools/cythonize.py b/tools/cythonize.py -index 402824cb..b6aba959 100755 ---- a/tools/cythonize.py -+++ b/tools/cythonize.py -@@ -95,21 +95,19 @@ def process_pyx(fromfile, tofile, cwd): - if tofile.endswith('.cxx'): - flags += ['--cplus'] - -- try: -+ try: -+ from Cython.Compiler.Main import setuptools_main -+ prev_argv = sys.argv[1:] - try: -- r = subprocess.call(['cython'] + flags + ["-o", tofile, fromfile], cwd=cwd) -- if r != 0: -- raise Exception('Cython failed') -- except OSError as e: -- # There are ways of installing Cython that don't result in a cython -- # executable on the path, see gh-2397. -- r = subprocess.call([sys.executable, '-c', -- 'import sys; from Cython.Compiler.Main import ' -- 'setuptools_main as main; sys.exit(main())'] + flags + -- ["-o", tofile, fromfile], -- cwd=cwd) -- if r != 0: -- raise Exception("Cython either isn't installed or it failed.") from e -+ oldcwd = os.getcwd() -+ os.chdir(cwd) -+ sys.argv[1:] = flags + ["-o", tofile, fromfile] -+ retcode = setuptools_main() -+ if retcode: -+ sys.exit(retcode) -+ finally: -+ sys.argv[1:] = prev_argv -+ os.chdir(oldcwd) - except OSError as e: - raise OSError('Cython needs to be installed') from e - -@@ -253,7 +251,7 @@ def find_process_files(root_dir): - lock = Lock() - - try: -- num_proc = int(os.environ.get('SCIPY_NUM_CYTHONIZE_JOBS', cpu_count())) -+ num_proc = int(os.environ.get('SCIPY_NUM_CYTHONIZE_JOBS', 1)) - pool = Pool(processes=num_proc) - except ImportError as e: - # Allow building (single-threaded) on GNU/Hurd, which does not