mirror of
https://github.com/python/cpython.git
synced 2025-08-22 09:45:06 +00:00
gh-97933: (PEP 709) inline list/dict/set comprehensions (#101441)
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com> Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
This commit is contained in:
parent
0aeda29793
commit
c3b595e73e
27 changed files with 1243 additions and 695 deletions
|
@ -1289,7 +1289,9 @@ swaptimize(basicblock *block, int *ix)
|
|||
// - can't invoke arbitrary code (besides finalizers)
|
||||
// - only touch the TOS (and pop it when finished)
|
||||
#define SWAPPABLE(opcode) \
|
||||
((opcode) == STORE_FAST || (opcode) == POP_TOP)
|
||||
((opcode) == STORE_FAST || \
|
||||
(opcode) == STORE_FAST_MAYBE_NULL || \
|
||||
(opcode) == POP_TOP)
|
||||
|
||||
static int
|
||||
next_swappable_instruction(basicblock *block, int i, int lineno)
|
||||
|
@ -1600,6 +1602,8 @@ scan_block_for_locals(basicblock *b, basicblock ***sp)
|
|||
uint64_t bit = (uint64_t)1 << instr->i_oparg;
|
||||
switch (instr->i_opcode) {
|
||||
case DELETE_FAST:
|
||||
case LOAD_FAST_AND_CLEAR:
|
||||
case STORE_FAST_MAYBE_NULL:
|
||||
unsafe_mask |= bit;
|
||||
break;
|
||||
case STORE_FAST:
|
||||
|
@ -1639,7 +1643,8 @@ fast_scan_many_locals(basicblock *entryblock, int nlocals)
|
|||
Py_ssize_t blocknum = 0;
|
||||
// state[i - 64] == blocknum if local i is guaranteed to
|
||||
// be initialized, i.e., if it has had a previous LOAD_FAST or
|
||||
// STORE_FAST within that basicblock (not followed by DELETE_FAST).
|
||||
// STORE_FAST within that basicblock (not followed by
|
||||
// DELETE_FAST/LOAD_FAST_AND_CLEAR/STORE_FAST_MAYBE_NULL).
|
||||
for (basicblock *b = entryblock; b != NULL; b = b->b_next) {
|
||||
blocknum++;
|
||||
for (int i = 0; i < b->b_iused; i++) {
|
||||
|
@ -1653,6 +1658,8 @@ fast_scan_many_locals(basicblock *entryblock, int nlocals)
|
|||
assert(arg >= 0);
|
||||
switch (instr->i_opcode) {
|
||||
case DELETE_FAST:
|
||||
case LOAD_FAST_AND_CLEAR:
|
||||
case STORE_FAST_MAYBE_NULL:
|
||||
states[arg - 64] = blocknum - 1;
|
||||
break;
|
||||
case STORE_FAST:
|
||||
|
@ -1975,7 +1982,7 @@ push_cold_blocks_to_end(cfg_builder *g, int code_flags) {
|
|||
}
|
||||
|
||||
void
|
||||
_PyCfg_ConvertExceptionHandlersToNops(basicblock *entryblock)
|
||||
_PyCfg_ConvertPseudoOps(basicblock *entryblock)
|
||||
{
|
||||
for (basicblock *b = entryblock; b != NULL; b = b->b_next) {
|
||||
for (int i = 0; i < b->b_iused; i++) {
|
||||
|
@ -1983,6 +1990,9 @@ _PyCfg_ConvertExceptionHandlersToNops(basicblock *entryblock)
|
|||
if (is_block_push(instr) || instr->i_opcode == POP_BLOCK) {
|
||||
INSTR_SET_OP0(instr, NOP);
|
||||
}
|
||||
else if (instr->i_opcode == STORE_FAST_MAYBE_NULL) {
|
||||
instr->i_opcode = STORE_FAST;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (basicblock *b = entryblock; b != NULL; b = b->b_next) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue