8000 gh-115685: Type/values propagate for TO_BOOL in tier 2 by Fidget-Spinner · Pull Request #115686 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-115685: Type/values propagate for TO_BOOL in tier 2 #115686

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 16 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Forgot sym_is_const
  • Loading branch information
Fidget-Spinner committed Feb 23, 2024
commit 7a480e870b7cb2db4f958aaf0d5a6dc8f67697d1
2 changes: 1 addition & 1 deletion Python/tier2_redundancy_eliminator_bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ dummy_func(void) {
}

op(_TO_BOOL_NONE, (value -- res)) {
if (sym_get_const(value) == Py_None) {
if (sym_is_const(value) && (sym_get_const(value) == Py_None)) {
Copy link
Member

Choose a reason for hiding this comment

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

Why is this necessary? Shouldn't sym_get_const return NULL for anything that isn't a constant?
It does seem rather verbose to have to prefix every sys_get_const with a sys_is_const.

Copy link
Member Author

Choose a reason for hiding this comment

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

In the code:

static inline PyObject *
sym_get_const(_Py_UOpsSymType *sym)
{
    assert(sym_is_const(sym));
    assert(sym->const_val);
    return sym->const_val;
}

So we assume there is always something there when there's sym_get_const. I think I can just change the contract to return NULL on non constants though.

Copy link
Member

Choose a reason for hiding this comment

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

The new sym_get_const() indeed returns NULL in this case.

REPLACE_OP(this_instr, _POP_TOP_LOAD_CONST_INLINE_BORROW, 0, (uintptr_t)Py_False);
}
sym_set_const(value, Py_None);
Expand Down
2 changes: 1 addition & 1 deletion Python/tier2_redundancy_eliminator_cases.c.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
_Py_UOpsSymType *value;
_Py_UOpsSymType *res;
value = stack_pointer[-1];
if (sym_get_const(value) == Py_None) {
if (sym_is_const(value) && (sym_get_const(value) == Py_None)) {
REPLACE_OP(this_instr, _POP_TOP_LOAD_CONST_INLINE_BORROW, 0, (uintptr_t)Py_False);
}
sym_set_const(value, Py_None);
Expand Down
0