Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

gh-98831: Modernize the LOAD_GLOBAL family #101502

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 3 commits into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
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
Next Next commit
Modernize LOAD_GLOBAL
  • Loading branch information
gvanrossum committed Feb 1, 2023
commit 0f2129fd4a2c949ac8d658bb240607a9cdc7e356
28 changes: 11 additions & 17 deletions 28 Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1068,8 +1068,13 @@ dummy_func(
}
}

// error: LOAD_GLOBAL has irregular stack effect
inst(LOAD_GLOBAL) {
// family(load_global, INLINE_CACHE_ENTRIES_LOAD_GLOBAL) = {
// LOAD_GLOBAL,
// LOAD_GLOBAL_BUILTIN,
// LOAD_GLOBAL_MODULE,
// };

inst(LOAD_GLOBAL, (unused/1, unused/1, unused/2, unused/1 -- null if (oparg & 1), v)) {
#if ENABLE_SPECIALIZATION
_PyLoadGlobalCache *cache = (_PyLoadGlobalCache *)next_instr;
if (ADAPTIVE_COUNTER_IS_ZERO(cache->counter)) {
Expand All @@ -1082,10 +1087,7 @@ dummy_func(
STAT_INC(LOAD_GLOBAL, deferred);
DECREMENT_ADAPTIVE_COUNTER(cache->counter);
#endif /* ENABLE_SPECIALIZATION */
int push_null = oparg & 1;
PEEK(0) = NULL;
PyObject *name = GETITEM(names, oparg>>1);
PyObject *v;
if (PyDict_CheckExact(GLOBALS())
&& PyDict_CheckExact(BUILTINS()))
{
Expand All @@ -1099,7 +1101,7 @@ dummy_func(
format_exc_check_arg(tstate, PyExc_NameError,
NAME_ERROR_MSG, name);
}
goto error;
ERROR_IF(true, error);
}
Py_INCREF(v);
}
Expand All @@ -1109,9 +1111,7 @@ dummy_func(
/* namespace 1: globals */
v = PyObject_GetItem(GLOBALS(), name);
if (v == NULL) {
if (!_PyErr_ExceptionMatches(tstate, PyExc_KeyError)) {
goto error;
}
ERROR_IF(!_PyErr_ExceptionMatches(tstate, PyExc_KeyError), error);
_PyErr_Clear(tstate);

/* namespace 2: builtins */
Expand All @@ -1122,14 +1122,11 @@ dummy_func(
tstate, PyExc_NameError,
NAME_ERROR_MSG, name);
}
goto error;
ERROR_IF(true, error);
}
}
}
/* Skip over inline cache */
JUMPBY(INLINE_CACHE_ENTRIES_LOAD_GLOBAL);
STACK_GROW(push_null);
PUSH(v);
null = NULL;
}

// error: LOAD_GLOBAL has irregular stack effect
Expand Down Expand Up @@ -3227,9 +3224,6 @@ family(call, INLINE_CACHE_ENTRIES_CALL) = {
family(for_iter, INLINE_CACHE_ENTRIES_FOR_ITER) = {
FOR_ITER, FOR_ITER_LIST,
FOR_ITER_RANGE };
family(load_global, INLINE_CACHE_ENTRIES_LOAD_GLOBAL) = {
LOAD_GLOBAL, LOAD_GLOBAL_BUILTIN,
LOAD_GLOBAL_MODULE };
family(store_fast) = { STORE_FAST, STORE_FAST__LOAD_FAST, STORE_FAST__STORE_FAST };
family(unpack_sequence, INLINE_CACHE_ENTRIES_UNPACK_SEQUENCE) = {
UNPACK_SEQUENCE, UNPACK_SEQUENCE_LIST,
Expand Down
23 changes: 11 additions & 12 deletions 23 Python/generated_cases.c.h

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

8 changes: 4 additions & 4 deletions 8 Python/opcode_metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ _PyOpcode_num_popped(int opcode, int oparg) {
case LOAD_NAME:
return 0;
case LOAD_GLOBAL:
return -1;
return 0;
case LOAD_GLOBAL_MODULE:
return -1;
case LOAD_GLOBAL_BUILTIN:
Expand Down Expand Up @@ -487,7 +487,7 @@ _PyOpcode_num_pushed(int opcode, int oparg) {
case LOAD_NAME:
return 1;
case LOAD_GLOBAL:
return -1;
return ((oparg & 1) ? 1 : 0) + 1;
case LOAD_GLOBAL_MODULE:
return -1;
case LOAD_GLOBAL_BUILTIN:
Expand Down Expand Up @@ -694,7 +694,7 @@ _PyOpcode_num_pushed(int opcode, int oparg) {
}
#endif
enum Direction { DIR_NONE, DIR_READ, DIR_WRITE };
enum InstructionFormat { INSTR_FMT_IB, INSTR_FMT_IBC, INSTR_FMT_IBC0, INSTR_FMT_IBC000, INSTR_FMT_IBC00000000, INSTR_FMT_IBIB, INSTR_FMT_IX, INSTR_FMT_IXC, INSTR_FMT_IXC000 };
enum InstructionFormat { INSTR_FMT_IB, INSTR_FMT_IBC, INSTR_FMT_IBC0, INSTR_FMT_IBC000, INSTR_FMT_IBC0000, INSTR_FMT_IBC00000000, INSTR_FMT_IBIB, INSTR_FMT_IX, INSTR_FMT_IXC, INSTR_FMT_IXC000 };
struct opcode_metadata {
enum Direction dir_op1;
enum Direction dir_op2;
Expand Down Expand Up @@ -769,7 +769,7 @@ struct opcode_metadata {
[STORE_GLOBAL] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },
[DELETE_GLOBAL] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },
[LOAD_NAME] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },
[LOAD_GLOBAL] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },
[LOAD_GLOBAL] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IBC0000 },
[LOAD_GLOBAL_MODULE] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },
[LOAD_GLOBAL_BUILTIN] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },
[DELETE_FAST] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.