Skip to content

Commit

Permalink
[GR-57623] Fix scipy build
Browse files Browse the repository at this point in the history
PullRequest: graalpython/3459
  • Loading branch information
msimacek committed Aug 28, 2024
2 parents c100ea5 + af716bb commit a0111e8
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 766 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand All @@ -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"));
Expand Down
Loading

0 comments on commit a0111e8

Please sign in to comment.