diff options
author | Eric Snow <ericsnowcurrently@gmail.com> | 2021-06-15 22:35:25 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-15 22:35:25 (GMT) |
commit | ac38a9f2dfbba95f5d4338eb11a0221d38ef9328 (patch) | |
tree | cbe976854afe2fc55df27e5134abc9cdc727c601 /Include/cpython/code.h | |
parent | 1d10bf0bb9409a406c56b0de8870df998637fd0f (diff) | |
download | cpython-ac38a9f2dfbba95f5d4338eb11a0221d38ef9328.zip cpython-ac38a9f2dfbba95f5d4338eb11a0221d38ef9328.tar.gz cpython-ac38a9f2dfbba95f5d4338eb11a0221d38ef9328.tar.bz2 |
bpo-43693: Eliminate unused "fast locals". (gh-26587)
Currently, if an arg value escapes (into the closure for an inner function) we end up allocating two indices in the fast locals even though only one gets used. Additionally, using the lower index would be better in some cases, such as with no-arg `super()`. To address this, we update the compiler to fix the offsets so each variable only gets one "fast local". As a consequence, now some cell offsets are interspersed with the locals (only when an arg escapes to an inner function).
https://bugs.python.org/issue43693
Diffstat (limited to 'Include/cpython/code.h')
-rw-r--r-- | Include/cpython/code.h | 8 |
1 files changed, 2 insertions, 6 deletions
diff --git a/Include/cpython/code.h b/Include/cpython/code.h index df79ddb..5bf4c8c 100644 --- a/Include/cpython/code.h +++ b/Include/cpython/code.h @@ -83,11 +83,11 @@ 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_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 */ + int co_nplaincellvars; /* number of non-arg cell variables */ + int co_ncellvars; /* total number of cell variables */ int co_nfreevars; /* number of free variables */ // lazily-computed values PyObject *co_varnames; /* tuple of strings (local variable names) */ @@ -142,10 +142,6 @@ struct PyCodeObject { #define CO_FUTURE_GENERATOR_STOP 0x800000 #define CO_FUTURE_ANNOTATIONS 0x1000000 -/* This value is found in the co_cell2arg array when the associated cell - variable does not correspond to an argument. */ -#define CO_CELL_NOT_AN_ARG (-1) - /* This should be defined if a future statement modifies the syntax. For example, when a keyword is added. */ |