Skip to content

Commit e9b09d5

Browse files
committed
Merge branch 'main' into inline-attributes-with-opt
2 parents 42361ad + a7252f8 commit e9b09d5

File tree

4 files changed

+48
-25
lines changed

4 files changed

+48
-25
lines changed

Lib/test/test_dis.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,7 @@ def _prepare_test_cases():
10461046
Instruction(opname='COMPARE_OP', opcode=107, arg=4, argval='>', argrepr='>', offset=34, starts_line=None, is_jump_target=False, positions=None),
10471047
Instruction(opname='POP_JUMP_IF_FALSE', opcode=114, arg=21, argval=42, argrepr='to 42', offset=36, starts_line=None, is_jump_target=False, positions=None),
10481048
Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=38, starts_line=8, is_jump_target=False, positions=None),
1049-
Instruction(opname='JUMP_ABSOLUTE', opcode=113, arg=26, argval=52, argrepr='to 52', offset=40, starts_line=None, is_jump_target=False, positions=None),
1049+
Instruction(opname='JUMP_FORWARD', opcode=110, arg=5, argval=52, argrepr='to 52', offset=40, starts_line=None, is_jump_target=False, positions=None),
10501050
Instruction(opname='JUMP_ABSOLUTE', opcode=113, arg=4, argval=8, argrepr='to 8', offset=42, starts_line=7, is_jump_target=True, positions=None),
10511051
Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=44, starts_line=10, is_jump_target=True, positions=None),
10521052
Instruction(opname='LOAD_CONST', opcode=100, arg=4, argval='I can haz else clause?', argrepr="'I can haz else clause?'", offset=46, starts_line=None, is_jump_target=False, positions=None),
@@ -1071,7 +1071,7 @@ def _prepare_test_cases():
10711071
Instruction(opname='LOAD_CONST', opcode=100, arg=2, argval=4, argrepr='4', offset=84, starts_line=None, is_jump_target=False, positions=None),
10721072
Instruction(opname='COMPARE_OP', opcode=107, arg=0, argval='<', argrepr='<', offset=86, starts_line=None, is_jump_target=False, positions=None),
10731073
Instruction(opname='POP_JUMP_IF_FALSE', opcode=114, arg=46, argval=92, argrepr='to 92', offset=88, starts_line=None, is_jump_target=False, positions=None),
1074-
Instruction(opname='JUMP_ABSOLUTE', opcode=113, arg=52, argval=104, argrepr='to 104', offset=90, starts_line=17, is_jump_target=False, positions=None),
1074+
Instruction(opname='JUMP_FORWARD', opcode=110, arg=6, argval=104, argrepr='to 104', offset=90, starts_line=17, is_jump_target=False, positions=None),
10751075
Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=92, starts_line=11, is_jump_target=True, positions=None),
10761076
Instruction(opname='POP_JUMP_IF_TRUE', opcode=115, arg=28, argval=56, argrepr='to 56', offset=94, starts_line=None, is_jump_target=False, positions=None),
10771077
Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=96, starts_line=19, is_jump_target=True, positions=None),

Objects/dictobject.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -461,10 +461,11 @@ static PyDictValues empty_values_struct = { 0, { NULL }};
461461
#endif
462462

463463
static inline int
464-
get_index_from_order(PyDictObject *mp, int i)
464+
get_index_from_order(PyDictObject *mp, Py_ssize_t i)
465465
{
466-
int shift = (mp->ma_used-1-i)*4;
467-
return (mp->ma_values->mv_order >> shift) & 15;
466+
assert(mp->ma_used <= 16);
467+
int shift = (int)(mp->ma_used-1-i)*4;
468+
return (int)(mp->ma_values->mv_order >> shift) & 15;
468469
}
469470

470471
int
@@ -496,14 +497,13 @@ _PyDict_CheckConsistency(PyObject *op, int check_content)
496497

