Skip to content

Conversation

@Yzi-Li
Copy link
Contributor

@Yzi-LiYzi-Li commented Jun 22, 2025

Document:

  • BUILD_TEMPLATE
  • BUILD_INTERPOLATION
  • NOT_TAKEN
  • POP_ITER
  • Remove BINARY_SUBSCR

📚 Documentation preview 📚: https://cpython-previews--135803.org.readthedocs.build/

@Yzi-LiYzi-Li marked this pull request as ready for review June 22, 2025 03:42
@Yzi-Li
Copy link
ContributorAuthor

@Fidget-Spinner I did a PR to fix the issue. I'm not sure if my expression is correct, so could you take a look? Thanks!

@Fidget-Spinner
Copy link
Member

Fidget-Spinner commented Jun 22, 2025

I think there's some misconception happening here, but no worries, I'll explain how to interpret the bytecode.

To document a new bytecode, you need to go to this file https://github.com/python/cpython/blob/main/Python/bytecodes.c . Then, find the bytecode definition (for example, inst(BUILD_INTERPOLATION). Everything after the comma and to the left of the -- are the stack inputs, everything to the right are stack outputs. So for example, inst(BUILD_INTERPOLATION, (value, str, format[oparg & 1] -- interpolation)) should be documented as:

``BUILD_INTERPOLATION`` expects as stack inputs: * ``STACK[oparg & 1]`` should be ``format`` * ``STACK[-1 - (oparg & 1)]`` should be ``str`` * ``STACK[-2 - (oparg & 1)]`` should be ``value`` ``BUILD_INTERPOLATION`` outputs the interpolation object to TOS after consuming its inputs 

Based on this, are you able to infer the behavior of BUILD_TEMPLATE :) ?

@Yzi-Li
Copy link
ContributorAuthor

Based on this, are you able to infer the behavior of BUILD_TEMPLATE :) ?

I have seen what you wrote. And I think I am able to express it.

But I've been a little busy recently so I might need a couple of days — sorry for the delay.


Create a Template object consuming interpolations and a string from the stack,
and pushes it onto the stack.
It consumes ``STACK[-1]``(string) and ``STACK[-2]``(interpolations) and

Choose a reason for hiding this comment

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

Nice, this is pretty close. One small error: it's the other way around, interpolations is STACK[-1], string is STACK[-2]. This is because the bytecode definition file models a stack (LIFO), which means the rightmost element is the top of the stack.

Comment on lines 589 to 590
Do nothing code. Used as a hint to the interpreter that a branch was predicted
as not taken.

Choose a reason for hiding this comment

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

I forgot what NOT_TAKEN does, but the rest look good. Maybe @iritkatriel knows?

Copy link
Member

Choose a reason for hiding this comment

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

It indeed does nothing. Not sure it's related to prediction though. It think it's to give tracing applications like code coverage a way to distinguish between the taken/not taken branches.

CC @markshannon

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

pureinst(NOP, (--)){} family(RESUME, 0) ={RESUME_CHECK, }; macro(NOT_TAKEN) =NOP;

Can we consider its behavior to be the same as NOP?

Choose a reason for hiding this comment

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

Yes its a NOP but I forgot if its a hint or not.

@Yzi-Li
Copy link
ContributorAuthor

Yzi-Li commented Jul 6, 2025

Sorry, I did some meaningless commits.

@Fidget-Spinner
Copy link
Member

I'm off next week. If no one else gets to it, I'll review the new changes the 2 weeks from now.

@AA-TurnerAA-Turner added the needs backport to 3.14 bugs and security fixes label Sep 21, 2025
@AA-Turner
Copy link
Member

@Fidget-Spinner do you have any further comments/reviews/objections? Would be good to document the 3.14 bytecodes, either in this PR or a different one.

A

@AA-Turner
Copy link
Member

I'll merge this, it adds documentation for two missing bytecode instructions for 3.14. Further improvements & other bytecodes can come later.

A

@AA-TurnerAA-Turner changed the title gh-135447: Document new bytecodes in 3.14gh-135447: Document NOT_TAKEN & POP_ITER bytecode instructionsSep 28, 2025
@AA-TurnerAA-Turner enabled auto-merge (squash) September 28, 2025 16:39
@AA-TurnerAA-Turner merged commit 519bc47 into python:mainSep 28, 2025
27 checks passed
@github-project-automationgithub-project-automationbot moved this from Todo to Done in Docs PRsSep 28, 2025
@miss-islington-app
Copy link

Thanks @Yzi-Li for the PR, and @AA-Turner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Sep 28, 2025
…nstructions (pythonGH-135803) (cherry picked from commit 519bc47) Co-authored-by: Yongzi Li <[email protected]> Co-authored-by: Adam Turner <[email protected]> Co-authored-by: Ken Jin <[email protected]>
@bedevere-app
Copy link

GH-139399 is a backport of this pull request to the 3.14 branch.

@bedevere-appbedevere-appbot removed the needs backport to 3.14 bugs and security fixes label Sep 28, 2025
hugovk pushed a commit that referenced this pull request Sep 28, 2025
…instructions (GH-135803) (#139399) Co-authored-by: Yongzi Li <[email protected]> Co-authored-by: Adam Turner <[email protected]> Co-authored-by: Ken Jin <[email protected]>
@Yzi-LiYzi-Li deleted the fix-issue-135447 branch October 12, 2025 05:06
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docsDocumentation in the Doc dirskip news

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants

@Yzi-Li@Fidget-Spinner@AA-Turner@iritkatriel