gh-131798: Add _IS_NONE to the JIT optimizer#148369
Open
Wulian233 wants to merge 2 commits intopython:mainfrom
Open
gh-131798: Add _IS_NONE to the JIT optimizer#148369Wulian233 wants to merge 2 commits intopython:mainfrom
_IS_NONE to the JIT optimizer#148369Wulian233 wants to merge 2 commits intopython:mainfrom
Conversation
Member
Fidget-Spinner
left a comment
There was a problem hiding this comment.
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)) { |
Member
There was a problem hiding this comment.
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); | ||
| } | ||
| } |
Member
There was a problem hiding this comment.
You can replace this whole chunk with
b = sym_new_type(ctx, &PyBool_Type);
REPLACE_OPCODE_IF_EVALUATES_PURE(value, b);
Contributor
Author
There was a problem hiding this comment.
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
Lines 3511 to 3520 in 72006a7
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
Member
There was a problem hiding this comment.
Are you sure you're in the right file? You should be editing optimizer_bytecodes.c not bytecodes.c
Contributor
Author
Misc/NEWS.d/next/Core_and_Builtins/2026-04-11-16-12-17.gh-issue-131798.be8mTq.rst
Show resolved
Hide resolved
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

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