FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

GH-125837: Split `LOAD_CONST` into three. by markshannon · Pull Request #125972 · python/cpython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
2a61cfc
Replace RETURN_VLAUE/RETURN_CONST with RETURN_VALUE_FUNC/RETURN_VALUE…
markshannon Oct 22, 2024
42a526c
Add LOAD_CONST_IMMORTAL
markshannon Oct 23, 2024
2a3b1e2
Fix up all the tests apart from test_dis
markshannon Oct 23, 2024
031f320
Update optimizer
markshannon Oct 23, 2024
cb5252b
Fix up test_dis
markshannon Oct 23, 2024
892edbc
Fix up a couple of comments
markshannon Oct 23, 2024
5ce99ca
Apply suggestions from code review
markshannon Oct 24, 2024
325c5fe
Clarify comment
markshannon Oct 24, 2024
6149153
Remove unused function
markshannon Oct 24, 2024
59a554a
Update test
markshannon Oct 24, 2024
bcb4e65
Update dis docs
markshannon Oct 24, 2024
f3383e5
Remove link to remove instruction
markshannon Oct 24, 2024
68e97ba
Restore RETURN_VALUE
markshannon Oct 25, 2024
0b8a5ad
Add LOAD_INT instruction
markshannon Oct 24, 2024
1bfdd70
Fix up dis and some tests
markshannon Oct 24, 2024
f934559
Fix up test dis
markshannon Oct 25, 2024
f135b69
Address review comments
markshannon Oct 25, 2024
8f2a781
Fix __annotate__ docstring
markshannon Oct 25, 2024
97c6cdc
Teach optimizer about LOAD_INT
markshannon Oct 25, 2024
eefcbdf
Remove remnants of earlier PR
markshannon Oct 25, 2024
58dab8e
Remove last remnant of earlier PR
markshannon Oct 25, 2024
81e4dd6
Remove the definitely last remnant of earlier PR
markshannon Oct 25, 2024
050fc1e
Document LOAD_INT and add news
markshannon Oct 25, 2024
46055c1
Revert unnecessary name changes
markshannon Oct 25, 2024
79305d2
Make functions static again to avoid warning
markshannon Oct 25, 2024
7e4b2a8
implement review suggestion
markshannon Oct 25, 2024
57e891e
Address review comments
markshannon Oct 28, 2024
207e35e
Fix typo
markshannon Oct 28, 2024
7c88f69
Remove extra argument
markshannon Oct 28, 2024
9d4e575
Rename LOAD_INT to LOAD_SMALL_INT
markshannon Oct 28, 2024
ae11453
Regenerate test file
markshannon Oct 28, 2024
3a50437
Fix test_dis
markshannon Oct 28, 2024
47927cf
Don't mark LOAD_SMALL_INT as having a constant, as it doesn't load fr…
markshannon Oct 28, 2024
3caac1a
Add back int to test
markshannon Oct 29, 2024
File filter

Filter by extension

Filter by extension .c  (2) .h  (4) .py  (3) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
Prev Previous commit
Next Next commit
Don't mark LOAD_SMALL_INT as having a constant, as it doesn't load fr…
…om code.co_consts
  • Loading branch information
