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-123044: Give thePOP_TOP after a case test a location in the body, not the pattern.#130627

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

@markshannon
Copy link
Member

@markshannonmarkshannon commentedFeb 27, 2025
edited by bedevere-appbot
Loading

@markshannonmarkshannon changed the titleGH-123044: GIve thePOP_TOP after a case test a location in the body, not the pattern.GH-123044: Give thePOP_TOP after a case test a location in the body, not the pattern.Feb 27, 2025
ADDOP(c,LOC(m->pattern),POP_TOP);
/* Use the body location to give better locations for branch events */
assert(asdl_seq_LEN(m->body)>0);
ADDOP(c,LOC(asdl_seq_GET(m->body,0)),POP_TOP);
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this be the location of the last instruction in the block? Line tracing might look like we executed that line more than once if we "return" to it after running another line.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I've added aNEXT_LOCATION pseudo location so that thePOP_TOP gets the location of whatever follows it.

.end_col_offset = (n)->end_col_offset }

staticconst_Py_SourceLocationNO_LOCATION= {-1,-1,-1,-1};
staticconst_Py_SourceLocationNEXT_LOCATION= {INT_MAX,INT_MAX,INT_MAX,INT_MAX};
Copy link
Member

@iritkatrieliritkatrielMar 1, 2025
edited
Loading

Choose a reason for hiding this comment

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

This is a good idea.

We probably need to change remove_redundant_nops to treat this as no location. Maybe it should be (-2, -2, -2, -2) and then just compare to 0?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

There are some checks forNO_LOCATION that compare to 0, but it isn't clear to me which should supportNEXT_LOCATION and which shouldn't, so I'm a bit reluctant to do that.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

With {2, -2, -2, -2},basicblock_remove_redundant_nops andpropagate_line_numbers needed changing.
basicblock_remove_redundant_nops needs to treat NEXT_LOCATION like NO_LOCATION
propagate_line_numbers needs to treat NEXT_LOCATIONnot like NO_LOCATION

if (same_location(instr[-1].i_loc,NEXT_LOCATION)) {
instr[-1].i_loc=instr->i_loc;
}
}
Copy link
Member

Choose a reason for hiding this comment

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

I think this transformation should be inpropagate_line_numbers in flowgraph.c. Otherwise the last instruction may remain without location, when it could have received a location from an earlier instruction in its block.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Wouldn't it be too early inpropagate_line_numbers?
If theNEXT_LOCATION instruction is at the end of the block where would it get the location information from?

Copy link
Member

Choose a reason for hiding this comment

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

From the next block (fall through or jump). If there is more than one successor, then we have a problem anyway, right, so what do we do?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

We should only useNEXT_LOCATION if instruction is not the last instruction in the block. I'll add an assert for that.

@markshannon
Copy link
MemberAuthor

The fuzzer found an example where the case body consists solely of a local variable annotation:

    ...    case _:        l: int

Since local variable annotations are removed from the compiler, there is no following instruction in the case body.
In this, somewhat weird, case we have to accept that the location for thePOP_TOP is going to be meaningless, and a terminator may end up with aNEXT_LOCATION. In that specific case, we have to just convert it toNO_LOCATION.

…tion to use. Assert NEXT_LOCATION never gets emitted
@markshannonmarkshannonforce-pushed thelocation-pop-top-after-case branch from859aa5a toa077433CompareMarch 10, 2025 14:02
@markshannonmarkshannon merged commitbe046ee intopython:mainMar 10, 2025
46 checks passed
seehwan pushed a commit to seehwan/cpython that referenced this pull requestApr 16, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@iritkatrieliritkatrieliritkatriel approved these changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@markshannon@iritkatriel

[8]ページ先頭

©2009-2025 Movatter.jp