FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-107265: Fix code_richcompare for ENTER_EXECUTOR case by corona10 · Pull Request #108165 · python/cpython · GitHub

/ cpython Public

gh-107265: Fix code_richcompare for ENTER_EXECUTOR case - #108165

Merged
corona10 merged 4 commits into
python:mainfrom
corona10:gh-107265
Aug 21, 2023
Merged

gh-107265: Fix code_richcompare for ENTER_EXECUTOR case#108165
corona10 merged 4 commits into
python:mainfrom
corona10:gh-107265

Conversation

corona10 commented Aug 20, 2023
edited
Loading

Copy link
Copy Markdown
Member

corona10 requested a review from gvanrossum August 20, 2023 11:09
corona10 requested a review from markshannon as a code owner August 20, 2023 11:09
corona10 changed the title gh-107265: Fix code_richcompare to lookup actual opcode when ENTER_EX… gh-107265: Fix code_richcompare for ENTER_EXECUTOR case Aug 20, 2023

gvanrossum left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LG, but could you add a test for this? You could add it to test_capi/test_misc.py in TestOptimizerAPI.

corona10 commented Aug 21, 2023
edited
Loading

Copy link
Copy Markdown
Member Author

LG, but could you add a test for this? You could add it to test_capi/test_misc.py in TestOptimizerAPI.

Thanks, I added the test, and if I understand the intention correctly.
co_instr.op.arg and cp_instr.op.arg should also be updated.
If not, comparing co_instr.cache == cp_instr.cache will be failed anyway.

Please let me know if I understand wrongly.

corona10 commented Aug 21, 2023
edited
Loading

Copy link
Copy Markdown
Member Author

pydoc test failure is unrelated to this PR, I checked it locally and asked to Discord too

gvanrossum left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Yes, the arg must also be restored, since it is overwritten (with the index of the executor to be used in this code object's array of executors). So it looks like writing the test was useful!

corona10 enabled auto-merge (squash) August 21, 2023 05:03
corona10 merged commit 4fdf3fd into python:main Aug 21, 2023
corona10 deleted the gh-107265 branch August 21, 2023 05:50
Comment thread Objects/codeobject.c
if (co_instr.op.code == ENTER_EXECUTOR) {
const int exec_index = co_instr.op.arg;
_PyExecutorObject *exec = co->co_executors->executors[exec_index];
co_instr.op.code = exec->vm_data.opcode;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Comparing two code objects must not modify the code object.

The interaction between executor, the specializer and instrumentation is subtle and likely to break without care.
This will leak executors, as it flip-flops between JUMP_BACKWARDS and ENTER_EXECUTOR, or worse if an optimizer assumes that a single instruction will only be seen once.

Comment thread Objects/codeobject.c
if (cp_instr.op.code == ENTER_EXECUTOR) {
const int exec_index = cp_instr.op.arg;
_PyExecutorObject *exec = cp->co_executors->executors[exec_index];
cp_instr.op.code = exec->vm_data.opcode;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Likewise

Copy link
Copy Markdown
Member

Please revert this. It will leak, and may not be safe.

Copy link
Copy Markdown
Member

#101346

Copy link
Copy Markdown
Member

@corona10 We can fix this in the hash PR you are working on.

Copy link
Copy Markdown
Member Author

@corona10 We can fix this in the hash PR you are working on.

Okay got it.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants


Back | FazBrowse Home | New Git URL