GH-120507: Lower the `BEFORE_WITH` and `BEFORE_ASYNC_WITH` instructio… · python/cpython@9cefcc0 · GitHub
Skip to content

Commit 9cefcc0

Browse files
authored
GH-120507: Lower the BEFORE_WITH and BEFORE_ASYNC_WITH instructions. (#120640)
* Remove BEFORE_WITH and BEFORE_ASYNC_WITH instructions. * Add LOAD_SPECIAL instruction * Reimplement `with` and `async with` statements using LOAD_SPECIAL
1 parent 73dc1c6 commit 9cefcc0

22 files changed

Lines changed: 663 additions & 651 deletions

Doc/library/dis.rst

Lines changed: 11 additions & 22 deletions

Include/ceval.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,13 @@ PyAPI_FUNC(void) PyEval_ReleaseThread(PyThreadState *tstate);
133133
#define FVS_MASK 0x4
134134
#define FVS_HAVE_SPEC 0x4
135135

136+
/* Special methods used by LOAD_SPECIAL */
137+
#define SPECIAL___ENTER__ 0
138+
#define SPECIAL___EXIT__ 1
139+
#define SPECIAL___AENTER__ 2
140+
#define SPECIAL___AEXIT__ 3
141+
#define SPECIAL_MAX 3
142+
136143
#ifndef Py_LIMITED_API
137144
# define Py_CPYTHON_CEVAL_H
138145
# include "cpython/ceval.h"

Include/internal/pycore_ceval.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,13 @@ typedef PyObject *(*conversion_func)(PyObject *);
245245
PyAPI_DATA(const binaryfunc) _PyEval_BinaryOps[];
246246
PyAPI_DATA(const conversion_func) _PyEval_ConversionFuncs[];
247247

248+
typedef struct _special_method {
249+
PyObject *name;
250+
const char *error;
251+
} _Py_SpecialMethod;
252+
253+
PyAPI_DATA(const _Py_SpecialMethod) _Py_SpecialMethods[];
254+
248255
PyAPI_FUNC(int) _PyEval_CheckExceptStarTypeValid(PyThreadState *tstate, PyObject* right);
249256
PyAPI_FUNC(int) _PyEval_CheckExceptTypeValid(PyThreadState *tstate, PyObject* right);
250257
PyAPI_FUNC(int) _PyEval_ExceptionGroupMatch(PyObject* exc_value, PyObject *match_type, PyObject **match, PyObject **rest);

Include/internal/pycore_object.h

Lines changed: 1 addition & 0 deletions

Include/internal/pycore_opcode_metadata.h

Lines changed: 11 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_uop_ids.h

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_uop_metadata.h

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)