10000 gh-120323: Remove class check for redundant _CHECK_ATTR_CLASS by Fidget-Spinner · Pull Request #121002 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-120323: Remove class check for redundant _CHECK_ATTR_CLASS #121002

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

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

Fidget-Spinner
Copy link
Member
@Fidget-Spinner Fidget-Spinner commented Jun 25, 2024

As requested, this I separated this PR out into just one with the type guard removal.

op(_CHECK_ATTR_CLASS, (type_version/2, owner -- owner)) {
assert(type_version);
if (sym_is_a_class(owner) &&
sym_matches_type_version(owner, type_version)) {
Copy link
Member

Choose a reason for hiding this comment

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

This is incorrect. sym_matches_type_version matches the type version of the symbol's class, not that of the symbol.

Copy link
Member

Choose a reason for hiding this comment

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

Please stop marking comments as resolved when they are not.
It wastes a lot of time forcing me double check all resolved issues, if I cannot trust that they are resolved.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry again, this was an old PR and was back when I more freely resolved things.

@bedevere-app
Copy link
bedevere-app bot commented Jun 25, 2024

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

Copy link
Member
@markshannon markshannon left a comment

Choose a reason for hiding this comment

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

This still needs tests.

It seems like you aren't making the distinction between the version of the symbol's class, and the version of a symbol that is a class.
This distinction is a subset of the more general distinction between a symbol representing a value (or finite set of values) and a symbol representing an instance of a class.

@@ -117,6 +117,12 @@ dummy_func(void) {

op(_GUARD_TYPE_VERSION, (type_version/2, owner -- owner)) {
assert(type_version);
// This is a contradiction.
Copy link
Member

Choose a reason for hiding this comment

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

This isn't necessarily a contradiction. Py_TYPE(owner)->tp_version == type_version can be true even if owner is a class.

I suspect we don't check the version number of metaclasses anywhere now, but it is definitely possible for enums.

sym_matches_type_version should check for the contradiction, so this check shouldn't be necessary.

op(_CHECK_ATTR_CLASS, (type_version/2, owner -- owner)) {
assert(type_version);
if (sym_is_a_class(owner) &&
sym_matches_type_version(owner, type_version)) {
Copy link
Member

Choose a reason for hiding this comment

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

Please stop marking comments as resolved when they are not.
It wastes a lot of time forcing me double check all resolved issues, if I cannot trust that they are resolved.

@@ -207,6 +216,15 @@ _Py_uop_sym_set_non_null(_Py_UOpsContext *ctx, _Py_UopsSymbol *sym)
sym_set_flag(sym, NOT_NULL);
}

void
_Py_uop_sym_set_is_a_class(_Py_UOpsContext *ctx, _Py_UopsSymbol *sym, unsigned int type_version)
Copy link
Member

Choose a reason for hiding this comment

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

This needs a better name. The is in the middle reads strangely.
Maybe just _Py_uop_sym_set_class?

@@ -121,6 +124,12 @@ _Py_uop_sym_is_null(_Py_UopsSymbol *sym)
return sym->flags == IS_NULL;
}

bool
_Py_uop_sym_is_a_class(_Py_UopsSymbol *sym, unsigned int type_version)
Copy link
Member

Choose a reason for hiding this comment

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

These need tests.
Specifically tests setting the symbol to be a class, and then setting its class's version.

@markshannon
Copy link
Member

@Fidget-Spinner do plan to continue working on this?

@Fidget-Spinner
Copy link
Member Author

Not in the immediate term. If anyone else wants to work on this they are free to pick it up. Else I will reliok before 3.14 beta.

@tengyangzh
Copy link

Not in the immediate term. If anyone else wants to work on this they are free to pick it up. Else I will reliok before 3.14 beta.

When is the release date for version 3.14 beta? This job looks really interesting, and if I have time, I think I can give it a try.

@Fidget-Spinner
Copy link
Member Author

May 2025. Feel free to take over the PR.

@python-cla-bot
Copy link
python-cla-bot bot commented Apr 18, 2025

All commit authors signed the Contributor License Agreement.

CLA signed

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.

3 participants
0