GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-133273: Keep instruction definitions in `bytecodes.c` and `optimizer_bytecodes.c` in sync by tomasr8 · Pull Request #133320 · python/cpython

Conversation

@tomasr8

@tomasr8 tomasr8 commented May 2, 2025 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

This implements the currently empty validate_uop.

It requires that instructions in bytecodes.c and optimizer_bytecodes.c:

  • have the same number of inputs and outputs
  • the input and output names match

Should we also validate the type/size?

I needed rename a few variables in bytecodes.c from unused to an actual name, otherwise changes are
kept to optimizer_bytecodes.c. There are some things I'm not sure about, I'll add comments to the relevant lines.

  • Issue: Keep instruction definitions in bytecodes.c and optimizer_bytecodes.c in sync #133273

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@tomasr8
tomasr8 requested review from Fidget-Spinner and markshannon as code owners May 2, 2025 20:22
@bedevere-app bedevere-app Bot mentioned this pull request May 2, 2025
Keep instruction definitions in bytecodes.c and optimizer_bytecodes.c in sync #133273
Closed
@bedevere-app bedevere-app Bot added the awaiting review label May 2, 2025
tomasr8
tomasr8 commented May 2, 2025
View reviewed changes
Comment thread Python/optimizer_bytecodes.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

@brandtbucher

brandtbucher commented May 2, 2025

Copy link
Copy Markdown
Member

Thanks!

Personally, I'm not sure that requiring the names to be in sync gains us anything. What's really useful is making sure that the stack effects are the same; if not, it's a serious bug in the optimizer. Making the names match just sort of creates busywork for anyone adding new optimizer cases.

And I think it's totally normal for something that's used in the bytecodes to be unused in the optimizer, and vice-versa. So I'd rather just have a special case for when one is unused (which the code generator can use to make the instruction more efficient), instead of forcing them to be loaded and the warnings to be manually silenced.

I'll wait for others to chime in, though. It's not a huge deal.

tomasr8 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Fidget-Spinner
Fidget-Spinner reviewed May 2, 2025
View reviewed changes
Comment thread Python/bytecodes.c
(void)counter;
}

op(_UNPACK_SEQUENCE, (seq -- unused[oparg], top[0])) {

@Fidget-Spinner Fidget-Spinner May 2, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Would it be possible to tell the validator that unused matches anything (both ways)?

So unused in optimizer_bytecodes/bytecodes isn't name-validated.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Fidget-Spinner

Fidget-Spinner commented May 2, 2025

Copy link
Copy Markdown
Member

Thanks!

Personally, I'm not sure that requiring the names to be in sync gains us anything. What's really useful is making sure that the stack effects are the same; if not, it's a serious bug in the optimizer. Making the names match just sort of creates busywork for anyone adding new optimizer cases.

And I think it's totally normal for something that's used in the bytecodes to be unused in the optimizer, and vice-versa. So I'd rather just have a special case for when one is unused (which the code generator can use to make the instruction more efficient), instead of forcing them to be loaded and the warnings to be manually silenced.

I agree on the unused part (see the comment above), but I think having names matching is useful, if just for the sake of standardization.

tomasr8 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tomasr8
Keep instruction definitions in bytecodes.c and optimizer_bytecodes.c…
7a09150
… in sync
@tomasr8
tomasr8 marked this pull request as draft May 3, 2025 08:50
@bedevere-app bedevere-app Bot removed the awaiting review label May 3, 2025
@tomasr8
tomasr8 force-pushed the validate-uops branch from 8a9fc9d to 7a09150 Compare May 3, 2025 08:51
@tomasr8
Also validate sizes
8e5e19b
@tomasr8

tomasr8 commented May 3, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

Thanks for the feedback! I updated the PR:

  • Ignore unused when checking uop names
  • Ensure that the uop size matches

Thanks to special-casing unused, I didn't need to modify bytecodes.c at all.

I also added skip news, since this is an internal change.

(I'll wait for the CI to pass and then mark it as ready)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tomasr8 tomasr8 added the skip news label May 3, 2025
tomasr8
tomasr8 commented May 3, 2025
View reviewed changes
Comment thread Python/optimizer_bytecodes.c
}

op(_CREATE_INIT_FRAME, (self, init, args[oparg] -- init_frame: _Py_UOpsAbstractFrame *)) {
op(_CREATE_INIT_FRAME, (init, self, args[oparg] -- init_frame: _Py_UOpsAbstractFrame *)) {

@tomasr8 tomasr8 May 3, 2025

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Looks like we found one case where checking the name is useful

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Fidget-Spinner reacted with rocket emoji
All reactions
  • 🚀 1 reaction

@Fidget-Spinner Fidget-Spinner May 8, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Awesome. This is exactly what we need this for!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@tomasr8
tomasr8 marked this pull request as ready for review May 3, 2025 11:47
@bedevere-app bedevere-app Bot added the awaiting review label May 3, 2025
@tomasr8
tomasr8 requested a review from Fidget-Spinner May 3, 2025 13:37
@tomasr8 tomasr8 assigned brandtbucher and unassigned brandtbucher May 3, 2025
@tomasr8
tomasr8 requested a review from brandtbucher May 3, 2025 13:38
@Fidget-Spinner

Fidget-Spinner commented May 6, 2025

Copy link
Copy Markdown
Member

I plan to merge this after 3.14 beta 1

tomasr8 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tomasr8
Merge remote-tracking branch 'upstream/main' into validate-uops
ffe5919
@tomasr8

tomasr8 commented May 8, 2025

Copy link
Copy Markdown
Member Author

(fixed a conflict)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Fidget-Spinner

Fidget-Spinner commented May 8, 2025

Copy link
Copy Markdown
Member

@brandtbucher merging this in the next 24 hours. Watch out for merge conflicts!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Fidget-Spinner
Fidget-Spinner merged commit 3f2f59a into python:main May 8, 2025
@bedevere-app bedevere-app Bot removed the awaiting review label May 8, 2025
@tomasr8
tomasr8 deleted the validate-uops branch May 8, 2025 20:38
Pranjal095 pushed a commit to Pranjal095/cpython that referenced this pull request Jul 12, 2025
@tomasr8 @Pranjal095
pythongh-133273: Keep instruction definitions in bytecodes.c and `o…
c65de78
…ptimizer_bytecodes.c` in sync (pythonGH-133320)
taegyunkim pushed a commit to taegyunkim/cpython that referenced this pull request Aug 4, 2025
@tomasr8 @taegyunkim
pythongh-133273: Keep instruction definitions in bytecodes.c and `o…
123b7f4
…ptimizer_bytecodes.c` in sync (pythonGH-133320)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@markshannon markshannon Awaiting requested review from markshannon markshannon is a code owner
@Fidget-Spinner Fidget-Spinner Awaiting requested review from Fidget-Spinner Fidget-Spinner is a code owner
@brandtbucher brandtbucher Awaiting requested review from brandtbucher

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

skip news

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@tomasr8 @brandtbucher @Fidget-Spinner
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.