8000 GH-99554: Pack location tables more effectively by brandtbucher · Pull Request #99556 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

GH-99554: Pack location tables more effectively #99556

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Dec 22, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup
  • Loading branch information
brandtbucher committed Nov 16, 2022
commit 24ce84fc8171c118c189582a3fcbca817ac6a666
11 changes: 7 additions & 4 deletions Python/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,13 @@ location_is_after(location loc1, location loc2) {
static inline bool
same_location(location a, location b)
{
return (a.lineno < 0 && b.lineno < 0) ||(a.lineno == b.lineno &&
a.end_lineno == b.end_lineno &&
a.col_offset == b.col_offset &&
a.end_col_offset == b.end_col_offset);
if (a.lineno < 0 && b.lineno < 0) {
Copy link
Member

Choose a reason for hiding this comment

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

I’d check also that they are the same value in case we will want to distinguish between ‘no location’ and ‘unknown location’ or something like that.

(I’m assuming you don’t rely on the full equality check because we’re inconsistent about what the other 3 values are).

Copy link
Member

Choose a reason for hiding this comment

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

Should an "unknown location" ever exist? That sounds like a compiler bug.

Copy link
Member

Choose a reason for hiding this comment

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

I'm thinking of cases where we just want to take the location of the previous instruction. Currently we just say "NO_LOCATION", but would we ever want to distinguish between this case and the case where there truly is no location (because the instructions are fake)? I don't know, but we might not want to rule it out.

Copy link
Member Author

Choose a reason for hiding this comment

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

(I’m assuming you don’t rely on the full equality check because we’re inconsistent about what the other 3 values are).

Actually, it appears that we can remove this special case entirely. Just using the full equality check results in the exact same PYC sizes for the entire stdlib.

return true;
}
return a.lineno == b.lineno &&
Copy link
Member

Choose a reason for hiding this comment

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

According to git diff you have a trailing space here. Surprised CI didn't catch it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Wow, nice catch! I'll fix it.

a.end_lineno == b.end_lineno &&
a.col_offset == b.col_offset &&
a.end_col_offset == b.end_col_offset;
}

#define LOC(x) SRC_LOCATION_FROM_AST(x)
Expand Down
0