Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-115816: Assorted naming and formatting changes to improve maintainability. #115987

Merged
merged 3 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 35 additions & 38 deletions Include/internal/pycore_optimizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ extern PyTypeObject _PyUOpOptimizer_Type;

/* Symbols */

struct _Py_UOpsSymType {
struct _Py_UopsSymbol {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, the new name uses the incorrect capitalization, Uops, instead of UOps.

int flags;
PyTypeObject *typ;
// constant propagated value (might be NULL)
Expand All @@ -38,34 +38,32 @@ struct _Py_UOpsSymType {
// Holds locals, stack, locals, stack ... co_consts (in that order)
#define MAX_ABSTRACT_INTERP_SIZE 4096

#define OVERALLOCATE_FACTOR 5

#define TY_ARENA_SIZE (UOP_MAX_TRACE_LENGTH * OVERALLOCATE_FACTOR)
#define TY_ARENA_SIZE (UOP_MAX_TRACE_LENGTH * 5)

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

typedef struct _Py_UOpsSymType _Py_UOpsSymType;
typedef struct _Py_UopsSymbol _Py_UopsSymbol;

struct _Py_UOpsAbstractFrame {
// Max stacklen
int stack_len;
int locals_len;

_Py_UOpsSymType **stack_pointer;
_Py_UOpsSymType **stack;
_Py_UOpsSymType **locals;
_Py_UopsSymbol **stack_pointer;
_Py_UopsSymbol **stack;
_Py_UopsSymbol **locals;
};

typedef struct _Py_UOpsAbstractFrame _Py_UOpsAbstractFrame;

typedef struct ty_arena {
int ty_curr_number;
int ty_max_number;
_Py_UOpsSymType arena[TY_ARENA_SIZE];
_Py_UopsSymbol arena[TY_ARENA_SIZE];
} ty_arena;

struct _Py_UOpsAbstractInterpContext {
struct _Py_UOpsContext {
PyObject_HEAD
// The current "executing" frame.
_Py_UOpsAbstractFrame *frame;
Expand All @@ -75,40 +73,39 @@ struct _Py_UOpsAbstractInterpContext {
// Arena for the symbolic types.
ty_arena t_arena;

_Py_UOpsSymType **n_consumed;
_Py_UOpsSymType **limit;
_Py_UOpsSymType *locals_and_stack[MAX_ABSTRACT_INTERP_SIZE];
_Py_UopsSymbol **n_consumed;
_Py_UopsSymbol **limit;
_Py_UopsSymbol *locals_and_stack[MAX_ABSTRACT_INTERP_SIZE];
};

typedef struct _Py_UOpsAbstractInterpContext _Py_UOpsAbstractInterpContext;

extern bool _Py_uop_sym_is_null(_Py_UOpsSymType *sym);
extern bool _Py_uop_sym_is_not_null(_Py_UOpsSymType *sym);
extern bool _Py_uop_sym_is_const(_Py_UOpsSymType *sym);
extern PyObject *_Py_uop_sym_get_const(_Py_UOpsSymType *sym);
extern _Py_UOpsSymType *_Py_uop_sym_new_unknown(_Py_UOpsAbstractInterpContext *ctx);
extern _Py_UOpsSymType *_Py_uop_sym_new_not_null(_Py_UOpsAbstractInterpContext *ctx);
extern _Py_UOpsSymType *_Py_uop_sym_new_type(
_Py_UOpsAbstractInterpContext *ctx, PyTypeObject *typ);
extern _Py_UOpsSymType *_Py_uop_sym_new_const(_Py_UOpsAbstractInterpContext *ctx, PyObject *const_val);
extern _Py_UOpsSymType *_Py_uop_sym_new_null(_Py_UOpsAbstractInterpContext *ctx);
extern bool _Py_uop_sym_matches_type(_Py_UOpsSymType *sym, PyTypeObject *typ);
extern void _Py_uop_sym_set_null(_Py_UOpsSymType *sym);
extern void _Py_uop_sym_set_type(_Py_UOpsSymType *sym, PyTypeObject *tp);

extern int _Py_uop_abstractcontext_init(_Py_UOpsAbstractInterpContext *ctx);
extern void _Py_uop_abstractcontext_fini(_Py_UOpsAbstractInterpContext *ctx);

extern _Py_UOpsAbstractFrame *_Py_uop_ctx_frame_new(
_Py_UOpsAbstractInterpContext *ctx,
typedef struct _Py_UOpsContext _Py_UOpsContext;

extern bool _Py_uop_sym_is_null(_Py_UopsSymbol *sym);
extern bool _Py_uop_sym_is_not_null(_Py_UopsSymbol *sym);
extern bool _Py_uop_sym_is_const(_Py_UopsSymbol *sym);
extern PyObject *_Py_uop_sym_get_const(_Py_UopsSymbol *sym);
extern _Py_UopsSymbol *_Py_uop_sym_new_unknown(_Py_UOpsContext *ctx);
extern _Py_UopsSymbol *_Py_uop_sym_new_not_null(_Py_UOpsContext *ctx);
extern _Py_UopsSymbol *_Py_uop_sym_new_type(
_Py_UOpsContext *ctx, PyTypeObject *typ);
extern _Py_UopsSymbol *_Py_uop_sym_new_const(_Py_UOpsContext *ctx, PyObject *const_val);
extern _Py_UopsSymbol *_Py_uop_sym_new_null(_Py_UOpsContext *ctx);
extern bool _Py_uop_sym_matches_type(_Py_UopsSymbol *sym, PyTypeObject *typ);
extern void _Py_uop_sym_set_null(_Py_UopsSymbol *sym);
extern void _Py_uop_sym_set_type(_Py_UopsSymbol *sym, PyTypeObject *tp);

extern int _Py_uop_abstractcontext_init(_Py_UOpsContext *ctx);
extern void _Py_uop_abstractcontext_fini(_Py_UOpsContext *ctx);

extern _Py_UOpsAbstractFrame *_Py_uop_frame_new(
_Py_UOpsContext *ctx,
PyCodeObject *co,
_Py_UOpsSymType **localsplus_start,
_Py_UopsSymbol **localsplus_start,
int n_locals_already_filled,
int curr_stackentries);
extern int _Py_uop_ctx_frame_pop(_Py_UOpsAbstractInterpContext *ctx);
extern int _Py_uop_frame_pop(_Py_UOpsContext *ctx);

PyAPI_FUNC(PyObject *)
_Py_uop_symbols_test(PyObject *self, PyObject *ignored);
PyAPI_FUNC(PyObject *) _Py_uop_symbols_test(PyObject *self, PyObject *ignored);

#ifdef __cplusplus
}
Expand Down
12 changes: 6 additions & 6 deletions Lib/test/test_generated_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -890,16 +890,16 @@ def test_overridden_abstract_args(self):
"""
output = """
case OP: {
_Py_UOpsSymType *arg1;
_Py_UOpsSymType *out;
_Py_UopsSymbol *arg1;
_Py_UopsSymbol *out;
arg1 = stack_pointer[-1];
eggs();
stack_pointer[-1] = out;
break;
}

case OP2: {
_Py_UOpsSymType *out;
_Py_UopsSymbol *out;
out = _Py_uop_sym_new_unknown(ctx);
if (out == NULL) goto out_of_space;
stack_pointer[-1] = out;
Expand All @@ -924,16 +924,16 @@ def test_no_overridden_case(self):
"""
output = """
case OP: {
_Py_UOpsSymType *out;
_Py_UopsSymbol *out;
out = _Py_uop_sym_new_unknown(ctx);
if (out == NULL) goto out_of_space;
stack_pointer[-1] = out;
break;
}

case OP2: {
_Py_UOpsSymType *arg1;
_Py_UOpsSymType *out;
_Py_UopsSymbol *arg1;
_Py_UopsSymbol *out;
arg1 = stack_pointer[-1];
stack_pointer[-1] = out;
break;
Expand Down
2 changes: 1 addition & 1 deletion Modules/_testinternalcapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "pycore_interp.h" // _PyInterpreterState_GetConfigCopy()
#include "pycore_long.h" // _PyLong_Sign()
#include "pycore_object.h" // _PyObject_IsFreed()
#include "pycore_optimizer.h" // _Py_UOpsSymType, etc.
#include "pycore_optimizer.h" // _Py_UopsSymbol, etc.
#include "pycore_pathconfig.h" // _PyPathConfig_ClearGlobal()
#include "pycore_pyerrors.h" // _PyErr_ChainExceptions1()
#include "pycore_pystate.h" // _PyThreadState_GET()
Expand Down
25 changes: 21 additions & 4 deletions Python/optimizer_analysis.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,23 @@ remove_globals(_PyInterpreterFrame *frame, _PyUOpInstruction *buffer,
} while (0);


/* Shortened forms for convenience, used in optimizer_bytecodes.c */
#define sym_is_not_null _Py_uop_sym_is_not_null
#define sym_is_const _Py_uop_sym_is_const
#define sym_get_const _Py_uop_sym_get_const
#define sym_new_unknown _Py_uop_sym_new_unknown
#define sym_new_not_null _Py_uop_sym_new_not_null
#define sym_new_type _Py_uop_sym_new_type
#define sym_is_null _Py_uop_sym_is_null
#define sym_new_const _Py_uop_sym_new_const
#define sym_new_null _Py_uop_sym_new_null
#define sym_matches_type _Py_uop_sym_matches_type
#define sym_set_null _Py_uop_sym_set_null
#define sym_set_type _Py_uop_sym_set_type
#define frame_new _Py_uop_frame_new
#define frame_pop _Py_uop_frame_pop


/* 1 for success, 0 for not ready, cannot error at the moment. */
static int
optimize_uops(
Expand All @@ -293,13 +310,13 @@ optimize_uops(
)
{

_Py_UOpsAbstractInterpContext context;
_Py_UOpsAbstractInterpContext *ctx = &context;
_Py_UOpsContext context;
_Py_UOpsContext *ctx = &context;

if (_Py_uop_abstractcontext_init(ctx) < 0) {
goto out_of_space;
}
_Py_UOpsAbstractFrame *frame = _Py_uop_ctx_frame_new(ctx, co, ctx->n_consumed, 0, curr_stacklen);
_Py_UOpsAbstractFrame *frame = _Py_uop_frame_new(ctx, co, ctx->n_consumed, 0, curr_stacklen);
if (frame == NULL) {
return -1;
}
Expand All @@ -313,7 +330,7 @@ optimize_uops(
int oparg = this_instr->oparg;
uint32_t opcode = this_instr->opcode;

_Py_UOpsSymType **stack_pointer = ctx->frame->stack_pointer;
_Py_UopsSymbol **stack_pointer = ctx->frame->stack_pointer;

DPRINTF(3, "Abstract interpreting %s:%d ",
_PyUOpName(opcode),
Expand Down
Loading
Loading