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
Naming is hard
  • Loading branch information
brandtbucher committed Mar 16, 2022
commit e70819f8caaa20cf4eed033b2ea4dd80a50ad384
4 changes: 2 additions & 2 deletions Include/cpython/code.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ struct PyCodeObject {
Type is a void* to keep the format private in codeobject.c to force
people to go through the proper APIs. */
void *co_extra;
char _co_code[1];
char co_code_adaptive[1];
};

/* Masks for co_flags above */
Expand Down Expand Up @@ -135,7 +135,7 @@ PyAPI_DATA(PyTypeObject) PyCode_Type;

#define PyCode_Check(op) Py_IS_TYPE(op, &PyCode_Type)
#define PyCode_GetNumFree(op) ((op)->co_nfreevars)
#define _PyCode_CODE(CO) ((_Py_CODEUNIT *)(CO)->_co_code)
#define _PyCode_CODE(CO) ((_Py_CODEUNIT *)(CO)->co_code_adaptive)
#define _PyCode_NBYTES(CO) (Py_SIZE(CO) * (Py_ssize_t)sizeof(_Py_CODEUNIT))

/* Public interface */
Expand Down
18 changes: 9 additions & 9 deletions Objects/codeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1521,9 +1521,9 @@ code_getfreevars(PyCodeObject *code, void *closure)
}

static PyObject *
code_getundercode(PyCodeObject *code, void *closure)
code_getcodeadaptive(PyCodeObject *code, void *closure)
{
return PyMemoryView_FromMemory(code->_co_code, _PyCode_NBYTES(code),
return PyMemoryView_FromMemory(code->co_code_adaptive, _PyCode_NBYTES(code),
PyBUF_READ);
}

Expand All @@ -1534,13 +1534,13 @@ code_getcode(PyCodeObject *code, void *closure)
}

static PyGetSetDef code_getsetlist[] = {
{"co_lnotab", (getter)code_getlnotab, NULL, NULL},
{"_co_code", (getter)code_getundercode, NULL, NULL},
{"co_lnotab", (getter)code_getlnotab, NULL, NULL},
{"_co_code_adaptive", (getter)code_getcodeadaptive, NULL, NULL},
// The following old names are kept for backward compatibility.
{"co_varnames", (getter)code_getvarnames, NULL, NULL},
{"co_cellvars", (getter)code_getcellvars, NULL, NULL},
{"co_freevars", (getter)code_getfreevars, NULL, NULL},
{"co_code", (getter)code_getcode, NULL, NULL},
{"co_varnames", (getter)code_getvarnames, NULL, NULL},
{"co_cellvars", (getter)code_getcellvars, NULL, NULL},
{"co_freevars", (getter)code_getfreevars, NULL, NULL},
{"co_code", (getter)code_getcode, NULL, NULL},
{0}
};

Expand Down Expand Up @@ -1729,7 +1729,7 @@ static struct PyMethodDef code_methods[] = {
PyTypeObject PyCode_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
"code",
offsetof(PyCodeObject, _co_code),
offsetof(PyCodeObject, co_code_adaptive),
sizeof(_Py_CODEUNIT),
(destructor)code_dealloc, /* tp_dealloc */
0, /* tp_vectorcall_offset */
Expand Down
11 changes: 6 additions & 5 deletions Tools/scripts/deepfreeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ def generate_code(self, name: str, code: types.CodeType) -> str:
# Derived values
nlocals, nplaincellvars, ncellvars, nfreevars = \
get_localsplus_counts(code, localsplusnames, localspluskinds)
co_code_adaptive = make_string_literal(code.co_code)
self.write("static")
with self.indent():
with self.block("struct"):
Expand Down Expand Up @@ -274,7 +275,7 @@ def generate_code(self, name: str, code: types.CodeType) -> str:
self.write("PyObject *co_columntable;")
self.write("PyObject *co_weakreflist;")
self.write("void *co_extra;")
self.write(f"char _co_code[{len(code.co_code)}];")
self.write(f"char co_code_adaptive[{len(code.co_code)}];")
with self.block(f"{name} =", ";"):
self.object_var_head("PyCode_Type", len(code.co_code) // 2)
# But the ordering here must match that in cpython/code.h
Expand Down Expand Up @@ -303,10 +304,10 @@ 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_code = {make_string_literal(code.co_code)},")
cast = f"(PyCodeObject *)&{name}"
self.deallocs.append(f"_PyStaticCode_Dealloc({cast});")
self.interns.append(f"_PyStaticCode_InternStrings({cast})")
self.write(f".co_code_adaptive = {co_code_adaptive},")
name_as_code = f"(PyCodeObject *)&{name}"
self.deallocs.append(f"_PyStaticCode_Dealloc({name_as_code});")
self.interns.append(f"_PyStaticCode_InternStrings({name_as_code})")
return f"& {name}.ob_base.ob_base"

def generate_tuple(self, name: str, t: Tuple[object, ...]) -> str:
Expand Down