8000 bpo-43693: Add new internal code objects fields: co_fastlocalnames and co_fastlocalkinds. by ericsnowcurrently · Pull Request #26388 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-43693: Add new internal code objects fields: co_fastlocalnames and co_fastlocalkinds. #26388

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 31 commits into from
Jun 3, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
a5edf53
Add co_fastlocalnames and co_fastlocalkinds.
ericsnowcurrently May 20, 2021
3cf1539
Populate the fast locals info first.
ericsnowcurrently May 26, 2021
3f11732
Allow co_varnames and friends to be NULL.
ericsnowcurrently May 21, 2021
a492565
Update the import magic number.
ericsnowcurrently May 21, 2021
0ff263e
Regen a couple more files.
ericsnowcurrently May 22, 2021
90f4e8a
Add a NEWS entry.
ericsnowcurrently May 22, 2021
ee10bb3
Fix the arg-is-cell case.
ericsnowcurrently May 24, 2021
861f90c
Use int for counts instead of Py_ssize_t.
ericsnowcurrently May 25, 2021
4d97056
Switch co_fastlocalkinds to a variable length array.
ericsnowcurrently May 25, 2021
f67e7eb
Fix a "smelly" symbol.
ericsnowcurrently May 26, 2021
c5d0ad2
Fix PyFrame_FastToLocals() and PyFrame_LocalsToFast().
ericsnowcurrently May 26, 2021
b9a975c
Fix a typo.
ericsnowcurrently May 26, 2021
3b01a5f
Regen other files.
ericsnowcurrently May 26, 2021
19465f4
Fix the gdb script.
ericsnowcurrently May 26, 2021
93c3568
lint
ericsnowcurrently May 26, 2021
418da97
Expose co_fastlocalnames to Python code.
ericsnowcurrently May 27, 2021
9de74bd
Update the dis docs.
ericsnowcurrently May 27, 2021
e50e286
Use co_fastlocalnames in the dis module.
ericsnowcurrently May 27, 2021
f0fda39
Fix some comments.
ericsnowcurrently May 27, 2021
361ca0a
Drop "inline" from some big functions.
ericsnowcurrently May 27, 2021
bbdaada
Clarify that we only look through the free vars in super_init_without…
ericsnowcurrently May 27, 2021
8c100d9
Clarify about the case where a "fast" arg is also a cell.
ericsnowcurrently May 27, 2021
505536e
Use a private getter function for co_fastlocalnames instead of a prop…
ericsnowcurrently May 27, 2021
885e435
Drop the arg-related flags.
ericsnowcurrently Jun 2, 2021
29e1c2a
Leave the bottom numbers for locals kinds.
ericsnowcurrently Jun 2, 2021
235e4aa
"fastlocal" -> "localsplus"
ericsnowcurrently Jun 2, 2021
13fe60d
Add a note about "locals plus" and variable kinds.
ericsnowcurrently Jun 2, 2021
fba56f5
co._get_localsplusnames() -> co._varname_from_oparg()
ericsnowcurrently Jun 2, 2021
68c7776
Fix the gdb hooks.
ericsnowcurrently Jun 2, 2021
e10e7da
Be more strict about types.
ericsnowcurrently Jun 3, 2021
87cb192
Add a TODO about "_PyCodeConstructor.argcount".
ericsnowcurrently Jun 3, 2021
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
"fastlocal" -> "localsplus"
  • Loading branch information
ericsnowcurrently committed Jun 3, 2021
commit 235e4aa3f9a9dd0978edbea1eb1ce61f3b59a266
10 changes: 5 additions & 5 deletions Include/cpython/code.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ typedef struct _PyOpcache _PyOpcache;


// These are duplicated from pycore_code.h.
typedef unsigned char _PyFastLocalKind;
typedef _PyFastLocalKind *_PyFastLocalKinds;
typedef unsigned char _PyLocalsPlusKind;
typedef _PyLocalsPlusKind *_PyLocalsPlusKinds;

