Skip to content
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

gh-107265: Fix code_hash for ENTER_EXECUTOR case #108188

Merged
merged 7 commits into from
Aug 21, 2023

Conversation

corona10
Copy link
Member

@corona10 corona10 commented Aug 21, 2023

@corona10
Copy link
Member Author

corona10 commented Aug 21, 2023

@gvanrossum cc @markshannon

I updated the code_richcompare not to modify the code object at all.

Copy link
Member

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

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

@markshannon Can you please confirm that this addresses your concern? (I'm sorry it slipped by me when I reviewed the previous PR.)

Objects/codeobject.c Outdated Show resolved Hide resolved
Objects/codeobject.c Outdated Show resolved Hide resolved
@markshannon
Copy link
Member

Would it better to ignore co_code_adaptive, and use co_code for comparisons?
It will definitely be slower, but it will be correct.

Ultimately we will want to compare by identity, I think.

@gvanrossum
Copy link
Member

Ultimately we will want to compare by identity, I think.

I'm no so sure, I expect that would cause too much breakage.

@gvanrossum
Copy link
Member

Would it better to ignore co_code_adaptive, and use co_code for comparisons?

Or factor out the normalization code involved in constructing co_code so it can be reused by compare and hash.

@gvanrossum
Copy link
Member

Would it better to ignore co_code_adaptive, and use co_code for comparisons?

Or factor out the normalization code involved in constructing co_code so it can be reused by compare and hash.

Never mind, that's already factored out (deopt_code()) but it modifies the bytecode array in place.

@markshannon
Copy link
Member

We keep changing the hash and equality functions, so I don't really see how another change will break anything, apart from assumptions in the compiler.

@corona10
Copy link
Member Author

corona10 commented Aug 21, 2023

Would it better to ignore co_code_adaptive, and use co_code for comparisons?
It will definitely be slower, but it will be correct.

IIUC, we need to update _PyCode_CODE for comparisons or add a new macro. It's worth experimenting with it.
I would like to do it in separate PR including the performance overhead comparison.

Copy link
Member

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

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

LGTM.

@gvanrossum
Copy link
Member

We keep changing the hash and equality functions, so I don't really see how another change will break anything, apart from assumptions in the compiler.

It seems pretty fundamental that co == co.replace(), which comparing by identity would break (and we rely in many places on .replace() always creating a new code object, with no specializations or executors, and all caches reset). IMO any field that can be changed through code.replace(xxx=yyy) should be included in equality, and no others. The hash should use a pragmatic subset of these that satisfies the required relationship between hash and equality and can be computed quickly.

@carljm
Copy link
Member

carljm commented Aug 21, 2023

In #101346 I tried to change code objects to compare by identity, and in the process I reached the same conclusion as @gvanrossum.

Making co != co.replace() (or, similarly, compile(source_string, ...) != compile(source_string, ...)) is a much bigger change than any tweaks to the details of code object comparison that have happened up until now.

@gvanrossum gvanrossum merged commit e6db23f into python:main Aug 21, 2023
17 checks passed
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.

5 participants