mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
GH-98686: Quicken everything (GH-98687)
This commit is contained in:
parent
18fc232e07
commit
276d77724f
21 changed files with 144 additions and 239 deletions
|
@ -114,9 +114,8 @@ class Printer:
|
|||
self.file = file
|
||||
self.cache: Dict[tuple[type, object, str], str] = {}
|
||||
self.hits, self.misses = 0, 0
|
||||
self.patchups: list[str] = []
|
||||
self.deallocs: list[str] = []
|
||||
self.interns: list[str] = []
|
||||
self.finis: list[str] = []
|
||||
self.inits: list[str] = []
|
||||
self.write('#include "Python.h"')
|
||||
self.write('#include "internal/pycore_gc.h"')
|
||||
self.write('#include "internal/pycore_code.h"')
|
||||
|
@ -257,7 +256,6 @@ class Printer:
|
|||
self.write(f".co_names = {co_names},")
|
||||
self.write(f".co_exceptiontable = {co_exceptiontable},")
|
||||
self.field(code, "co_flags")
|
||||
self.write(".co_warmup = QUICKENING_INITIAL_WARMUP_VALUE,")
|
||||
self.write("._co_linearray_entry_size = 0,")
|
||||
self.field(code, "co_argcount")
|
||||
self.field(code, "co_posonlyargcount")
|
||||
|
@ -284,8 +282,8 @@ class Printer:
|
|||
self.write(f"._co_firsttraceable = {i},")
|
||||
break
|
||||
name_as_code = f"(PyCodeObject *)&{name}"
|
||||
self.deallocs.append(f"_PyStaticCode_Dealloc({name_as_code});")
|
||||
self.interns.append(f"_PyStaticCode_InternStrings({name_as_code})")
|
||||
self.finis.append(f"_PyStaticCode_Fini({name_as_code});")
|
||||
self.inits.append(f"_PyStaticCode_Init({name_as_code})")
|
||||
return f"& {name}.ob_base.ob_base"
|
||||
|
||||
def generate_tuple(self, name: str, t: Tuple[object, ...]) -> str:
|
||||
|
@ -373,11 +371,7 @@ class Printer:
|
|||
def generate_file(self, module: str, code: object)-> None:
|
||||
module = module.replace(".", "_")
|
||||
self.generate(f"{module}_toplevel", code)
|
||||
with self.block(f"static void {module}_do_patchups(void)"):
|
||||
for p in self.patchups:
|
||||
self.write(p)
|
||||
self.patchups.clear()
|
||||
self.write(EPILOGUE.replace("%%NAME%%", module))
|
||||
self.write(EPILOGUE.format(name=module))
|
||||
|
||||
def generate(self, name: str, obj: object) -> str:
|
||||
# Use repr() in the key to distinguish -0.0 from +0.0
|
||||
|
@ -421,11 +415,10 @@ class Printer:
|
|||
|
||||
EPILOGUE = """
|
||||
PyObject *
|
||||
_Py_get_%%NAME%%_toplevel(void)
|
||||
{
|
||||
%%NAME%%_do_patchups();
|
||||
return Py_NewRef((PyObject *) &%%NAME%%_toplevel);
|
||||
}
|
||||
_Py_get_{name}_toplevel(void)
|
||||
{{
|
||||
return Py_NewRef((PyObject *) &{name}_toplevel);
|
||||
}}
|
||||
"""
|
||||
|
||||
FROZEN_COMMENT_C = "/* Auto-generated by Programs/_freeze_module.c */"
|
||||
|
@ -461,10 +454,10 @@ def generate(args: list[str], output: TextIO) -> None:
|
|||
code = compile(fd.read(), f"<frozen {modname}>", "exec")
|
||||
printer.generate_file(modname, code)
|
||||
with printer.block(f"void\n_Py_Deepfreeze_Fini(void)"):
|
||||
for p in printer.deallocs:
|
||||
for p in printer.finis:
|
||||
printer.write(p)
|
||||
with printer.block(f"int\n_Py_Deepfreeze_Init(void)"):
|
||||
for p in printer.interns:
|
||||
for p in printer.inits:
|
||||
with printer.block(f"if ({p} < 0)"):
|
||||
printer.write("return -1;")
|
||||
printer.write("return 0;")
|
||||
|
|
|
@ -477,7 +477,6 @@ Python/pyfpe.c - PyFPE_counter -
|
|||
Python/pylifecycle.c _Py_FatalErrorFormat reentrant -
|
||||
Python/pylifecycle.c - _Py_UnhandledKeyboardInterrupt -
|
||||
Python/pylifecycle.c fatal_error reentrant -
|
||||
Python/specialize.c - _Py_QuickenedCount -
|
||||
|
||||
|
||||
##################################
|
||||
|
|
Can't render this file because it has a wrong number of fields in line 4.
|
Loading…
Add table
Add a link
Reference in a new issue