From 11fc9d7e084daa13fc05640182ece01f51369bc2 Mon Sep 17 00:00:00 2001 From: Irit Katriel Date: Mon, 13 Nov 2023 15:49:21 +0000 Subject: [PATCH 1/6] gh-107149: make new opcode utils private --- Include/cpython/compile.h | 20 ++++++++++---------- Modules/_opcode.c | 34 +++++++++++++++++----------------- Python/compile.c | 16 ++++++++-------- Python/intrinsics.c | 4 ++-- 4 files changed, 37 insertions(+), 37 deletions(-) diff --git a/Include/cpython/compile.h b/Include/cpython/compile.h index 265f5397b45116..4be42ffe505db0 100644 --- a/Include/cpython/compile.h +++ b/Include/cpython/compile.h @@ -69,14 +69,14 @@ typedef struct { PyAPI_FUNC(int) PyCompile_OpcodeStackEffect(int opcode, int oparg); PyAPI_FUNC(int) PyCompile_OpcodeStackEffectWithJump(int opcode, int oparg, int jump); -PyAPI_FUNC(int) PyUnstable_OpcodeIsValid(int opcode); -PyAPI_FUNC(int) PyUnstable_OpcodeHasArg(int opcode); -PyAPI_FUNC(int) PyUnstable_OpcodeHasConst(int opcode); -PyAPI_FUNC(int) PyUnstable_OpcodeHasName(int opcode); -PyAPI_FUNC(int) PyUnstable_OpcodeHasJump(int opcode); -PyAPI_FUNC(int) PyUnstable_OpcodeHasFree(int opcode); -PyAPI_FUNC(int) PyUnstable_OpcodeHasLocal(int opcode); -PyAPI_FUNC(int) PyUnstable_OpcodeHasExc(int opcode); +PyAPI_FUNC(int) _PyCompile_OpcodeIsValid(int opcode); +PyAPI_FUNC(int) _PyCompile_OpcodeHasArg(int opcode); +PyAPI_FUNC(int) _PyCompile_OpcodeHasConst(int opcode); +PyAPI_FUNC(int) _PyCompile_OpcodeHasName(int opcode); +PyAPI_FUNC(int) _PyCompile_OpcodeHasJump(int opcode); +PyAPI_FUNC(int) _PyCompile_OpcodeHasFree(int opcode); +PyAPI_FUNC(int) _PyCompile_OpcodeHasLocal(int opcode); +PyAPI_FUNC(int) _PyCompile_OpcodeHasExc(int opcode); -PyAPI_FUNC(PyObject*) PyUnstable_GetUnaryIntrinsicName(int index); -PyAPI_FUNC(PyObject*) PyUnstable_GetBinaryIntrinsicName(int index); +PyAPI_FUNC(PyObject*) _PyCompile_GetUnaryIntrinsicName(int index); +PyAPI_FUNC(PyObject*) _PyCompile_GetBinaryIntrinsicName(int index); diff --git a/Modules/_opcode.c b/Modules/_opcode.c index f0b547795b847a..afc696aa6783e9 100644 --- a/Modules/_opcode.c +++ b/Modules/_opcode.c @@ -78,7 +78,7 @@ static int _opcode_is_valid_impl(PyObject *module, int opcode) /*[clinic end generated code: output=b0d918ea1d073f65 input=fe23e0aa194ddae0]*/ { - return PyUnstable_OpcodeIsValid(opcode); + return _PyCompile_OpcodeIsValid(opcode); } /*[clinic input] @@ -94,8 +94,8 @@ static int _opcode_has_arg_impl(PyObject *module, int opcode) /*[clinic end generated code: output=7a062d3b2dcc0815 input=93d878ba6361db5f]*/ { - return PyUnstable_OpcodeIsValid(opcode) && - PyUnstable_OpcodeHasArg(opcode); + return _PyCompile_OpcodeIsValid(opcode) && + _PyCompile_OpcodeHasArg(opcode); } /*[clinic input] @@ -111,8 +111,8 @@ static int _opcode_has_const_impl(PyObject *module, int opcode) /*[clinic end generated code: output=c646d5027c634120 input=a6999e4cf13f9410]*/ { - return PyUnstable_OpcodeIsValid(opcode) && - PyUnstable_OpcodeHasConst(opcode); + return _PyCompile_OpcodeIsValid(opcode) && + _PyCompile_OpcodeHasConst(opcode); } /*[clinic input] @@ -128,8 +128,8 @@ static int _opcode_has_name_impl(PyObject *module, int opcode) /*[clinic end generated code: output=b49a83555c2fa517 input=448aa5e4bcc947ba]*/ { - return PyUnstable_OpcodeIsValid(opcode) && - PyUnstable_OpcodeHasName(opcode); + return _PyCompile_OpcodeIsValid(opcode) && + _PyCompile_OpcodeHasName(opcode); } /*[clinic input] @@ -145,8 +145,8 @@ static int _opcode_has_jump_impl(PyObject *module, int opcode) /*[clinic end generated code: output=e9c583c669f1c46a input=35f711274357a0c3]*/ { - return PyUnstable_OpcodeIsValid(opcode) && - PyUnstable_OpcodeHasJump(opcode); + return _PyCompile_OpcodeIsValid(opcode) && + _PyCompile_OpcodeHasJump(opcode); } @@ -168,8 +168,8 @@ static int _opcode_has_free_impl(PyObject *module, int opcode) /*[clinic end generated code: output=d81ae4d79af0ee26 input=117dcd5c19c1139b]*/ { - return PyUnstable_OpcodeIsValid(opcode) && - PyUnstable_OpcodeHasFree(opcode); + return _PyCompile_OpcodeIsValid(opcode) && + _PyCompile_OpcodeHasFree(opcode); } @@ -186,8 +186,8 @@ static int _opcode_has_local_impl(PyObject *module, int opcode) /*[clinic end generated code: output=da5a8616b7a5097b input=9a798ee24aaef49d]*/ { - return PyUnstable_OpcodeIsValid(opcode) && - PyUnstable_OpcodeHasLocal(opcode); + return _PyCompile_OpcodeIsValid(opcode) && + _PyCompile_OpcodeHasLocal(opcode); } /*[clinic input] @@ -203,8 +203,8 @@ static int _opcode_has_exc_impl(PyObject *module, int opcode) /*[clinic end generated code: output=41b68dff0ec82a52 input=db0e4bdb9bf13fa5]*/ { - return PyUnstable_OpcodeIsValid(opcode) && - PyUnstable_OpcodeHasExc(opcode); + return _PyCompile_OpcodeIsValid(opcode) && + _PyCompile_OpcodeHasExc(opcode); } /*[clinic input] @@ -309,7 +309,7 @@ _opcode_get_intrinsic1_descs_impl(PyObject *module) return NULL; } for (int i=0; i <= MAX_INTRINSIC_1; i++) { - PyObject *name = PyUnstable_GetUnaryIntrinsicName(i); + PyObject *name = _PyCompile_GetUnaryIntrinsicName(i); if (name == NULL) { Py_DECREF(list); return NULL; @@ -336,7 +336,7 @@ _opcode_get_intrinsic2_descs_impl(PyObject *module) return NULL; } for (int i=0; i <= MAX_INTRINSIC_2; i++) { - PyObject *name = PyUnstable_GetBinaryIntrinsicName(i); + PyObject *name = _PyCompile_GetBinaryIntrinsicName(i); if (name == NULL) { Py_DECREF(list); return NULL; diff --git a/Python/compile.c b/Python/compile.c index 6c64b405b2b286..8b1eef79a79eae 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -883,49 +883,49 @@ PyCompile_OpcodeStackEffect(int opcode, int oparg) } int -PyUnstable_OpcodeIsValid(int opcode) +_PyCompile_OpcodeIsValid(int opcode) { return IS_VALID_OPCODE(opcode); } int -PyUnstable_OpcodeHasArg(int opcode) +_PyCompile_OpcodeHasArg(int opcode) { return OPCODE_HAS_ARG(opcode); } int -PyUnstable_OpcodeHasConst(int opcode) +_PyCompile_OpcodeHasConst(int opcode) { return OPCODE_HAS_CONST(opcode); } int -PyUnstable_OpcodeHasName(int opcode) +_PyCompile_OpcodeHasName(int opcode) { return OPCODE_HAS_NAME(opcode); } int -PyUnstable_OpcodeHasJump(int opcode) +_PyCompile_OpcodeHasJump(int opcode) { return OPCODE_HAS_JUMP(opcode); } int -PyUnstable_OpcodeHasFree(int opcode) +_PyCompile_OpcodeHasFree(int opcode) { return OPCODE_HAS_FREE(opcode); } int -PyUnstable_OpcodeHasLocal(int opcode) +_PyCompile_OpcodeHasLocal(int opcode) { return OPCODE_HAS_LOCAL(opcode); } int -PyUnstable_OpcodeHasExc(int opcode) +_PyCompile_OpcodeHasExc(int opcode) { return IS_BLOCK_PUSH_OPCODE(opcode); } diff --git a/Python/intrinsics.c b/Python/intrinsics.c index bbd79ec473f470..a9915ffb69fd40 100644 --- a/Python/intrinsics.c +++ b/Python/intrinsics.c @@ -269,7 +269,7 @@ _PyIntrinsics_BinaryFunctions[] = { #undef INTRINSIC_FUNC_ENTRY PyObject* -PyUnstable_GetUnaryIntrinsicName(int index) +_PyCompile_GetUnaryIntrinsicName(int index) { if (index < 0 || index > MAX_INTRINSIC_1) { return NULL; @@ -278,7 +278,7 @@ PyUnstable_GetUnaryIntrinsicName(int index) } PyObject* -PyUnstable_GetBinaryIntrinsicName(int index) +_PyCompile_GetBinaryIntrinsicName(int index) { if (index < 0 || index > MAX_INTRINSIC_2) { return NULL; From 269f2f5a31c1c25f202344f5b097ff7bc429557f Mon Sep 17 00:00:00 2001 From: Irit Katriel Date: Mon, 13 Nov 2023 18:34:28 +0000 Subject: [PATCH 2/6] add comment --- Include/cpython/compile.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Include/cpython/compile.h b/Include/cpython/compile.h index 4be42ffe505db0..ad35edd41bc8a1 100644 --- a/Include/cpython/compile.h +++ b/Include/cpython/compile.h @@ -69,6 +69,7 @@ typedef struct { PyAPI_FUNC(int) PyCompile_OpcodeStackEffect(int opcode, int oparg); PyAPI_FUNC(int) PyCompile_OpcodeStackEffectWithJump(int opcode, int oparg, int jump); +/* The following are exported for use in the _opcode modula (Modules/_opcode.c) */ PyAPI_FUNC(int) _PyCompile_OpcodeIsValid(int opcode); PyAPI_FUNC(int) _PyCompile_OpcodeHasArg(int opcode); PyAPI_FUNC(int) _PyCompile_OpcodeHasConst(int opcode); From da3a3ddb9a6e3b32680cb3992f351bbe72729215 Mon Sep 17 00:00:00 2001 From: Irit Katriel <1055913+iritkatriel@users.noreply.github.com> Date: Mon, 13 Nov 2023 20:35:09 +0000 Subject: [PATCH 3/6] Update Include/cpython/compile.h Co-authored-by: Oleg Iarygin --- Include/cpython/compile.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Include/cpython/compile.h b/Include/cpython/compile.h index ad35edd41bc8a1..2c24596f162490 100644 --- a/Include/cpython/compile.h +++ b/Include/cpython/compile.h @@ -69,7 +69,7 @@ typedef struct { PyAPI_FUNC(int) PyCompile_OpcodeStackEffect(int opcode, int oparg); PyAPI_FUNC(int) PyCompile_OpcodeStackEffectWithJump(int opcode, int oparg, int jump); -/* The following are exported for use in the _opcode modula (Modules/_opcode.c) */ +/* The following are exported for use in the _opcode module (Modules/_opcode.c) */ PyAPI_FUNC(int) _PyCompile_OpcodeIsValid(int opcode); PyAPI_FUNC(int) _PyCompile_OpcodeHasArg(int opcode); PyAPI_FUNC(int) _PyCompile_OpcodeHasConst(int opcode); From fd24584c0e7eb03e6070c4a0aaa9cb7602db68e2 Mon Sep 17 00:00:00 2001 From: Irit Katriel Date: Mon, 13 Nov 2023 21:40:15 +0000 Subject: [PATCH 4/6] move most declarations to /Include/internal.. --- Include/cpython/compile.h | 12 ++---------- Include/internal/pycore_compile.h | 11 +++++++++++ Modules/_opcode.c | 1 + 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/Include/cpython/compile.h b/Include/cpython/compile.h index 2c24596f162490..a4ddb69061cce9 100644 --- a/Include/cpython/compile.h +++ b/Include/cpython/compile.h @@ -69,15 +69,7 @@ typedef struct { PyAPI_FUNC(int) PyCompile_OpcodeStackEffect(int opcode, int oparg); PyAPI_FUNC(int) PyCompile_OpcodeStackEffectWithJump(int opcode, int oparg, int jump); -/* The following are exported for use in the _opcode module (Modules/_opcode.c) */ -PyAPI_FUNC(int) _PyCompile_OpcodeIsValid(int opcode); -PyAPI_FUNC(int) _PyCompile_OpcodeHasArg(int opcode); -PyAPI_FUNC(int) _PyCompile_OpcodeHasConst(int opcode); -PyAPI_FUNC(int) _PyCompile_OpcodeHasName(int opcode); -PyAPI_FUNC(int) _PyCompile_OpcodeHasJump(int opcode); -PyAPI_FUNC(int) _PyCompile_OpcodeHasFree(int opcode); -PyAPI_FUNC(int) _PyCompile_OpcodeHasLocal(int opcode); -PyAPI_FUNC(int) _PyCompile_OpcodeHasExc(int opcode); - +// Export for '_opcode' extention module PyAPI_FUNC(PyObject*) _PyCompile_GetUnaryIntrinsicName(int index); PyAPI_FUNC(PyObject*) _PyCompile_GetBinaryIntrinsicName(int index); + diff --git a/Include/internal/pycore_compile.h b/Include/internal/pycore_compile.h index a5a7146f5ee917..8ee5727ec2290d 100644 --- a/Include/internal/pycore_compile.h +++ b/Include/internal/pycore_compile.h @@ -102,6 +102,17 @@ int _PyCompile_EnsureArrayLargeEnough( int _PyCompile_ConstCacheMergeOne(PyObject *const_cache, PyObject **obj); + +// Export for '_opcode' extention module +PyAPI_FUNC(int) _PyCompile_OpcodeIsValid(int opcode); +PyAPI_FUNC(int) _PyCompile_OpcodeHasArg(int opcode); +PyAPI_FUNC(int) _PyCompile_OpcodeHasConst(int opcode); +PyAPI_FUNC(int) _PyCompile_OpcodeHasName(int opcode); +PyAPI_FUNC(int) _PyCompile_OpcodeHasJump(int opcode); +PyAPI_FUNC(int) _PyCompile_OpcodeHasFree(int opcode); +PyAPI_FUNC(int) _PyCompile_OpcodeHasLocal(int opcode); +PyAPI_FUNC(int) _PyCompile_OpcodeHasExc(int opcode); + /* Access compiler internals for unit testing */ // Export for '_testinternalcapi' shared extension diff --git a/Modules/_opcode.c b/Modules/_opcode.c index afc696aa6783e9..93c71377f03a76 100644 --- a/Modules/_opcode.c +++ b/Modules/_opcode.c @@ -6,6 +6,7 @@ #include "compile.h" #include "opcode.h" #include "internal/pycore_code.h" +#include "internal/pycore_compile.h" #include "internal/pycore_intrinsics.h" /*[clinic input] From 7cb1e3784d340c2a6f056adb89413f031afcdf59 Mon Sep 17 00:00:00 2001 From: Irit Katriel Date: Mon, 13 Nov 2023 22:56:53 +0000 Subject: [PATCH 5/6] move the rest --- Include/cpython/compile.h | 4 ---- Include/internal/pycore_compile.h | 3 +++ Python/intrinsics.c | 1 + 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Include/cpython/compile.h b/Include/cpython/compile.h index a4ddb69061cce9..086685fe62c50b 100644 --- a/Include/cpython/compile.h +++ b/Include/cpython/compile.h @@ -69,7 +69,3 @@ typedef struct { PyAPI_FUNC(int) PyCompile_OpcodeStackEffect(int opcode, int oparg); PyAPI_FUNC(int) PyCompile_OpcodeStackEffectWithJump(int opcode, int oparg, int jump); -// Export for '_opcode' extention module -PyAPI_FUNC(PyObject*) _PyCompile_GetUnaryIntrinsicName(int index); -PyAPI_FUNC(PyObject*) _PyCompile_GetBinaryIntrinsicName(int index); - diff --git a/Include/internal/pycore_compile.h b/Include/internal/pycore_compile.h index 8ee5727ec2290d..e5870759ba74f1 100644 --- a/Include/internal/pycore_compile.h +++ b/Include/internal/pycore_compile.h @@ -113,6 +113,9 @@ PyAPI_FUNC(int) _PyCompile_OpcodeHasFree(int opcode); PyAPI_FUNC(int) _PyCompile_OpcodeHasLocal(int opcode); PyAPI_FUNC(int) _PyCompile_OpcodeHasExc(int opcode); +PyAPI_FUNC(PyObject*) _PyCompile_GetUnaryIntrinsicName(int index); +PyAPI_FUNC(PyObject*) _PyCompile_GetBinaryIntrinsicName(int index); + /* Access compiler internals for unit testing */ // Export for '_testinternalcapi' shared extension diff --git a/Python/intrinsics.c b/Python/intrinsics.c index a9915ffb69fd40..d3146973b75178 100644 --- a/Python/intrinsics.c +++ b/Python/intrinsics.c @@ -5,6 +5,7 @@ #include "pycore_frame.h" #include "pycore_function.h" #include "pycore_global_objects.h" +#include "pycore_compile.h" // _PyCompile_GetUnaryIntrinsicName, etc #include "pycore_intrinsics.h" // INTRINSIC_PRINT #include "pycore_pyerrors.h" // _PyErr_SetString() #include "pycore_runtime.h" // _Py_ID() From b14458a4294d6c6dbbcd66b9a633b8bfe92b419b Mon Sep 17 00:00:00 2001 From: Irit Katriel Date: Tue, 14 Nov 2023 00:09:08 +0000 Subject: [PATCH 6/6] whitespace --- Include/cpython/compile.h | 1 - 1 file changed, 1 deletion(-) diff --git a/Include/cpython/compile.h b/Include/cpython/compile.h index 086685fe62c50b..0d587505ef7f85 100644 --- a/Include/cpython/compile.h +++ b/Include/cpython/compile.h @@ -68,4 +68,3 @@ typedef struct { #define PY_INVALID_STACK_EFFECT INT_MAX PyAPI_FUNC(int) PyCompile_OpcodeStackEffect(int opcode, int oparg); PyAPI_FUNC(int) PyCompile_OpcodeStackEffectWithJump(int opcode, int oparg, int jump); -