Skip to content

Commit c379ffd

Browse files
committed
Introduce type 'wrapper_descriptor'
1 parent da729ad commit c379ffd

File tree

8 files changed

+33
-4
lines changed

8 files changed

+33
-4
lines changed

graalpython/com.oracle.graal.python.cext/src/capi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ declare_type(PyFloat_Type, float, PyFloatObject);
179179
declare_type(PySlice_Type, slice, PySliceObject);
180180
declare_type(PyByteArray_Type, bytearray, PyByteArrayObject);
181181
declare_type(PyCFunction_Type, builtin_function_or_method, PyCFunctionObject);
182-
declare_type(PyWrapperDescr_Type, method_descriptor, PyWrapperDescrObject); // LS: previously wrapper_descriptor
182+
declare_type(PyWrapperDescr_Type, wrapper_descriptor, PyWrapperDescrObject);
183183
// tfel: Both method_descriptor maps to both PyWrapperDescr_Type and
184184
// PyMethodDescr_Type. This reflects our interpreter, but we need to make sure
185185
// that the dynamic type for method_descriptor is always going to be

graalpython/com.oracle.graal.python.cext/src/descrobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ typedef struct {
4848

4949
PyTypeObject PyGetSetDescr_Type = PY_TRUFFLE_TYPE("getset_descriptor", &PyType_Type, Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, sizeof(PyGetSetDescrObject));
5050
/* NOTE: we use the same Python type (namely 'PBuiltinFunction') for 'wrapper_descriptor' as for 'method_descriptor'; so the flags must be the same! */
51-
PyTypeObject PyWrapperDescr_Type = PY_TRUFFLE_TYPE("wrapper_descriptor", &PyType_Type, Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_METHOD_DESCRIPTOR| _Py_TPFLAGS_HAVE_VECTORCALL, sizeof(PyWrapperDescrObject));
51+
PyTypeObject PyWrapperDescr_Type = PY_TRUFFLE_TYPE("wrapper_descriptor", &PyType_Type, Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_METHOD_DESCRIPTOR, sizeof(PyWrapperDescrObject));
5252
PyTypeObject PyMemberDescr_Type = PY_TRUFFLE_TYPE("member_descriptor", &PyType_Type, Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, sizeof(PyMemberDescrObject));
5353
PyTypeObject PyMethodDescr_Type = PY_TRUFFLE_TYPE_WITH_VECTORCALL("method_descriptor", &PyType_Type, Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_METHOD_DESCRIPTOR| _Py_TPFLAGS_HAVE_VECTORCALL, sizeof(PyMethodDescrObject), offsetof(PyMethodDescrObject, vectorcall));
5454
PyTypeObject PyDictProxy_Type = PY_TRUFFLE_TYPE("mappingproxy", &PyType_Type, Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, sizeof(mappingproxyobject));

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import static com.oracle.graal.python.nodes.BuiltinNames.MEMBER_DESCRIPTOR;
4343
import static com.oracle.graal.python.nodes.BuiltinNames.PROPERTY;
4444
import static com.oracle.graal.python.nodes.BuiltinNames.SIMPLE_QUEUE;
45+
import static com.oracle.graal.python.nodes.BuiltinNames.WRAPPER_DESCRIPTOR;
4546

4647
import java.util.Arrays;
4748
import java.util.HashSet;
@@ -84,6 +85,7 @@ public enum PythonBuiltinClassType implements TruffleObject {
8485
Boolean("bool", BUILTINS, Flags.PUBLIC_DERIVED_WODICT),
8586
GetSetDescriptor("get_set_desc", Flags.PRIVATE_DERIVED_WODICT),
8687
MemberDescriptor(MEMBER_DESCRIPTOR, Flags.PRIVATE_DERIVED_WODICT),
88+
WrapperDescriptor(WRAPPER_DESCRIPTOR, Flags.PRIVATE_DERIVED_WODICT),
8789
PArray("array", "array"),
8890
PArrayIterator("arrayiterator", Flags.PRIVATE_DERIVED_WODICT),
8991
PIterator("iterator", Flags.PRIVATE_DERIVED_WODICT),

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
import static com.oracle.graal.python.nodes.BuiltinNames.SUPER;
6464
import static com.oracle.graal.python.nodes.BuiltinNames.TUPLE;
6565
import static com.oracle.graal.python.nodes.BuiltinNames.TYPE;
66+
import static com.oracle.graal.python.nodes.BuiltinNames.WRAPPER_DESCRIPTOR;
6667
import static com.oracle.graal.python.nodes.BuiltinNames.ZIP;
6768
import static com.oracle.graal.python.nodes.ErrorMessages.ARG_MUST_NOT_BE_ZERO;
6869
import static com.oracle.graal.python.nodes.ErrorMessages.ERROR_CALLING_SET_NAME;
@@ -3251,7 +3252,7 @@ Object call(@SuppressWarnings("unused") Object clazz, Object get, Object set, St
32513252
}
32523253

32533254
@Builtin(name = MEMBER_DESCRIPTOR, constructsClass = PythonBuiltinClassType.MemberDescriptor, isPublic = false, minNumOfPositionalArgs = 1, //
3254-
parameterNames = {"cls", "fget", "fset", "name", "owner"})
3255+
parameterNames = {"cls", "fget", "fset", "name", "owner"})
32553256
@GenerateNodeFactory
32563257
public abstract static class MemberDescriptorNode extends DescriptorNode {
32573258
@Specialization(guards = "isPythonClass(owner)")
@@ -3262,6 +3263,18 @@ Object doGeneric(@SuppressWarnings("unused") Object clazz, Object get, Object se
32623263
}
32633264
}
32643265

3266+
@Builtin(name = WRAPPER_DESCRIPTOR, constructsClass = PythonBuiltinClassType.WrapperDescriptor, isPublic = false, minNumOfPositionalArgs = 1, //
3267+
parameterNames = {"cls", "fget", "fset", "name", "owner"})
3268+
@GenerateNodeFactory
3269+
public abstract static class WrapperDescriptorNode extends DescriptorNode {
3270+
@Specialization(guards = "isPythonClass(owner)")
3271+
@TruffleBoundary
3272+
Object doGeneric(@SuppressWarnings("unused") Object clazz, Object get, Object set, String name, Object owner) {
3273+
denyInstantiationAfterInitialization(WRAPPER_DESCRIPTOR);
3274+
return PythonObjectFactory.getUncached().createGetSetDescriptor(ensure(get), ensure(set), name, owner);
3275+
}
3276+
}
3277+
32653278
// slice(stop)
32663279
// slice(start, stop[, step])
32673280
@Builtin(name = "slice", minNumOfPositionalArgs = 2, maxNumOfPositionalArgs = 4, constructsClass = PythonBuiltinClassType.PSlice)

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
import com.oracle.truffle.api.library.ExportMessage;
6767
import com.oracle.truffle.api.nodes.Node;
6868
import com.oracle.truffle.api.nodes.RootNode;
69+
import com.oracle.truffle.api.object.Shape;
6970
import com.oracle.truffle.api.profiles.ConditionProfile;
7071

7172
@ExportLibrary(PythonObjectLibrary.class)
@@ -86,7 +87,11 @@ public PBuiltinFunction(PythonLanguage lang, String name, Object enclosingType,
8687
}
8788

8889
public PBuiltinFunction(PythonLanguage lang, String name, Object enclosingType, Object[] defaults, PKeyword[] kwDefaults, int flags, RootCallTarget callTarget) {
89-
super(PythonBuiltinClassType.PBuiltinFunction, PythonBuiltinClassType.PBuiltinFunction.getInstanceShape(lang));
90+
this(PythonBuiltinClassType.PBuiltinFunction, PythonBuiltinClassType.PBuiltinFunction.getInstanceShape(lang), name, enclosingType, defaults, kwDefaults, flags, callTarget);
91+
}
92+
93+
public PBuiltinFunction(PythonBuiltinClassType cls, Shape shape, String name, Object enclosingType, Object[] defaults, PKeyword[] kwDefaults, int flags, RootCallTarget callTarget) {
94+
super(cls, shape);
9095
this.name = name;
9196
if (enclosingType != null) {
9297
this.qualname = PString.cat(GetNameNode.doSlowPath(enclosingType), ".", name);

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,9 @@ static long doBuiltinClassType(PythonBuiltinClassType clazz) {
218218
case PBuiltinFunction:
219219
result = DEFAULT | HAVE_GC | METHOD_DESCRIPTOR | HAVE_VECTORCALL;
220220
break;
221+
case WrapperDescriptor:
222+
result = DEFAULT | HAVE_GC | METHOD_DESCRIPTOR;
223+
break;
221224
case PMethod:
222225
case PBuiltinMethod:
223226
result = DEFAULT | HAVE_GC | HAVE_VECTORCALL;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ public abstract class BuiltinNames {
143143
public static final String _CODECS = "_codecs";
144144
public static final String GETSET_DESCRIPTOR = "getset_descriptor";
145145
public static final String MEMBER_DESCRIPTOR = "member_descriptor";
146+
public static final String WRAPPER_DESCRIPTOR = "wrapper_descriptor";
146147
public static final String SIMPLE_QUEUE = "SimpleQueue";
147148
public static final String EMPTY = "Empty";
148149

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/object/PythonObjectFactory.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,11 @@ public final PBuiltinFunction createBuiltinFunction(String name, Object type, Ob
555555
return trace(new PBuiltinFunction(getLanguage(), name, type, defaults, kw, flags, callTarget));
556556
}
557557

558+
public final PBuiltinFunction createWrapperDescriptor(String name, Object type, Object[] defaults, PKeyword[] kw, int flags, RootCallTarget callTarget) {
559+
return trace(new PBuiltinFunction(PythonBuiltinClassType.WrapperDescriptor, PythonBuiltinClassType.WrapperDescriptor.getInstanceShape(getLanguage()), name, type, defaults, kw, flags,
560+
callTarget));
561+
}
562+
558563
public final GetSetDescriptor createGetSetDescriptor(Object get, Object set, String name, Object type) {
559564
return trace(new GetSetDescriptor(getLanguage(), get, set, name, type));
560565
}

0 commit comments

Comments
 (0)