Skip to content

Commit

Permalink
Extract cached properties
Browse files Browse the repository at this point in the history
Reviewed By: carljm

Differential Revision: D51032460

fbshipit-source-id: 522424b3d515f3c1b6f1f16a53bd882e91011640
  • Loading branch information
Johnston Jiaa authored and facebook-github-bot committed Nov 10, 2023
1 parent 0cd6234 commit d5f7bef
Show file tree
Hide file tree
Showing 17 changed files with 1,147 additions and 1,064 deletions.
988 changes: 988 additions & 0 deletions CachedProperties/cached_properties.c

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions CachedProperties/cached_properties.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#ifndef Py_CACHED_PROPERTIES_H
#define Py_CACHED_PROPERTIES_H

#include "Python.h"

/* fb t46346203 */
typedef struct {
PyObject_HEAD
PyObject *func; /* function object */
PyObject *name_or_descr; /* str or member descriptor object */
} PyCachedPropertyDescrObject;
/* end fb t46346203 */

/* fb T82701047 */
typedef struct {
PyObject_HEAD
PyObject *func; /* function object */
PyObject *name_or_descr; /* str or member descriptor object */
} PyAsyncCachedPropertyDescrObject;
/* end fb T82701047 */

/* fb T82701047 */
typedef struct {
PyObject_HEAD
PyObject *func; /* function object */
PyObject *name; /* str or member descriptor object */
PyObject *value; /* value or NULL when uninitialized */
} PyAsyncCachedClassPropertyDescrObject;
/* end fb T82701047 */

CiAPI_DATA(PyTypeObject) PyAsyncCachedPropertyWithDescr_Type;
CiAPI_DATA(PyType_Spec) _PyCachedClassProperty_TypeSpec; /* fb t46346203 */
CiAPI_DATA(PyTypeObject) PyCachedProperty_Type; /* fb T46346203 */
CiAPI_DATA(PyTypeObject) PyCachedPropertyWithDescr_Type; /* fb T46346203 */
CiAPI_DATA(PyTypeObject) PyAsyncCachedProperty_Type; /* fb T82701047 */
CiAPI_DATA(PyTypeObject) PyAsyncCachedClassProperty_Type; /* fb T82701047 */
#endif /* !Py_CACHED_PROPERTIES_H */
1 change: 1 addition & 0 deletions CinderX/CachedProperties
90 changes: 90 additions & 0 deletions CinderX/clinic/cached_properties.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions CinderX/known-core-python-exported-symbols
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,6 @@ _PyAST_With
_PyAST_withitem
_PyAST_Yield
_PyAST_YieldFrom
PyAsyncCachedClassProperty_Type
PyAsyncCachedProperty_Type
PyAsyncCachedPropertyWithDescr_Type
_PyAsyncGenASend_Type
_PyAsyncGenAThrow_Type
PyAsyncGen_New
Expand Down Expand Up @@ -350,9 +347,6 @@ _PyBytesWriter_Prepare
_PyBytesWriter_Resize
_PyBytesWriter_WriteBytes
_Py_c_abs
_PyCachedClassProperty_TypeSpec
PyCachedProperty_Type
PyCachedPropertyWithDescr_Type
PyCallable_Check
PyCallIter_New
PyCallIter_Type
Expand Down
7 changes: 6 additions & 1 deletion CinderX/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@
"StaticPython/methodobject_vectorcall.c",
]

CACHEDPROPS_SRCS = [
"CachedProperties/cached_properties.c",
]

ALL_SRCS = (
CINDER_SRCS +
CINDERX_SRCS +
Expand All @@ -243,7 +247,8 @@
ASMJIT_SRCS +
SHADOWCODE_SRCS +
STRICTM_SRCS +
STATICPYTHON_SRCS
STATICPYTHON_SRCS +
CACHEDPROPS_SRCS
)

# Monkey-patch the ability to compile C++ files (but not C files) with
Expand Down
31 changes: 0 additions & 31 deletions Include/descrobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,46 +73,15 @@ typedef struct {
} PyWrapperDescrObject;
#endif /* Py_LIMITED_API */

/* fb t46346203 */
typedef struct {
PyObject_HEAD
PyObject *func; /* function object */
PyObject *name_or_descr; /* str or member descriptor object */
} PyCachedPropertyDescrObject;
/* end fb t46346203 */

/* fb T82701047 */
typedef struct {
PyObject_HEAD
PyObject *func; /* function object */
PyObject *name_or_descr; /* str or member descriptor object */
} PyAsyncCachedPropertyDescrObject;
/* end fb T82701047 */

/* fb T82701047 */
typedef struct {
PyObject_HEAD
PyObject *func; /* function object */
PyObject *name; /* str or member descriptor object */
PyObject *value; /* value or NULL when uninitialized */
} PyAsyncCachedClassPropertyDescrObject;
/* end fb T82701047 */