497498
if (check_content) {
498499
PyDictKeyEntry *entries = DK_ENTRIES(keys);
499-
Py_ssize_t i;
500500

501-
for (i=0; i < DK_SIZE(keys); i++) {
501+
for (Py_ssize_t i=0; i < DK_SIZE(keys); i++) {
502502
Py_ssize_t ix = dictkeys_get_index(keys, i);
503503
CHECK(DKIX_DUMMY <= ix && ix <= usable);
504504
}
505505

506-
for (i=0; i < usable; i++) {
506+
for (Py_ssize_t i=0; i < usable; i++) {
507507
PyDictKeyEntry *entry = &entries[i];
508508
PyObject *key = entry->me_key;
509509

@@ -531,7 +531,7 @@ _PyDict_CheckConsistency(PyObject *op, int check_content)
531531
CHECK(mp->ma_used <= SHARED_KEYS_MAX_SIZE);
532532
/* splitted table */
533533
int duplicate_check = 0;
534-
for (i=0; i < mp->ma_used; i++) {
534+
for (Py_ssize_t i=0; i < mp->ma_used; i++) {
535535
int index = get_index_from_order(mp, i);
536536
CHECK((duplicate_check & (1<<index)) == 0);
537537
duplicate_check |= (1<<index);
@@ -1079,7 +1079,7 @@ insertdict(PyDictObject *mp, PyObject *key, Py_hash_t hash, PyObject *value)
10791079
ep->me_key = key;
10801080
ep->me_hash = hash;
10811081
if (mp->ma_values) {
1082-
int index = mp->ma_keys->dk_nentries;
1082+
Py_ssize_t index = mp->ma_keys->dk_nentries;
10831083
assert(index < SHARED_KEYS_MAX_SIZE);
10841084
assert((mp->ma_values->mv_order >> 60) == 0);
10851085
mp->ma_values->mv_order = (mp->ma_values->mv_order)<<4 | index;
@@ -1227,7 +1227,7 @@ dictresize(PyDictObject *mp, uint8_t log2_newsize)
12271227
* Note that values of split table is always dense.
12281228
*/
12291229
for (Py_ssize_t i = 0; i < numentries; i++) {
1230-
int index = oldvalues->mv_order >> ((numentries-1-i)*4)&15;
1230+
int index = oldvalues->mv_order >> ((numentries-1-i)*4) & 15;
12311231
assert(oldvalues->values[index] != NULL);
12321232
PyDictKeyEntry *ep = &oldentries[index];
12331233
PyObject *key = ep->me_key;
@@ -1592,7 +1592,7 @@ delitem_common(PyDictObject *mp, Py_hash_t hash, Py_ssize_t ix,
15921592
if (((mp->ma_values->mv_order >> i) & 15) == (uint64_t)ix) {
15931593
/* Remove 4 bits at ith position */
15941594
uint64_t order = mp->ma_values->mv_order;
1595-
uint64_t high = order >> i >> 4 << i;
1595+
uint64_t high = ((order>>i)>>4)<<i;
15961596
uint64_t low = order & ((((uint64_t)1)<<i)-1);
15971597
mp->ma_values->mv_order = high | low;
15981598
break;
@@ -2989,7 +2989,7 @@ PyDict_SetDefault(PyObject *d, PyObject *key, PyObject *defaultobj)
29892989
ep->me_key = key;
29902990
ep->me_hash = hash;
29912991
if (_PyDict_HasSplitTable(mp)) {
2992-
int index = mp->ma_keys->dk_nentries;
2992+
int index = (int)mp->ma_keys->dk_nentries;
29932993
assert(index < SHARED_KEYS_MAX_SIZE);
29942994
assert(mp->ma_values->values[index] == NULL);
29952995
mp->ma_values->values[index] = value;

Python/ceval.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4045,19 +4045,18 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
40454045

40464046
TARGET(JUMP_ABSOLUTE) {
40474047
PREDICTED(JUMP_ABSOLUTE);
4048-
if (oparg < INSTR_OFFSET()) {
4049-
/* Increment the warmup counter and quicken if warm enough
4050-
* _Py_Quicken is idempotent so we don't worry about overflow */
4051-
if (!PyCodeObject_IsWarmedUp(co)) {
4052-
PyCodeObject_IncrementWarmup(co);
4053-
if (PyCodeObject_IsWarmedUp(co)) {
4054-
if (_Py_Quicken(co)) {
4055-
goto error;
4056-
}
4057-
int nexti = INSTR_OFFSET();
4058-
first_instr = co->co_firstinstr;
4059-
next_instr = first_instr + nexti;
4048+
assert(oparg < INSTR_OFFSET());
4049+
/* Increment the warmup counter and quicken if warm enough
4050+
* _Py_Quicken is idempotent so we don't worry about overflow */
4051+
if (!PyCodeObject_IsWarmedUp(co)) {
4052+
PyCodeObject_IncrementWarmup(co);
4053+
if (PyCodeObject_IsWarmedUp(co)) {
4054+
if (_Py_Quicken(co)) {
4055+
goto error;
40604056
}
4057+
int nexti = INSTR_OFFSET();
4058+
first_instr = co->co_firstinstr;
4059+
next_instr = first_instr + nexti;
40614060
}
40624061
}
40634062
JUMPTO(oparg);
@@ -4066,6 +4065,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
40664065
}
40674066

40684067
TARGET(JUMP_ABSOLUTE_QUICK) {
4068+
assert(oparg < INSTR_OFFSET());
40694069
JUMPTO(oparg);
40704070
CHECK_EVAL_BREAKER();
40714071
DISPATCH();

Python/compile.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7220,6 +7220,26 @@ assemble_emit(struct assembler *a, struct instr *i)
72207220
return 1;
72217221
}
72227222

7223+
static void
7224+
normalize_jumps(struct assembler *a)
7225+
{
7226+
for (basicblock *b = a->a_entry; b != NULL; b = b->b_next) {
7227+
b->b_visited = 0;
7228+
}
7229+
for (basicblock *b = a->a_entry; b != NULL; b = b->b_next) {
7230+
b->b_visited = 1;
7231+
if (b->b_iused == 0) {
7232+
continue;
7233+
}
7234+
struct instr *last = &b->b_instr[b->b_iused-1];
7235+
if (last->i_opcode == JUMP_ABSOLUTE &&
7236+
last->i_target->b_visited == 0
7237+
) {
7238+
last->i_opcode = JUMP_FORWARD;
7239+
}
7240+
}
7241+
}
7242+
72237243
static void
72247244
assemble_jump_offsets(struct assembler *a, struct compiler *c)
72257245
{
@@ -7897,6 +7917,9 @@ assemble(struct compiler *c, int addNone)
78977917
clean_basic_block(b);
78987918
}
78997919

7920+
/* Order of basic blocks must have been determined by now */
7921+
normalize_jumps(&a);
7922+
79007923
/* Can't modify the bytecode after computing jump offsets. */
79017924
assemble_jump_offsets(&a, c);
79027925

0 commit comments

Comments
 (0)