8000 GH-93678: reduce boilerplate and code repetition in the compiler by iritkatriel · Pull Request #93682 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

GH-93678: reduce boilerplate and code repetition in the compiler #93682

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 18 commits into from
Jun 14, 2022
Merged
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

10000
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
define NO_LOCATION as a static const in global scope
  • Loading branch information
iritkatriel committed Jun 13, 2022
commit 26dc190be73b24ca25bbc3c377e1745ba7c47c9e
20 changes: 7 additions & 13 deletions Python/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ struct location {
#define LOCATION(LNO, END_LNO, COL, END_COL) \
((const struct location){(LNO), (END_LNO), (COL), (END_COL)})

#define NO_LOCATION {-1, -1, -1, -1}
static struct location NO_LOCATION = {-1, -1, -1, -1};

struct instr {
int i_opcode;
Expand Down Expand Up @@ -1285,8 +1285,6 @@ basicblock_addop(basicblock *b, int opcode, int oparg,
IS_BLOCK_PUSH_OPCODE(opcode));
assert(oparg == 0 || target == NULL);

static struct location no_location = NO_LOCATION;

int off = basicblock_next_instr(b);
if (off < 0) {
return 0;
Expand All @@ -1295,7 +1293,7 @@ basicblock_addop(basicblock *b, int opcode, int oparg,
i->i_opcode = opcode;
i->i_oparg = oparg;
i->i_target = target;
i->i_loc = loc ? *loc : no_location;
i->i_loc = loc ? *loc : NO_LOCATION;

return 1;
}
Expand Down Expand Up @@ -7388,8 +7386,7 @@ push_cold_blocks_to_end(struct compiler *c, basicblock *entry, int code_flags) {
if (explicit_jump == NULL) {
return -1;
}
static struct location no_location = NO_LOCATION;
basicblock_addop(explicit_jump, JUMP, 0, b->b_next, &no_location);
basicblock_addop(explicit_jump, JUMP, 0, b->b_next, &NO_LOCATION);

explicit_jump->b_cold = 1;
explicit_jump->b_next = b->b_next;
Expand Down Expand Up @@ -8294,8 +8291,6 @@ insert_prefix_instructions(struct compiler *c, basicblock *entryblock,
{
assert(c->u->u_firstlineno > 0);

static struct location no_location = NO_LOCATION;

/* Add the generator prefix instructions. */
if (code_flags & (CO_GENERATOR | CO_COROUTINE | CO_ASYNC_GENERATOR)) {
struct instr make_gen = {
Expand All @@ -8310,7 +8305,7 @@ insert_prefix_instructions(struct compiler *c, basicblock *entryblock,
struct instr pop_top = {
.i_opcode = POP_TOP,
.i_oparg = 0,
.i_loc = no_location,
.i_loc = NO_LOCATION,
.i_target = NULL,
};
if (insert_instruction(entryblock, 1, &pop_top) < 0) {
Expand Down Expand Up @@ -8342,7 +8337,7 @@ insert_prefix_instructions(struct compiler *c, basicblock *entryblock,
.i_opcode = MAKE_CELL,
// This will get fixed in offset_derefs().
.i_oparg = oldindex,
.i_loc = no_location,
.i_loc = NO_LOCATION,
.i_target = NULL,
};
if (insert_instruction(entryblock, ncellsused, &make_cell) < 0) {
Expand All @@ -8357,7 +8352,7 @@ insert_prefix_instructions(struct compiler *c, basicblock *entryblock,
struct instr copy_frees = {
.i_opcode = COPY_FREE_VARS,
.i_oparg = nfreevars,
.i_loc = no_location,
.i_loc = NO_LOCATION,
.i_target = NULL,
};
if (insert_instruction(entryblock, 0, &copy_frees) < 0) {
Expand Down Expand Up @@ -9363,8 +9358,7 @@ propagate_line_numbers(struct assembler *a) {
continue;
}

static struct location no_location = NO_LOCATION;
struct location prev_location = no_location;
struct location prev_location = NO_LOCATION;
for (int i = 0; i < b->b_iused; i++) {
if (b->b_instr[i].i_loc.lineno < 0) {
b->b_instr[i].i_loc = prev_location;
Expand Down
0