-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
bpo-46841: Quicken code in-place #31888
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
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 a77a124
Clean things up a bit
brandtbucher 975b8d1
Bump the magic number
brandtbucher 40ddf39
co_bytecode -> _co_code
brandtbucher bfcba6d
Generate specialization table
brandtbucher 0376822
Clean things up a bit
brandtbucher 3e77b8d
Pack code objects more efficiently
brandtbucher 0a598a7
Fix typo
brandtbucher 2fda3b8
More cleanup
brandtbucher 42810dd
Try a different approach
brandtbucher 7df4934
Clean up the diff
brandtbucher 5fa0ca2
Support equality comparisons again
brandtbucher 1fc2282
Never un-quicken!
brandtbucher b40e300
More renaming and cleanup
brandtbucher af27670
Revert marshal format changes
brandtbucher 629bf8b
More cleanup
brandtbucher 59cda59
Clean up the diff
brandtbucher 73c33c1
Catch up with main
brandtbucher ecfb193
Miscellaneous cleanup
brandtbucher 824b2da
Remove outdated comment
brandtbucher 8164f41
Properly skip over EXTENDED_ARG instructions
brandtbucher 932a3f2
Make sure that f_lasti is always valid
brandtbucher c0c5498
Add some comments
brandtbucher f62a395
Catch up with main
brandtbucher e7464a3
Check opargs during size calculations
brandtbucher 4f51fdd
Add another TODO
brandtbucher 75bd375
Clean up formatting
brandtbucher d6d5128
Fix compiler warning
brandtbucher 82145c1
Simplify calculation of instr_prev
brandtbucher ca176ac
_Py_Quicken -> _PyCode_Quicken
brandtbucher 1e06bb5
Revert expensive f_lasti changes
brandtbucher e70819f
Naming is hard
brandtbucher 001eb53
Catch up with main
brandtbucher 6b96204
make patchcheck
brandtbucher 3087025
blurb add
brandtbucher 6f3bc38
Reuse the PyCodeObject definition for deepfreeze
brandtbucher c8054b9
Clean up TODO
brandtbucher File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Miscellaneous cleanup
- Loading branch information
commit ecfb193e11b6fb8408cc7ed132c2984aac8810b2
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,9 +105,9 @@ frame_getback(PyFrameObject *f, void *closure) | |
return res; | ||
} | ||
|
||
/* Given the index of the effective opcode, | ||
scan back to construct the oparg with EXTENDED_ARG */ | ||
// XXX This is broken! | ||
// Given the index of the effective opcode, scan back to construct the oparg | ||
// with EXTENDED_ARG. This only works correctly with *unquickened* code, | ||
// obtained via a call to _PyCode_GetCode! | ||
static unsigned int | ||
get_arg(const _Py_CODEUNIT *codestr, Py_ssize_t i) | ||
{ | ||
|
@@ -171,18 +171,17 @@ top_of_stack(int64_t stack) | |
static int64_t * | ||
mark_stacks(PyCodeObject *code_obj, int len) | ||
{ | ||
// XXX: this is one big TODO!!! | ||
PyObject *xxx = _PyCode_GetCode(code_obj); | ||
if (xxx == NULL) { | ||
PyObject *co_code = _PyCode_GetCode(code_obj); | ||
if (co_code == NULL) { | ||
return NULL; | ||
} | ||
_Py_CODEUNIT *code = (_Py_CODEUNIT *)PyBytes_AS_STRING(xxx); | ||
_Py_CODEUNIT *code = (_Py_CODEUNIT *)PyBytes_AS_STRING(co_code); | ||
int64_t *stacks = PyMem_New(int64_t, len+1); | ||
int i, j, opcode; | ||
|
||
if (stacks == NULL) { | ||
PyErr_NoMemory(); | ||
Py_DECREF(xxx); | ||
Py_DECREF(co_code); | ||
return NULL; | ||
} | ||
for (int i = 1; i <= len; i++) { | ||
|
@@ -310,7 +309,7 @@ mark_stacks(PyCodeObject *code_obj, int len) | |
} | ||
} | ||
} | ||
Py_DECREF(xxx); | ||
Py_DECREF(co_code); | ||
return stacks; | ||
} | ||
|
||
|
@@ -845,15 +844,23 @@ PyFrame_New(PyThreadState *tstate, PyCodeObject *code, | |
static int | ||
_PyFrame_OpAlreadyRan(_PyInterpreterFrame *frame, int opcode, int oparg) | ||
{ | ||
// XXX: Does this handle EXTENDED_ARGs/CACHEs? | ||
// This only works when opcode is a non-quickened form: | ||
assert(_PyOpcode_Deopt[opcode] == opcode); | ||
int check_oparg = 0; | ||
for (int i = 0; i < frame->f_lasti; i++) { | ||
_Py_CODEUNIT instruction = _PyCode_CODE(frame->f_code)[i]; | ||
int deopt = _PyOpcode_Deopt[_Py_OPCODE(instruction)]; | ||
instruction = _Py_MAKECODEUNIT(deopt, oparg); | ||
if (instruction == _Py_MAKECODEUNIT(opcode, oparg)) { | ||
int check_opcode = _PyOpcode_Deopt[_Py_OPCODE(instruction)]; | ||
check_oparg |= _Py_OPARG(instruction); | ||
if (check_opcode == opcode && check_oparg == oparg) { | ||
return 1; | ||
} | ||
i += _PyOpcode_Caches[deopt]; | ||
if (check_opcode == EXTENDED_ARG) { | ||
check_oparg <<= 8; | ||
} | ||
else { | ||
check_oparg = 0; | ||
} | ||
i += _PyOpcode_Caches[check_opcode]; | ||
} | ||
return 0; | ||
} | ||
|
@@ -872,7 +879,10 @@ _PyFrame_FastToLocalsWithError(_PyInterpreterFrame *frame) { | |
} | ||
co = frame->f_code; | ||
fast = _PyFrame_GetLocalsArray(frame); | ||
if (frame->f_lasti < 0 && _Py_OPCODE(_PyCode_CODE(co)[0]) == COPY_FREE_VARS) { | ||
// COPY_FREE_VARS has no quickened forms, so no need to use _PyOpcode_Deopt | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should (in theory) be able to assert |
||
// here: | ||
if (frame->f_lasti < 0 && _Py_OPCODE(_PyCode_CODE(co)[0]) == COPY_FREE_VARS) | ||
{ | ||
/* Free vars have not been initialized -- Do that */ | ||
PyCodeObject *co = frame->f_code; | ||
PyObject *closure = frame->f_func->func_closure; | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might be able to remove this entirely, as there should be no way to trace before the first
RESUME
.So don't worry too much if it appears a bit broken.