Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6ecfcfe

Browse filesBrowse files
authored
GH-115816: Assorted naming and formatting changes to improve maintainability. (GH-115987)
* Rename _Py_UOpsAbstractInterpContext to _Py_UOpsContext and _Py_UOpsSymType to _Py_UopsSymbol. * #define shortened form of _Py_uop_... names for improved readability.
1 parent 10fbcd6 commit 6ecfcfe
Copy full SHA for 6ecfcfe

File tree

8 files changed

+498
-476
lines changed
Filter options

8 files changed

+498
-476
lines changed

‎Include/internal/pycore_optimizer.h

Copy file name to clipboardExpand all lines: Include/internal/pycore_optimizer.h
+35-38Lines changed: 35 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ extern PyTypeObject _PyUOpOptimizer_Type;
2828

2929
/* Symbols */
3030

31-
struct _Py_UOpsSymType {
31+
struct _Py_UopsSymbol {
3232
int flags;
3333
PyTypeObject *typ;
3434
// constant propagated value (might be NULL)
@@ -38,34 +38,32 @@ struct _Py_UOpsSymType {
3838
// Holds locals, stack, locals, stack ... co_consts (in that order)
3939
#define MAX_ABSTRACT_INTERP_SIZE 4096
4040

41-
#define OVERALLOCATE_FACTOR 5
42-
43-
#define TY_ARENA_SIZE (UOP_MAX_TRACE_LENGTH * OVERALLOCATE_FACTOR)
41+
#define TY_ARENA_SIZE (UOP_MAX_TRACE_LENGTH * 5)
4442

4543
// Need extras for root frame and for overflow frame (see TRACE_STACK_PUSH())
4644
#define MAX_ABSTRACT_FRAME_DEPTH (TRACE_STACK_SIZE + 2)
4745

48-
typedef struct _Py_UOpsSymType _Py_UOpsSymType;
46+
typedef struct _Py_UopsSymbol _Py_UopsSymbol;
4947

5048
struct _Py_UOpsAbstractFrame {
5149
// Max stacklen
5250
int stack_len;
5351
int locals_len;
5452

55-
_Py_UOpsSymType **stack_pointer;
56-
_Py_UOpsSymType **stack;
57-
_Py_UOpsSymType **locals;
53+
_Py_UopsSymbol **stack_pointer;
54+
_Py_UopsSymbol **stack;
55+
_Py_UopsSymbol **locals;
5856
};
5957

6058
typedef struct _Py_UOpsAbstractFrame _Py_UOpsAbstractFrame;
6159

6260
typedef struct ty_arena {
6361
int ty_curr_number;
6462
int ty_max_number;
65-
_Py_UOpsSymType arena[TY_ARENA_SIZE];
63+
_Py_UopsSymbol arena[TY_ARENA_SIZE];
6664
} ty_arena;
6765

68-
struct _Py_UOpsAbstractInterpContext {
66+
struct _Py_UOpsContext {
6967
PyObject_HEAD
7068
// The current "executing" frame.
7169
_Py_UOpsAbstractFrame *frame;
@@ -75,40 +73,39 @@ struct _Py_UOpsAbstractInterpContext {
7573
// Arena for the symbolic types.
7674
ty_arena t_arena;
7775

78-
_Py_UOpsSymType **n_consumed;
79-
_Py_UOpsSymType **limit;
80-
_Py_UOpsSymType *locals_and_stack[MAX_ABSTRACT_INTERP_SIZE];
76+
_Py_UopsSymbol **n_consumed;
77+
_Py_UopsSymbol **limit;
78+
_Py_UopsSymbol *locals_and_stack[MAX_ABSTRACT_INTERP_SIZE];
8179
};
8280

83-
typedef struct _Py_UOpsAbstractInterpContext _Py_UOpsAbstractInterpContext;
84-
85-
extern bool _Py_uop_sym_is_null(_Py_UOpsSymType *sym);
86-
extern bool _Py_uop_sym_is_not_null(_Py_UOpsSymType *sym);
87-
extern bool _Py_uop_sym_is_const(_Py_UOpsSymType *sym);
88-
extern PyObject *_Py_uop_sym_get_const(_Py_UOpsSymType *sym);
89-
extern _Py_UOpsSymType *_Py_uop_sym_new_unknown(_Py_UOpsAbstractInterpContext *ctx);
90-
extern _Py_UOpsSymType *_Py_uop_sym_new_not_null(_Py_UOpsAbstractInterpContext *ctx);
91-
extern _Py_UOpsSymType *_Py_uop_sym_new_type(
92-
_Py_UOpsAbstractInterpContext *ctx, PyTypeObject *typ);
93-
extern _Py_UOpsSymType *_Py_uop_sym_new_const(_Py_UOpsAbstractInterpContext *ctx, PyObject *const_val);
94-
extern _Py_UOpsSymType *_Py_uop_sym_new_null(_Py_UOpsAbstractInterpContext *ctx);
95-
extern bool _Py_uop_sym_matches_type(_Py_UOpsSymType *sym, PyTypeObject *typ);
96-
extern void _Py_uop_sym_set_null(_Py_UOpsSymType *sym);
97-
extern void _Py_uop_sym_set_type(_Py_UOpsSymType *sym, PyTypeObject *tp);
98-
99-
extern int _Py_uop_abstractcontext_init(_Py_UOpsAbstractInterpContext *ctx);
100-
extern void _Py_uop_abstractcontext_fini(_Py_UOpsAbstractInterpContext *ctx);
101-
102-
extern _Py_UOpsAbstractFrame *_Py_uop_ctx_frame_new(
103-
_Py_UOpsAbstractInterpContext *ctx,
81+
typedef struct _Py_UOpsContext _Py_UOpsContext;
82+
83+
extern bool _Py_uop_sym_is_null(_Py_UopsSymbol *sym);
84+
extern bool _Py_uop_sym_is_not_null(_Py_UopsSymbol *sym);
85+
extern bool _Py_uop_sym_is_const(_Py_UopsSymbol *sym);
86+
extern PyObject *_Py_uop_sym_get_const(_Py_UopsSymbol *sym);
87+
extern _Py_UopsSymbol *_Py_uop_sym_new_unknown(_Py_UOpsContext *ctx);
88+
extern _Py_UopsSymbol *_Py_uop_sym_new_not_null(_Py_UOpsContext *ctx);
89+
extern _Py_UopsSymbol *_Py_uop_sym_new_type(
90+
_Py_UOpsContext *ctx, PyTypeObject *typ);
91+
extern _Py_UopsSymbol *_Py_uop_sym_new_const(_Py_UOpsContext *ctx, PyObject *const_val);
92+
extern _Py_UopsSymbol *_Py_uop_sym_new_null(_Py_UOpsContext *ctx);
93+
extern bool _Py_uop_sym_matches_type(_Py_UopsSymbol *sym, PyTypeObject *typ);
94+
extern void _Py_uop_sym_set_null(_Py_UopsSymbol *sym);
95+
extern void _Py_uop_sym_set_type(_Py_UopsSymbol *sym, PyTypeObject *tp);
96+
97+
extern int _Py_uop_abstractcontext_init(_Py_UOpsContext *ctx);
98+
extern void _Py_uop_abstractcontext_fini(_Py_UOpsContext *ctx);
99+
100+
extern _Py_UOpsAbstractFrame *_Py_uop_frame_new(
101+
_Py_UOpsContext *ctx,
104102
PyCodeObject *co,
105-
_Py_UOpsSymType **localsplus_start,
103+
_Py_UopsSymbol **localsplus_start,
106104
int n_locals_already_filled,
107105
int curr_stackentries);
108-
extern int _Py_uop_ctx_frame_pop(_Py_UOpsAbstractInterpContext *ctx);
106+
extern int _Py_uop_frame_pop(_Py_UOpsContext *ctx);
109107

110-
PyAPI_FUNC(PyObject *)
111-
_Py_uop_symbols_test(PyObject *self, PyObject *ignored);
108+
PyAPI_FUNC(PyObject *) _Py_uop_symbols_test(PyObject *self, PyObject *ignored);
112109

113110
#ifdef __cplusplus
114111
}

‎Lib/test/test_generated_cases.py

Copy file name to clipboardExpand all lines: Lib/test/test_generated_cases.py
+6-6Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -890,16 +890,16 @@ def test_overridden_abstract_args(self):
890890
"""
891891
output = """
892892
case OP: {
893-
_Py_UOpsSymType *arg1;
894-
_Py_UOpsSymType *out;
893+
_Py_UopsSymbol *arg1;
894+
_Py_UopsSymbol *out;
895895
arg1 = stack_pointer[-1];
896896
eggs();
897897
stack_pointer[-1] = out;
898898
break;
899899
}
900900
901901
case OP2: {
902-
_Py_UOpsSymType *out;
902+
_Py_UopsSymbol *out;
903903
out = _Py_uop_sym_new_unknown(ctx);
904904
if (out == NULL) goto out_of_space;
905905
stack_pointer[-1] = out;
@@ -924,16 +924,16 @@ def test_no_overridden_case(self):
924924
"""
925925
output = """
926926
case OP: {
927-
_Py_UOpsSymType *out;
927+
_Py_UopsSymbol *out;
928928
out = _Py_uop_sym_new_unknown(ctx);
929929
if (out == NULL) goto out_of_space;
930930
stack_pointer[-1] = out;
931931
break;
932932
}
933933
934934
case OP2: {
935-
_Py_UOpsSymType *arg1;
936-
_Py_UOpsSymType *out;
935+
_Py_UopsSymbol *arg1;
936+
_Py_UopsSymbol *out;
937937
arg1 = stack_pointer[-1];
938938
stack_pointer[-1] = out;
939939
break;

‎Modules/_testinternalcapi.c

Copy file name to clipboardExpand all lines: Modules/_testinternalcapi.c
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#include "pycore_interp.h" // _PyInterpreterState_GetConfigCopy()
2525
#include "pycore_long.h" // _PyLong_Sign()
2626
#include "pycore_object.h" // _PyObject_IsFreed()
27-
#include "pycore_optimizer.h" // _Py_UOpsSymType, etc.
27+
#include "pycore_optimizer.h" // _Py_UopsSymbol, etc.
2828
#include "pycore_pathconfig.h" // _PyPathConfig_ClearGlobal()
2929
#include "pycore_pyerrors.h" // _PyErr_ChainExceptions1()
3030
#include "pycore_pystate.h" // _PyThreadState_GET()

‎Python/optimizer_analysis.c

Copy file name to clipboardExpand all lines: Python/optimizer_analysis.c
+21-4Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,23 @@ remove_globals(_PyInterpreterFrame *frame, _PyUOpInstruction *buffer,
282282
} while (0);
283283

284284

285+
/* Shortened forms for convenience, used in optimizer_bytecodes.c */
286+
#define sym_is_not_null _Py_uop_sym_is_not_null
287+
#define sym_is_const _Py_uop_sym_is_const
288+
#define sym_get_const _Py_uop_sym_get_const
289+
#define sym_new_unknown _Py_uop_sym_new_unknown
290+
#define sym_new_not_null _Py_uop_sym_new_not_null
291+
#define sym_new_type _Py_uop_sym_new_type
292+
#define sym_is_null _Py_uop_sym_is_null
293+
#define sym_new_const _Py_uop_sym_new_const
294+
#define sym_new_null _Py_uop_sym_new_null
295+
#define sym_matches_type _Py_uop_sym_matches_type
296+
#define sym_set_null _Py_uop_sym_set_null
297+
#define sym_set_type _Py_uop_sym_set_type
298+
#define frame_new _Py_uop_frame_new
299+
#define frame_pop _Py_uop_frame_pop
300+
301+
285302
/* 1 for success, 0 for not ready, cannot error at the moment. */
286303
static int
287304
optimize_uops(
@@ -293,13 +310,13 @@ optimize_uops(
293310
)
294311
{
295312

296-
_Py_UOpsAbstractInterpContext context;
297-
_Py_UOpsAbstractInterpContext *ctx = &context;
313+
_Py_UOpsContext context;
314+
_Py_UOpsContext *ctx = &context;
298315

299316
if (_Py_uop_abstractcontext_init(ctx) < 0) {
300317
goto out_of_space;
301318
}
302-
_Py_UOpsAbstractFrame *frame = _Py_uop_ctx_frame_new(ctx, co, ctx->n_consumed, 0, curr_stacklen);
319+
_Py_UOpsAbstractFrame *frame = _Py_uop_frame_new(ctx, co, ctx->n_consumed, 0, curr_stacklen);
303320
if (frame == NULL) {
304321
return -1;
305322
}
@@ -313,7 +330,7 @@ optimize_uops(
313330
int oparg = this_instr->oparg;
314331
uint32_t opcode = this_instr->opcode;
315332

316-
_Py_UOpsSymType **stack_pointer = ctx->frame->stack_pointer;
333+
_Py_UopsSymbol **stack_pointer = ctx->frame->stack_pointer;
317334

318335
DPRINTF(3, "Abstract interpreting %s:%d ",
319336
_PyUOpName(opcode),

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.