PyAPI_DATA(PyTypeObject) PyClassMethodDescr_Type;
PyAPI_DATA(PyTypeObject) PyGetSetDescr_Type;
PyAPI_DATA(PyTypeObject) PyMemberDescr_Type;
CiAPI_DATA(PyTypeObject) PyAsyncCachedPropertyWithDescr_Type;
PyAPI_DATA(PyTypeObject) PyMethodDescr_Type;
PyAPI_DATA(PyTypeObject) PyWrapperDescr_Type;
PyAPI_DATA(PyTypeObject) PyDictProxy_Type;
#ifndef Py_LIMITED_API
PyAPI_DATA(PyTypeObject) _PyMethodWrapper_Type;
#endif /* Py_LIMITED_API */
CiAPI_DATA(PyType_Spec) _PyCachedClassProperty_TypeSpec; /* fb t46346203 */
CiAPI_DATA(PyTypeObject) PyCachedProperty_Type; /* fb T46346203 */
CiAPI_DATA(PyTypeObject) PyCachedPropertyWithDescr_Type; /* fb T46346203 */
CiAPI_DATA(PyTypeObject) PyAsyncCachedProperty_Type; /* fb T82701047 */
CiAPI_DATA(PyTypeObject) PyAsyncCachedClassProperty_Type; /* fb T82701047 */

PyAPI_FUNC(PyObject *) PyDescr_NewMethod(PyTypeObject *, PyMethodDef *);
PyAPI_FUNC(PyObject *) PyDescr_NewClassMethod(PyTypeObject *, PyMethodDef *);
Expand Down
12 changes: 12 additions & 0 deletions Makefile.pre.in
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,11 @@ STRICTM_OBJS= \
PARALLELGC_OBJS = \
CinderX/ParallelGC/parallel_gc.o

##########################################################################
# Cached Properties
CACHEDPROPS_OBJS = \
CachedProperties/cached_properties.o

##########################################################################
# Objects
OBJECT_OBJS= \
Expand Down Expand Up @@ -711,6 +716,7 @@ BUILD_CINDERX_SRCS=@BUILD_CINDERX_SRCS@
ifeq ($(BUILD_CINDERX_SRCS), yes)
CINDERX_OBJS = \
$(ASMJIT_OBJS) \
$(CACHEDPROPS_OBJS) \
$(CINDER_OBJS) \
$(JIT_OBJS) \
$(PARALLELGC_OBJS) \
Expand Down Expand Up @@ -1505,6 +1511,9 @@ STRICTM_HEADERS = \
$(STRICTM_PRIVATE_HEADERS) \
$(STRICTM_PUBLIC_HEADERS)

CACHEDPROPS_HEADERS = \
$(srcdir)/CachedProperties/cached_properties.h

CINDER_HEADERS= \
$(srcdir)/Cinder/Include/cinder/cinder.h \
$(srcdir)/Cinder/Include/cinder/exports.h \
Expand Down Expand Up @@ -1686,13 +1695,16 @@ PYTHON_HEADERS= \
$(SHADOWCODE_HEADERS) \
$(STATICPYTHON_HEADERS) \
$(STRICTM_HEADERS) \
$(CACHEDPROPS_HEADERS) \

$(LIBRARY_OBJS) $(MODOBJS) Programs/python.o: $(PYTHON_HEADERS) $(I386_DASM_HEADERS) $(JSON_HEADERS) $(CINDER_HEADERS)

$(CINDER_OBJS): $(JIT_PUBLIC_HEADERS) $(CINDER_HEADERS)

$(PARALLELGC_OBJS): $(CINDER_HEADERS) $(srcdir)/CinderX/ParallelGC/condvar.h $(srcdir)/CinderX/ParallelGC/ws_deque.h

$(CACHEDPROPS_OBJS): $(CACHEDPROPS_HEADERS) $(PYTHON_HEADERS)

$(JIT_OBJS): $(JIT_HEADERS) $(CINDER_HEADERS)

$(SHADOWCODE_OBJS): $(SHADOWCODE_HEADERS) $(PYTHON_HEADERS)
Expand Down
2 changes: 2 additions & 0 deletions Modules/_static.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include "structmember.h"
#include "pycore_object.h"

#include "CachedProperties/cached_properties.h"

#include "StaticPython/classloader.h"

PyDoc_STRVAR(_static__doc__,
Expand Down
2 changes: 2 additions & 0 deletions Modules/cinder.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "internal/pycore_shadow_frame.h"
#include "frameobject.h"

#include "CachedProperties/cached_properties.h"

#include "Jit/pyjit.h"

PyAPI_FUNC(void) _PyShadow_ClearCache(PyObject *co);
Expand Down
96 changes: 1 addition & 95 deletions Objects/clinic/descrobject.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d5f7bef

Please sign in to comment.