Skip to content

gh-131798: Add _IS_NONE to the JIT optimizer#148369

Merged
Fidget-Spinner merged 3 commits intopython:mainfrom
Wulian233:_IS_NONE
Apr 11, 2026
Merged

gh-131798: Add _IS_NONE to the JIT optimizer#148369
Fidget-Spinner merged 3 commits intopython:mainfrom
Wulian233:_IS_NONE

Conversation

@Wulian233
Copy link
Copy Markdown
Contributor

@Wulian233 Wulian233 commented Apr 11, 2026

Hello! This is my first time submitting something to JIT. I'm still learning, so there may be some mistakes. Welcome corrections!

Copy link
Copy Markdown
Member

@Fidget-Spinner Fidget-Spinner left a comment

Choose a reason for hiding this comment

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

Thanks for contributing to the JIT, and welcome!

Comment on lines +714 to +725
if (sym_is_const(ctx, value)) {
PyObject *value_o = sym_get_const(ctx, value);
assert(value_o != NULL);
b = sym_new_const(ctx, Py_IsNone(value_o) ? Py_True : Py_False);
}
else if (sym_has_type(value)) {
b = sym_new_const(ctx, sym_matches_type(value, &_PyNone_Type) ? Py_True : Py_False);
}
else {
b = sym_new_type(ctx, &PyBool_Type);
}
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You can replace this whole chunk with

        b = sym_new_type(ctx, &PyBool_Type);
        REPLACE_OPCODE_IF_EVALUATES_PURE(value, b);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank you! Currently, I have the following code in my local environment:

    op(_IS_NONE, (value -- b)) {
        b = sym_new_type(ctx, &PyBool_Type);
        REPLACE_OPCODE_IF_EVALUATES_PURE(value, b);
    }

However, when running optimizer_generator.py, it throws the following error:

File "E:/cpython/Python/bytecodes.c", line 3519

                ^
SyntaxError: 'value' is cleared on some paths, but not all

next step, should I replace

cpython/Python/bytecodes.c

Lines 3511 to 3520 in 72006a7

op(_IS_NONE, (value -- b)) {
if (PyStackRef_IsNone(value)) {
b = PyStackRef_True;
DEAD(value);
}
else {
b = PyStackRef_False;
DECREF_INPUTS();
}
}

with the following?

        op(_IS_NONE, (value -- b)) {
            b = PyStackRef_IsNone(value) ? PyStackRef_True : PyStackRef_False;
            DECREF_INPUTS();
        }

I apologize if this is a basic question

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Are you sure you're in the right file? You should be editing optimizer_bytecodes.c not bytecodes.c

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yeah, looks this😥
image

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That's probably a bug in the cases generator then. Let's just use your current approach for now but fixed.

Copy link
Copy Markdown
Member

@Fidget-Spinner Fidget-Spinner left a comment

Choose a reason for hiding this comment

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

Thanks!

@Fidget-Spinner Fidget-Spinner merged commit a059e85 into python:main Apr 11, 2026
115 of 116 checks passed
@Wulian233 Wulian233 deleted the _IS_NONE branch April 11, 2026 15:11
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