Skip to content

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

Open
Wulian233 wants to merge 2 commits intopython:mainfrom
Wulian233:_IS_NONE
Open

gh-131798: Add _IS_NONE to the JIT optimizer#148369
Wulian233 wants to merge 2 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!

assert(value_o != NULL);
b = sym_new_const(ctx, Py_IsNone(value_o) ? Py_True : Py_False);
}
else if (sym_has_type(value)) {
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.

This isn't right I think. It checks for exact match, not type.

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

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