Skip to content

gh-143732: Add tier2 specialization for TO_BOOL#148271

Open
eendebakpt wants to merge 4 commits intopython:mainfrom
eendebakpt:to_bool_specialization
Open

gh-143732: Add tier2 specialization for TO_BOOL#148271
eendebakpt wants to merge 4 commits intopython:mainfrom
eendebakpt:to_bool_specialization

Conversation

@eendebakpt
Copy link
Copy Markdown
Contributor

@eendebakpt eendebakpt commented Apr 8, 2026

See discussion at #148113.

This PR adds two tier2 opcodes for specialization of TO_BOOL. The *args and **kwargs` arguments are marked in tier2 as tuple and dict, respectively.

In this PR there is no additional type recording or tier1 opcodes, that is left to followup PRs.

@eendebakpt eendebakpt marked this pull request as ready for review April 8, 2026 22:21
Comment on lines +541 to +550
if (sym_matches_type(value, &PyDict_Type)) {
REPLACE_OP(this_instr, _TO_BOOL_DICT, 0, 0);
}
else if (sym_matches_type(value, &PyTuple_Type) ||
sym_matches_type(value, &PySet_Type) ||
sym_matches_type(value, &PyFrozenSet_Type) ||
sym_matches_type(value, &PyBytes_Type) ||
sym_matches_type(value, &PyByteArray_Type)) {
REPLACE_OP(this_instr, _TO_BOOL_SIZED, 0, 0);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Would this be better?

PyTypeObject *tp = sym_get_type(value);
if (tp == &PyTuple_Type || tp == ...)

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.

2 participants