Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
6ca0d42
Move bytecode into the code object
brandtbucher Mar 10, 2022
a77a124
Clean things up a bit
brandtbucher Mar 10, 2022
975b8d1
Bump the magic number
brandtbucher Mar 10, 2022
40ddf39
co_bytecode -> _co_code
brandtbucher Mar 10, 2022
bfcba6d
Generate specialization table
brandtbucher Mar 10, 2022
0376822
Clean things up a bit
brandtbucher Mar 10, 2022
3e77b8d
Pack code objects more efficiently
brandtbucher Mar 10, 2022
0a598a7
Fix typo
brandtbucher Mar 10, 2022
2fda3b8
More cleanup
brandtbucher Mar 11, 2022
42810dd
Try a different approach
brandtbucher Mar 11, 2022
7df4934
Clean up the diff
brandtbucher Mar 11, 2022
5fa0ca2
Support equality comparisons again
brandtbucher Mar 11, 2022
1fc2282
Never un-quicken!
brandtbucher Mar 11, 2022
b40e300
More renaming and cleanup
brandtbucher Mar 11, 2022
af27670
Revert marshal format changes
brandtbucher Mar 11, 2022
629bf8b
More cleanup
brandtbucher Mar 11, 2022
59cda59
Clean up the diff
brandtbucher Mar 11, 2022
73c33c1
Catch up with main
brandtbucher Mar 12, 2022
ecfb193
Miscellaneous cleanup
brandtbucher Mar 14, 2022
824b2da
Remove outdated comment
brandtbucher Mar 14, 2022
8164f41
Properly skip over EXTENDED_ARG instructions
brandtbucher Mar 14, 2022
932a3f2
Make sure that f_lasti is always valid
brandtbucher Mar 14, 2022
c0c5498
Add some comments
brandtbucher Mar 14, 2022
f62a395
Catch up with main
brandtbucher Mar 14, 2022
e7464a3
Check opargs during size calculations
brandtbucher Mar 14, 2022
4f51fdd
Add another TODO
brandtbucher Mar 14, 2022
75bd375
Clean up formatting
brandtbucher Mar 15, 2022
d6d5128
Fix compiler warning
brandtbucher Mar 15, 2022
82145c1
Simplify calculation of instr_prev
brandtbucher Mar 15, 2022
ca176ac
_Py_Quicken -> _PyCode_Quicken
brandtbucher Mar 15, 2022
1e06bb5
Revert expensive f_lasti changes
brandtbucher Mar 15, 2022
e70819f
Naming is hard
brandtbucher Mar 16, 2022
001eb53
Catch up with main
brandtbucher Mar 16, 2022
6b96204
make patchcheck
brandtbucher Mar 16, 2022
3087025
blurb add
brandtbucher Mar 16, 2022
6f3bc38
Reuse the PyCodeObject definition for deepfreeze
brandtbucher Mar 16, 2022
c8054b9
Clean up TODO
brandtbucher Mar 18, 2022
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
Pack code objects more efficiently
  • Loading branch information
brandtbucher committed Mar 10, 2022
commit 3e77b8d969693e3c30f915210c2a688a464f7f0d
17 changes: 8 additions & 9 deletions Include/cpython/code.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ struct PyCodeObject {
int co_kwonlyargcount; /* #keyword only arguments */
int co_stacksize; /* #entries needed for evaluation stack */
int co_firstlineno; /* first source line number */

// 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_nplaincellvars; /* number of non-arg cell variables */
int co_ncellvars; /* total number of cell variables */
int co_nfreevars; /* number of free variables */

PyObject *co_localsplusnames; /* tuple mapping offsets to names */
PyObject *co_localspluskinds; /* Bytes mapping to local kinds (one byte per variable) */
PyObject *co_filename; /* unicode (where it was loaded from) */
Expand All @@ -76,15 +84,6 @@ struct PyCodeObject {
PyObject *co_columntable; /* bytes object that holds start/end column
offset each instruction */

/* These fields are set with computed values on new code objects. */

// 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_nplaincellvars; /* number of non-arg cell variables */
int co_ncellvars; /* total number of cell variables */
int co_nfreevars; /* number of free variables */

/* The remaining fields are zeroed out on new code objects. */

PyObject *co_weakreflist; /* to support weakrefs to code objects */
Expand Down
20 changes: 10 additions & 10 deletions Tools/scripts/deepfreeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,11 @@ def generate_code(self, name: str, code: types.CodeType) -> str:
self.write("int co_kwonlyargcount;")
self.write("int co_stacksize;")
self.write("int co_firstlineno;")
self.write("int co_nlocalsplus;")
self.write("int co_nlocals;")
self.write("int co_nplaincellvars;")
self.write("int co_ncellvars;")
self.write("int co_nfreevars;")
self.write("PyObject *co_localsplusnames;")
self.write("PyObject *co_localspluskinds;")
self.write("PyObject *co_filename;")
Expand All @@ -267,11 +272,6 @@ def generate_code(self, name: str, code: types.CodeType) -> str:
self.write("PyObject *co_linetable;")
self.write("PyObject *co_endlinetable;")
self.write("PyObject *co_columntable;")
self.write("int co_nlocalsplus;")
self.write("int co_nlocals;")
self.write("int co_nplaincellvars;")
self.write("int co_ncellvars;")
self.write("int co_nfreevars;")
self.write("PyObject *co_weakreflist;")
self.write("void *co_extra;")
self.write(f"char _co_code[{len(code.co_code)}];")
Expand All @@ -290,6 +290,11 @@ def generate_code(self, name: str, code: types.CodeType) -> str:
self.field(code, "co_kwonlyargcount")
self.field(code, "co_stacksize")
self.field(code, "co_firstlineno")
self.write(f".co_nlocalsplus = {len(localsplusnames)},")
self.field(code, "co_nlocals")
self.write(f".co_nplaincellvars = {nplaincellvars},")
self.write(f".co_ncellvars = {ncellvars},")
self.write(f".co_nfreevars = {nfreevars},")
self.write(f".co_localsplusnames = {co_localsplusnames},")
self.write(f".co_localspluskinds = {co_localspluskinds},")
self.write(f".co_filename = {co_filename},")
Expand All @@ -298,11 +303,6 @@ def generate_code(self, name: str, code: types.CodeType) -> str:
self.write(f".co_linetable = {co_linetable},")
self.write(f".co_endlinetable = {co_endlinetable},")
self.write(f".co_columntable = {co_columntable},")
self.write(f".co_nlocalsplus = {len(localsplusnames)},")
self.field(code, "co_nlocals")
self.write(f".co_nplaincellvars = {nplaincellvars},")
self.write(f".co_ncellvars = {ncellvars},")
self.write(f".co_nfreevars = {nfreevars},")
self.write(f"._co_code = {make_string_literal(code.co_code)},")
self.deallocs.append(f"_PyStaticCode_Dealloc(&{name});")
self.interns.append(f"_PyStaticCode_InternStrings(&{name})")
Expand Down