Skip to content

gh-126835: Avoid creating unnecessary tuple when looking for constant sequence during constant folding #131054

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

Merged
merged 7 commits into from
Mar 12, 2025
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
rename get_const_sequence_instructions
  • Loading branch information
WolframAlph committed Mar 10, 2025
commit 64eb38dc6b622c5f67cf58c471d3d134e937352b
10 changes: 5 additions & 5 deletions Python/flowgraph.c
Original file line number Diff line number Diff line change
Expand Up @@ -1351,7 +1351,7 @@ add_const(PyObject *newconst, PyObject *consts, PyObject *const_cache)
Returns boolean indicating whether succeeded to collect requested number of instructions.
*/
static bool
get_const_sequence_instructions(basicblock *bb, int start, cfg_instr **seq, int size)
get_const_instr_sequence(basicblock *bb, int start, cfg_instr **seq, int size)
{
assert(start < bb->b_iused);
assert(size >= 0);
Expand Down Expand Up @@ -1426,7 +1426,7 @@ fold_tuple_of_constants(basicblock *bb, int i, PyObject *consts, PyObject *const
}

cfg_instr *seq[STACK_USE_GUIDELINE];
if (!get_const_sequence_instructions(bb, i-1, seq, seq_size)) {
if (!get_const_instr_sequence(bb, i-1, seq, seq_size)) {
/* not a const sequence */
return SUCCESS;
}
Expand Down Expand Up @@ -1482,7 +1482,7 @@ optimize_lists_and_sets(basicblock *bb, int i, int nextop,
}

cfg_instr *seq[STACK_USE_GUIDELINE];
if (!get_const_sequence_instructions(bb, i-1, seq, seq_size)) { /* not a const sequence */
if (!get_const_instr_sequence(bb, i-1, seq, seq_size)) { /* not a const sequence */
if (contains_or_iter && instr->i_opcode == BUILD_LIST) {
/* iterate over a tuple instead of list */
INSTR_SET_OP1(instr, BUILD_TUPLE, instr->i_oparg);
Expand Down Expand Up @@ -1722,7 +1722,7 @@ fold_const_binop(basicblock *bb, int i, PyObject *consts, PyObject *const_cache)
assert(binop->i_opcode == BINARY_OP);

cfg_instr *seq[BINOP_OPERAND_COUNT];
if (!get_const_sequence_instructions(bb, i-1, seq, BINOP_OPERAND_COUNT)) {
if (!get_const_instr_sequence(bb, i-1, seq, BINOP_OPERAND_COUNT)) {
/* not a const sequence */
return SUCCESS;
}
Expand Down Expand Up @@ -1804,7 +1804,7 @@ fold_const_unaryop(basicblock *bb, int i, PyObject *consts, PyObject *const_cach
cfg_instr *unaryop = &bb->b_instr[i];

cfg_instr *instr;
if (!get_const_sequence_instructions(bb, i - 1, &instr, UNARYOP_OPERAND_COUNT)) {
if (!get_const_instr_sequence(bb, i - 1, &instr, UNARYOP_OPERAND_COUNT)) {
/* not a const */
return SUCCESS;
}
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy