gh-93678: add _testinternalcapi.optimize_cfg() and test utils for compiler optimization unit tests (GH-96007)

This commit is contained in:
Irit Katriel 2022-08-24 11:02:53 +01:00 committed by GitHub
parent 6bda5b85b5
commit 420f39f457
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 496 additions and 49 deletions

View file

@ -38,6 +38,11 @@ extern int _PyAST_Optimize(
struct _arena *arena,
_PyASTOptimizeState *state);
/* Access compiler internals for unit testing */
PyAPI_FUNC(PyObject*) _PyCompile_OptimizeCfg(
PyObject *instructions,
PyObject *consts);
#ifdef __cplusplus
}
#endif

View file

@ -298,6 +298,7 @@ struct _Py_global_strings {
STRUCT_FOR_ID(code)
STRUCT_FOR_ID(command)
STRUCT_FOR_ID(comment_factory)
STRUCT_FOR_ID(consts)
STRUCT_FOR_ID(context)
STRUCT_FOR_ID(cookie)
STRUCT_FOR_ID(copy)
@ -407,6 +408,7 @@ struct _Py_global_strings {
STRUCT_FOR_ID(input)
STRUCT_FOR_ID(insert_comments)
STRUCT_FOR_ID(insert_pis)
STRUCT_FOR_ID(instructions)
STRUCT_FOR_ID(intern)
STRUCT_FOR_ID(intersection)
STRUCT_FOR_ID(isatty)

View file

@ -807,6 +807,7 @@ extern "C" {
INIT_ID(code), \
INIT_ID(command), \
INIT_ID(comment_factory), \
INIT_ID(consts), \
INIT_ID(context), \
INIT_ID(cookie), \
INIT_ID(copy), \
@ -916,6 +917,7 @@ extern "C" {
INIT_ID(input), \
INIT_ID(insert_comments), \
INIT_ID(insert_pis), \
INIT_ID(instructions), \
INIT_ID(intern), \
INIT_ID(intersection), \
INIT_ID(isatty), \
@ -1916,6 +1918,8 @@ _PyUnicode_InitStaticStrings(void) {
PyUnicode_InternInPlace(&string);
string = &_Py_ID(comment_factory);
PyUnicode_InternInPlace(&string);
string = &_Py_ID(consts);
PyUnicode_InternInPlace(&string);
string = &_Py_ID(context);
PyUnicode_InternInPlace(&string);
string = &_Py_ID(cookie);
@ -2134,6 +2138,8 @@ _PyUnicode_InitStaticStrings(void) {
PyUnicode_InternInPlace(&string);
string = &_Py_ID(insert_pis);
PyUnicode_InternInPlace(&string);
string = &_Py_ID(instructions);
PyUnicode_InternInPlace(&string);
string = &_Py_ID(intern);
PyUnicode_InternInPlace(&string);
string = &_Py_ID(intersection);
@ -5755,6 +5761,10 @@ _PyStaticObjects_CheckRefcnt(void) {
_PyObject_Dump((PyObject *)&_Py_ID(comment_factory));
Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
};
if (Py_REFCNT((PyObject *)&_Py_ID(consts)) < _PyObject_IMMORTAL_REFCNT) {
_PyObject_Dump((PyObject *)&_Py_ID(consts));
Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
};
if (Py_REFCNT((PyObject *)&_Py_ID(context)) < _PyObject_IMMORTAL_REFCNT) {
_PyObject_Dump((PyObject *)&_Py_ID(context));
Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
@ -6191,6 +6201,10 @@ _PyStaticObjects_CheckRefcnt(void) {
_PyObject_Dump((PyObject *)&_Py_ID(insert_pis));
Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
};
if (Py_REFCNT((PyObject *)&_Py_ID(instructions)) < _PyObject_IMMORTAL_REFCNT) {
_PyObject_Dump((PyObject *)&_Py_ID(instructions));
Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
};
if (Py_REFCNT((PyObject *)&_Py_ID(intern)) < _PyObject_IMMORTAL_REFCNT) {
_PyObject_Dump((PyObject *)&_Py_ID(intern));
Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");