8000 gh-132732: Fix up pure types in JIT by Fidget-Spinner · Pull Request #136050 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-132732: Fix up pure types in JIT #136050

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 1 commit into
base: main
Choose a base branch
from

Conversation

Fidget-Spinner
Copy link
Member
@Fidget-Spinner Fidget-Spinner commented Jun 27, 2025

@brandtbucher
Copy link
Member
brandtbucher commented Jun 27, 2025

How do you feel about recursively checking the tuple's elements for safety? Something like:

if (typ == &PyTuple_Type) {
    Py_ssize_t length = _Py_uop_sym_tuple_length(sym);
    if (length < 0) {
        return false;
    }
    for (Py_ssize_t i = 0; i < length; i++) {
        if (!_Py_uop_sym_is_safe_const(ctx, sym)) {
            return false;
        }
    }
    return true;
}

Potential downside is that in theory, the tuples could be huge. We could set an upper bound of a maximum of a few elements or something, though (but that gets tricky with the recursion, which could be arbitrarily deep too).

@Fidget-Spinner
Copy link
Member Author

The tuples in the optimizer are limited to a size of 6, though that could recursively go on for a long time...

I think it's not worth thinking over. I don't think it's a common thing to use tuples in a "constant" way to do operations on. If they are, they would use lists instead. Unless of course they want to program in an immutable fashion.

@brandtbucher
Copy link
Member

Constant tuples can be arbitrary size. This constant evaluation doesn’t operate on abstract tuples. But your point stands, probably better to ignore them for now.

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
0