markshannon committed Oct 28, 2024
commit 47927cfd3003daca35ba8807209d9c2c7bfeb505
2 changes: 1 addition & 1 deletion Include/internal/pycore_opcode_metadata.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Include/internal/pycore_uop_metadata.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions Lib/dis.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ def _get_const_value(op, arg, co_consts):
Otherwise (if it is a LOAD_CONST and co_consts is not
provided) returns the dis.UNKNOWN sentinel.
"""
assert op in hasconst
assert op in hasconst or op == LOAD_SMALL_INT

if op == LOAD_SMALL_INT:
return arg
Expand Down Expand Up @@ -993,7 +993,8 @@ def _find_imports(co):
if op == IMPORT_NAME and i >= 2:
from_op = opargs[i-1]
level_op = opargs[i-2]
if (from_op[0] in hasconst and level_op[0] in hasconst):
if (from_op[0] in hasconst and
(level_op[0] in hasconst or level_op[0] == LOAD_SMALL_INT)):
level = _get_const_value(level_op[0], level_op[1], consts)
fromlist = _get_const_value(from_op[0], from_op[1], consts)
yield (names[oparg], level, fromlist)
Expand Down
1 change: 0 additions & 1 deletion Lib/test/test_ast/test_ast.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -2311,7 +2311,6 @@ def get_load_const(self, tree):
def test_load_const(self):
consts = [None,
True, False,
124,
Comment thread
Eclips4 marked this conversation as resolved.
Comment thread
markshannon marked this conversation as resolved.
2.0,
3j,
"unicode",
Expand Down
88 changes: 44 additions & 44 deletions Lib/test/test_dis.py

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions Python/bytecodes.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,6 @@ dummy_func(
}

replicate(4) inst(LOAD_SMALL_INT, (-- value)) {
/* Tell code generator that this is a const load */
(void)FRAME_CO_CONSTS;
assert(oparg < _PY_NSMALLPOSINTS);
PyObject *obj = (PyObject *)&_PyLong_SMALL_INTS[_PY_NSMALLNEGINTS + oparg];
value = PyStackRef_FromPyObjectImmortal(obj);
Expand Down
10 changes: 0 additions & 10 deletions Python/executor_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 10 additions & 4 deletions Python/flowgraph.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1264,11 +1264,17 @@ jump_thread(basicblock *bb, cfg_instr *inst, cfg_instr *target, int opcode)
return false;
}

static int
loads_const(int opcode)
{
return OPCODE_HAS_CONST(opcode) || opcode == LOAD_SMALL_INT;
}

static PyObject*
get_const_value(int opcode, int oparg, PyObject *co_consts)
{
PyObject *constant = NULL;
assert(OPCODE_HAS_CONST(opcode));
assert(loads_const(opcode));
if (opcode == LOAD_CONST) {
constant = PyList_GET_ITEM(co_consts, oparg);
}
Expand Down Expand Up @@ -1332,7 +1338,7 @@ fold_tuple_on_constants(PyObject *const_cache,
assert(inst[n].i_oparg == n);

for (int i = 0; i < n; i++) {
if (!OPCODE_HAS_CONST(inst[i].i_opcode)) {
if (!loads_const(inst[i].i_opcode)) {
return SUCCESS;
}
}
Expand Down Expand Up @@ -2102,7 +2108,7 @@ remove_unused_consts(basicblock *entryblock, PyObject *consts)
for (basicblock *b = entryblock; b != NULL; b = b->b_next) {
for (int i = 0; i < b->b_iused; i++) {
int opcode = b->b_instr[i].i_opcode;
if (OPCODE_HAS_CONST(opcode) && opcode != LOAD_SMALL_INT) {
if (OPCODE_HAS_CONST(opcode)) {
int index = b->b_instr[i].i_oparg;
index_map[index] = index;
}
Expand Down Expand Up @@ -2156,7 +2162,7 @@ remove_unused_consts(basicblock *entryblock, PyObject *consts)
for (basicblock *b = entryblock; b != NULL; b = b->b_next) {
for (int i = 0; i < b->b_iused; i++) {
int opcode = b->b_instr[i].i_opcode;
if (OPCODE_HAS_CONST(opcode) && opcode != LOAD_SMALL_INT) {
if (OPCODE_HAS_CONST(opcode)) {
int index = b->b_instr[i].i_oparg;
assert(reverse_index_map[index] >= 0);
assert(reverse_index_map[index] < n_used_consts);
Expand Down
2 changes: 0 additions & 2 deletions Python/generated_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.


Back | FazBrowse Home | New Git URL