Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-144681: Fix JIT trace builder assertion failure when conditional branch jump target coincides with fallthrough target#144742

Open
cocolato wants to merge 6 commits intopython:mainfrom
cocolato:fix-gh-144681
Open

gh-144681: Fix JIT trace builder assertion failure when conditional branch jump target coincides with fallthrough target#144742
cocolato wants to merge 6 commits intopython:mainfrom
cocolato:fix-gh-144681

Conversation

@cocolato
Copy link
Contributor

@cocolatococolato commentedFeb 12, 2026
edited by bedevere-appbot
Loading

When the JIT trace builder translatesPOP_JUMP_IF_TRUE instructions, it determines the branch direction by comparingnext_instr (where execution actually went) againstcomputed_jump_instr (the jump target address). However, when oparg equals 1 and the instruction is followed by NOT_TAKEN, the computed jump target and the computed fallthrough target are the same address:

computed_next_instr = target + 2 + 1 (skip NOT_TAKEN) = target + 3computed_jump_instr = target + 2 + 1 (oparg)

In this minimal reproduction case:

deftrigger():_= [xforxinrange(200)if [].append(x)orTrue]foriinrange(300):trigger()print("we finished")

which produces:

...        POP_JUMP_IF_TRUE         1 (to L4)L3:     NOT_TAKENL4:     LOAD_FAST_BORROW         0 (x)        LIST_APPEND              3        JUMP_BACKWARD           30 (to L2)...

the address comparisoncomputed_jump_instr == next_instr is always true regardless of which branch was actually taken, causing the assertionjump_happened == (target_instr[1].cache & 1) failed when the branch was not taken.

So we should fall back to theRECORD_BRANCH_TAKEN cache bit (target_instr[1].cache & 1) to determine the branch direction, since address comparison is ambiguous.

@devdanzin
Copy link
Member

Related:#141797

Copy link
Member

@Fidget-SpinnerFidget-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

cocolato reacted with heart emoji
Copy link
Member

@markshannonmarkshannon 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 finding the root problem and coming up with a fix. This can be simplified by treatingtarget_instr[1].cache & 1 as the source of truth for branches.

cocolato reacted with heart emoji
_Py_CODEUNIT *computed_jump_instr = computed_next_instr_without_modifiers + oparg;
assert(next_instr == computed_next_instr || next_instr == computed_jump_instr);
int jump_happened = computed_jump_instr == next_instr;
int jump_happened;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
intjump_happened;
intjump_happened=target_instr[1].cache&1;

The direction of the jump is always recorded.

} else {
jump_happened = computed_jump_instr == next_instr;
}
assert(jump_happened == (target_instr[1].cache & 1));
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
assert(jump_happened==(target_instr[1].cache&1));
assert(jump_happened? (next_instr==computed_jump_instr) : (next_instr==computed_next_instr));

assert(next_instr == computed_next_instr || next_instr == computed_jump_instr);
int jump_happened = computed_jump_instr == next_instr;
int jump_happened;
if (computed_next_instr == computed_jump_instr) {
Copy link
Member

Choose a reason for hiding this comment

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

Then there is no need to change behavior depending on how long the branch is.

@bedevere-app
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phraseI have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

And if you don't make the requested changes, you will be poked with soft cushions!

@cocolato
Copy link
ContributorAuthor

Thanks for review! I have made the requested changes; please review again.

@bedevere-app
Copy link

Thanks for making the requested changes!

@markshannon,@Fidget-Spinner: please review the changes made to this pull request.

@cocolato
Copy link
ContributorAuthor

cocolato commentedMar 9, 2026
edited
Loading

The failed test appears unrelated to the current PR. It seems to have been introduced here:#145279

@markshannon
Copy link
Member

Let's see if updating the branch fixes it

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@markshannonmarkshannonmarkshannon approved these changes

@Fidget-SpinnerFidget-SpinnerFidget-Spinner approved these changes

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

4 participants

@cocolato@devdanzin@markshannon@Fidget-Spinner

[8]ページ先頭

©2009-2026 Movatter.jp