/* Bytecode object */
struct PyCodeObject {
Expand Down Expand Up @@ -60,8 +60,8 @@ struct PyCodeObject {
int co_kwonlyargcount; /* #keyword only arguments */
int co_stacksize; /* #entries needed for evaluation stack */
int co_firstlineno; /* first source line number */
PyObject *co_fastlocalnames; /* tuple mapping fastlocalsplus to names */
_PyFastLocalKinds co_fastlocalkinds; /* array mapping to local kinds */
PyObject *co_localsplusnames; /* tuple mapping offsets to names */
_PyLocalsPlusKinds co_localspluskinds; /* array mapping to local kinds */
PyObject *co_filename; /* unicode (where it was loaded from) */
PyObject *co_name; /* unicode (name, for reference) */
PyObject *co_linetable; /* string (encoding addr<->lineno mapping) See
Expand All @@ -71,7 +71,7 @@ struct PyCodeObject {
/* These fields are set with computed values on new code objects. */

int *co_cell2arg; /* Maps cell vars which are arguments. */
// redundant values (derived from co_fastlocalnames and co_fastlocalkinds)
// redundant values (derived from co_localsplusnames and co_localspluskinds)
int co_nlocalsplus; /* number of local + cell + free variables */
int co_nlocals; /* number of local variables */
int co_ncellvars; /* number of cell variables */
Expand Down
16 changes: 8 additions & 8 deletions Include/internal/pycore_code.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,24 @@ struct _PyOpcache {


// We would use an enum if C let us specify the storage type.
typedef unsigned char _PyFastLocalKind;
/* Note that these all fit within _PyFastLocalKind, as do combinations. */
typedef unsigned char _PyLocalsPlusKind;
/* Note that these all fit within _PyLocalsPlusKind, as do combinations. */
// Later, we will use the smaller numbers to differentiate the different
// kinds of locals (e.g. pos-only arg, varkwargs, local-only).
#define CO_FAST_LOCAL 0x20
#define CO_FAST_CELL 0x40
#define CO_FAST_FREE 0x80

typedef _PyFastLocalKind *_PyFastLocalKinds;
typedef _PyLocalsPlusKind *_PyLocalsPlusKinds;

static inline int
_PyCode_InitFastLocalKinds(int num, _PyFastLocalKinds *pkinds)
_PyCode_InitLocalsPlusKinds(int num, _PyLocalsPlusKinds *pkinds)
{
if (num == 0) {
*pkinds = NULL;
return 0;
}
_PyFastLocalKinds kinds = PyMem_NEW(_PyFastLocalKind, num);
_PyLocalsPlusKinds kinds = PyMem_NEW(_PyLocalsPlusKind, num);
if (kinds == NULL) {
PyErr_NoMemory();
return -1;
Expand All @@ -54,7 +54,7 @@ _PyCode_InitFastLocalKinds(int num, _PyFastLocalKinds *pkinds)
}

static inline void
_PyCode_ClearFastLocalKinds(_PyFastLocalKinds kinds)
_PyCode_ClearLocalsPlusKinds(_PyLocalsPlusKinds kinds)
{
if (kinds != NULL) {
PyMem_Free(kinds);
Expand All @@ -77,8 +77,8 @@ struct _PyCodeConstructor {
PyObject *names;

/* mapping frame offsets to information */
PyObject *fastlocalnames;
_PyFastLocalKinds fastlocalkinds;
PyObject *localsplusnames;
_PyLocalsPlusKinds localspluskinds;

/* args (within varnames) */
int argcount;
Expand Down
18 changes: 9 additions & 9 deletions Lib/dis.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def get_instructions(x, *, first_line=None):
else:
line_offset = 0
return _get_instructions_bytes(co.co_code,
co._get_fastlocalnames(), co.co_nlocals,
co._get_localsplusnames(), co.co_nlocals,
co.co_names, co.co_consts,
linestarts, line_offset)

Expand Down Expand Up @@ -336,7 +336,7 @@ def parse_exception_table(code):
except StopIteration:
return entries

def _get_instructions_bytes(code, fastlocalnames=None, nlocals=0,
def _get_instructions_bytes(code, localsplusnames=None, nlocals=0,
names=None, constants=None,
linestarts=None, line_offset=0,
exception_entries=()):
Expand Down Expand Up @@ -378,12 +378,12 @@ def _get_instructions_bytes(code, fastlocalnames=None, nlocals=0,
argval = offset + 2 + arg*2
argrepr = "to " + repr(argval)
elif op in haslocal:
argval, argrepr = _get_name_info(arg, fastlocalnames)
argval, argrepr = _get_name_info(arg, localsplusnames)
elif op in hascompare:
argval = cmp_op[arg]
argrepr = argval
elif op in hasfree:
argval, argrepr = _get_name_info(arg + nlocals, fastlocalnames)
argval, argrepr = _get_name_info(arg + nlocals, localsplusnames)
elif op == FORMAT_VALUE:
argval, argrepr = FORMAT_VALUE_CONVERTERS[arg & 0x3]
argval = (argval, bool(arg & 0x4))
Expand All @@ -403,7 +403,7 @@ def disassemble(co, lasti=-1, *, file=None):
linestarts = dict(findlinestarts(co))
exception_entries = parse_exception_table(co)
6D40 _disassemble_bytes(co.co_code, lasti,
co._get_fastlocalnames(), co.co_nlocals,
co._get_localsplusnames(), co.co_nlocals,
co.co_names, co.co_consts, linestarts, file=file,
exception_entries=exception_entries)

Expand All @@ -418,7 +418,7 @@ def _disassemble_recursive(co, *, file=None, depth=None):
print("Disassembly of %r:" % (x,), file=file)
_disassemble_recursive(x, file=file, depth=depth)

def _disassemble_bytes(code, lasti=-1, fastlocalnames=None, nlocals=0,
def _disassemble_bytes(code, lasti=-1, localsplusnames=None, nlocals=0,
names=None, constants=None, linestarts=None,
*, file=None, line_offset=0, exception_entries=()):
# Omit the line number column entirely if we have no line number info
Expand All @@ -436,7 +436,7 @@ def _disassemble_bytes(code, lasti=-1, fastlocalnames=None, nlocals=0,
offset_width = len(str(maxoffset))
else:
offset_width = 4
for instr in _get_instructions_bytes(code, fastlocalnames, nlocals, names,
for instr in _get_instructions_bytes(code, localsplusnames, nlocals, names,
constants, linestarts,
line_offset=line_offset, exception_entries=exception_entries):
new_source_line = (show_lineno and
Expand Down Expand Up @@ -527,7 +527,7 @@ def __init__(self, x, *, first_line=None, current_offset=None):
def __iter__(self):
co = self.codeobj
return _get_instructions_bytes(co.co_code,
co._get_fastlocalnames(), co.co_nlocals,
co._get_localsplusnames(), co.co_nlocals,
co.co_names, co.co_consts,
self._linestarts,
line_offset=self._line_offset,
Expand Down Expand Up @@ -557,7 +557,7 @@ def dis(self):
offset = -1
with io.StringIO() as output:
_disassemble_bytes(co.co_code,
fastlocalnames=co._get_fastlocalnames(),
localsplusnames=co._get_localsplusnames(),
nlocals=co.co_nlocals,
names=co.co_names, constants=co.co_consts,
linestarts=self._linestarts,
Expand Down
16 changes: 8 additions & 8 deletions Objects/clinic/codeobject.c.h

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

Loading
0