Skip to content

Conversation

Yzi-Li
Copy link
Contributor

@Yzi-Li Yzi-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-Li Yzi-Li marked this pull request as ready for review June 22, 2025 03:42
@Yzi-Li
Copy link
Contributor Author

Yzi-Li commented Jun 22, 2025

@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
Contributor Author

Yzi-Li commented Jun 23, 2025

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
Copy link
Member

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.
Copy link
Member

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
Contributor Author

Choose a reason for hiding this comment

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

pure inst(NOP, (--)) {
}

family(RESUME, 0) = {
    RESUME_CHECK,
};

macro(NOT_TAKEN) = NOP;

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

Copy link
Member

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
Contributor Author

Yzi-Li commented Jul 6, 2025

Sorry, I did some meaningless commits.

@Yzi-Li Yzi-Li requested a review from Fidget-Spinner July 11, 2025 10:55
@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-Turner AA-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-Turner AA-Turner changed the title gh-135447: Document new bytecodes in 3.14 gh-135447: Document NOT_TAKEN & POP_ITER bytecode instructions Sep 28, 2025
@AA-Turner AA-Turner enabled auto-merge (squash) September 28, 2025 16:39
@AA-Turner AA-Turner merged commit 519bc47 into python:main Sep 28, 2025
27 checks passed
@github-project-automation github-project-automation bot moved this from Todo to Done in Docs PRs Sep 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

bedevere-app bot commented Sep 28, 2025

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

@bedevere-app bedevere-app bot 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir skip news
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants