Skip to content

Commit 080d999

Browse files
authored
Merge branch 'main' into fix-predicate-symbol-bug
2 parents 7d66b07 + 1dc12b2 commit 080d999

File tree

12 files changed

+1594
-903
lines changed

12 files changed

+1594
-903
lines changed

Include/internal/pycore_optimizer.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,15 @@ typedef struct _JitOptContext {
3737
// Arena for the symbolic types.
3838
ty_arena t_arena;
3939

40+
// Arena for the descriptor mappings.
41+
descr_arena d_arena;
42+
4043
JitOptRef *n_consumed;
4144
JitOptRef *limit;
4245
JitOptRef locals_and_stack[MAX_ABSTRACT_INTERP_SIZE];
4346
_PyJitUopBuffer out_buffer;
47+
// Index of the last escaped uop in out_buffer.
48+
int last_escape_index;
4449
} JitOptContext;
4550

4651

@@ -295,6 +300,9 @@ extern JitOptRef _Py_uop_sym_new_truthiness(JitOptContext *ctx, JitOptRef value,
295300
extern bool _Py_uop_sym_is_compact_int(JitOptRef sym);
296301
extern JitOptRef _Py_uop_sym_new_compact_int(JitOptContext *ctx);
297302
extern void _Py_uop_sym_set_compact_int(JitOptContext *ctx, JitOptRef sym);
303+
extern JitOptRef _Py_uop_sym_new_descr_object(JitOptContext *ctx, unsigned int type_version);
304+
extern JitOptRef _Py_uop_sym_get_attr(JitOptContext *ctx, JitOptRef ref, uint16_t slot_index);
305+
extern JitOptRef _Py_uop_sym_set_attr(JitOptContext *ctx, JitOptRef ref, uint16_t slot_index, JitOptRef value);
298306
extern JitOptRef _Py_uop_sym_new_predicate(JitOptContext *ctx, JitOptRef lhs_ref, JitOptRef rhs_ref, JitOptPredicateKind kind);
299307
extern void _Py_uop_sym_apply_predicate_narrowing(JitOptContext *ctx, JitOptRef sym, bool branch_is_true);
300308

Include/internal/pycore_optimizer_types.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ extern "C" {
1616

1717
#define TY_ARENA_SIZE (UOP_MAX_TRACE_LENGTH * 5)
1818

19+
// Maximum descriptor mappings per object tracked symbolically
20+
#define MAX_SYMBOLIC_DESCR_SIZE 16
21+
#define DESCR_ARENA_SIZE (MAX_SYMBOLIC_DESCR_SIZE * 100)
22+
1923
// Need extras for root frame and for overflow frame (see TRACE_STACK_PUSH())
2024
#define MAX_ABSTRACT_FRAME_DEPTH (16)
2125

@@ -41,6 +45,7 @@ typedef enum _JitSymType {
4145
JIT_SYM_TRUTHINESS_TAG = 9,
4246
JIT_SYM_COMPACT_INT = 10,
4347
JIT_SYM_PREDICATE_TAG = 11,
48+
JIT_SYM_DESCR_TAG = 12,
4449
} JitSymType;
4550

4651
typedef struct _jit_opt_known_class {
@@ -91,6 +96,31 @@ typedef struct {
9196
uint8_t tag;
9297
} JitOptCompactInt;
9398

99+
/*
100+
Mapping from slot index or attribute offset to its symbolic value.
101+
SAFETY:
102+
This structure is used for both STORE_ATTR_SLOT and STORE_ATTR_INSTANCE_VALUE.
103+
These two never appear on the same object type because:
104+
__slots__ classes don't have Py_TPFLAGS_INLINE_VALUES
105+
Therefore, there is no index collision between slot offsets and inline value offsets.
106+
Note:
107+
STORE_ATTR_WITH_HINT is NOT currently tracked.
108+
If we want to track it in the future, we need to be careful about
109+
potential index collisions with STORE_ATTR_INSTANCE_VALUE.
110+
*/
111+
typedef struct {
112+
uint16_t slot_index;
113+
uint16_t symbol;
114+
} JitOptDescrMapping;
115+
116+
typedef struct _jit_opt_descr {
117+
uint8_t tag;
118+
uint8_t num_descrs;
119+
uint16_t last_modified_index; // Index in out_buffer when this object was last modified
120+
uint32_t type_version;
121+
JitOptDescrMapping *descrs;
122+
} JitOptDescrObject;
123+
94124
typedef union _jit_opt_symbol {
95125
uint8_t tag;
96126
JitOptKnownClass cls;
@@ -99,6 +129,7 @@ typedef union _jit_opt_symbol {
99129
JitOptTuple tuple;
100130
JitOptTruthiness truthiness;
101131
JitOptCompactInt compact;
132+
JitOptDescrObject descr;
102133
JitOptPredicate predicate;
103134
} JitOptSymbol;
104135

@@ -128,6 +159,11 @@ typedef struct ty_arena {
128159
JitOptSymbol arena[TY_ARENA_SIZE];
129160
} ty_arena;
130161

162+
typedef struct descr_arena {
163+
int descr_curr_number;
164+
int descr_max_number;
165+
JitOptDescrMapping arena[DESCR_ARENA_SIZE];
166+
} descr_arena;
131167

132168
#ifdef __cplusplus
133169
}

0 commit comments

Comments
 (0)