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-120642: Move private PyCode APIs to the internal C API by vstinner · Pull Request #120643 · python/cpython

Conversation

@vstinner

@vstinner vstinner commented Jun 17, 2024 •
edited by bedevere-app Bot
Loading

Uh oh!

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

Copy link
Copy Markdown
Member
  • Move _Py_BackoffCounter to pycore_backoff.h.
  • Move _Py_CODEUNIT and related functions to pycore_code.h.
  • Move Include/cpython/optimizer.h content to pycore_optimizer.h.
  • Remove Include/cpython/optimizer.h.
  • Issue: [C API] Move private PyCode and PyOptimizer API to the internal C API #120642

Sorry, something went wrong.

Uh oh!

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

All reactions
@vstinner
pythongh-120642: Move private PyCode APIs to the internal C API
118f88f
* Move _Py_BackoffCounter to pycore_backoff.h.
* Move _Py_CODEUNIT and related functions to pycore_code.h.
* Move Include/cpython/optimizer.h content to pycore_optimizer.h.
* Remove Include/cpython/optimizer.h.
@vstinner
vstinner requested review from a team, ericsnowcurrently and erlend-aasland as code owners June 17, 2024 14:18
@bedevere-app bedevere-app Bot mentioned this pull request Jun 17, 2024
[C API] Move private PyCode and PyOptimizer API to the internal C API #120642
Closed
@bedevere-app bedevere-app Bot added the awaiting core review label Jun 17, 2024
@vstinner

vstinner commented Jun 17, 2024

Copy link
Copy Markdown
Member Author

@markshannon @iritkatriel @encukou: What do you think of this change?

The main effect is that 6 PyUnstable optimizer functions are moved to the internal C API (pycore_optimizer.h):

  • PyUnstable_Replace_Executor()
  • PyUnstable_SetOptimizer()
  • PyUnstable_GetOptimizer()
  • PyUnstable_GetExecutor()
  • PyUnstable_Optimizer_NewCounter()
  • PyUnstable_Optimizer_NewUOpOptimizer()

An alternative is to modify structures to add names to unions and structures, and then modify functions using it.

All reactions

Sorry, something went wrong.

Uh oh!

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

@vstinner vstinner added the skip news label Jun 17, 2024
@zooba

zooba commented Jun 17, 2024

Copy link
Copy Markdown
Member

We already went through and added union names to some of these, but I guess whichever developer keeps adding them didn't notice.

Looking at the number of CI failures, possibly adding the names is going to be less disruptive! 😆

All reactions

Sorry, something went wrong.

Uh oh!

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

@vstinner
Update Python/pylifecycle.c
7e4f175
@vstinner

vstinner commented Jun 17, 2024

Copy link
Copy Markdown
Member Author

Looking at the number of CI failures, possibly adding the names is going to be less disruptive! 😆

I just forgot to push a local change, I'm ashamed :-(

All reactions

Sorry, something went wrong.

Uh oh!

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

@vstinner

vstinner commented Jun 17, 2024

Copy link
Copy Markdown
Member Author

We already went through and added union names to some of these, but I guess whichever developer keeps adding them didn't notice.

test_cext and test_cppext are supposed to catch such issue, but we don't suppot "strict ISO C99" for now.

We can update these tests once a decision will be taken: capi-workgroup/decisions#30

All reactions

Sorry, something went wrong.

Uh oh!

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

@vstinner vstinner mentioned this pull request Jun 17, 2024
C standard for public headers capi-workgroup/decisions#30
Closed
shihai1991
shihai1991 reviewed Jun 19, 2024
View reviewed changes
Comment thread Include/Python.h Resolved

Uh oh!

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

@vstinner
Add NEWS entry
711cdc0
@vstinner vstinner removed the skip news label Jun 19, 2024
@vstinner
Remove PyUnstable functions
0788b3c
Remove PyUnstable_Replace_Executor().

Rename functions:

* PyUnstable_GetExecutor() => _Py_GetExecutor()
* PyUnstable_GetOptimizer() => _Py_GetOptimizer()
* PyUnstable_SetOptimizer() => _Py_SetOptimizerAPI()
* PyUnstable_Optimizer_NewCounter() => _PyOptimizer_NewCounter()
* PyUnstable_Optimizer_NewUOpOptimizer() => _PyOptimizer_NewUOpOptimizer()
@vstinner
vstinner requested a review from markshannon as a code owner June 20, 2024 09:46
@vstinner
Update code for the JIT compiler
464fc8d
@vstinner
vstinner requested a review from Fidget-Spinner as a code owner June 20, 2024 09:54
@vstinner vstinner mentioned this pull request Jun 20, 2024
Pluggable optimizer API #104584
Closed
@vstinner

vstinner commented Jun 20, 2024

Copy link
Copy Markdown
Member Author

If possible, I would like to backport this change to 3.13 to solve a C99 compatibility issue in the Python C API.

All reactions

Sorry, something went wrong.

Uh oh!

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

@vstinner vstinner added the needs backport to 3.13 only security fixes label Jun 20, 2024
Fidget-Spinner
Fidget-Spinner reviewed Jun 20, 2024
View reviewed changes
Comment thread Include/cpython/code.h Resolved

Uh oh!

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

vstinner added 2 commits June 26, 2024 11:21
@vstinner
Merge branch 'main' into internal_code
5588b7a
@vstinner
Document _Py_CODEUNIT removal
3f73bf3
@vstinner
vstinner force-pushed the internal_code branch from 05ae5f3 to 3f73bf3 Compare June 26, 2024 09:29
@Yhg1s

Yhg1s commented Jun 26, 2024

Copy link
Copy Markdown
Member

Since this is removing (unstable) C API functions added in 3.13 that everyone agrees we should remove, we should backport this to 3.13, yes.

All reactions

Sorry, something went wrong.

Uh oh!

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

markshannon
markshannon reviewed Jun 26, 2024
View reviewed changes
Comment thread Python/optimizer.c Outdated

int
PyUnstable_SetOptimizer(_PyOptimizerObject *optimizer)
_Py_SetOptimizerAPI(_PyOptimizerObject *optimizer)

@markshannon markshannon Jun 26, 2024

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.

Why the API suffix?
Maybe Py_SetTier2Optimizer (to distinguish it from the AST, bytecode or tier 1 optimizers)

Sorry, something went wrong.

Uh oh!

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

All reactions

@vstinner vstinner Jun 26, 2024

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.

There is another _Py_SetOptimizer() function with a different API. This one adds more boilerplate code and calls the first one.

Sorry, something went wrong.

Uh oh!

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

All reactions

@vstinner vstinner Jun 26, 2024

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.

I renamed the function to _Py_SetTier2Optimizer() (I added an underscore prefix).

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Include/internal/pycore_code.h
static inline _Py_CODEUNIT
_py_make_codeunit(uint8_t opcode, uint8_t oparg)
{
// No designated initialisers because of C++ compat

@markshannon markshannon Jun 26, 2024

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.

This is an internal header. Why does it need to be C++ compatible?

Sorry, something went wrong.

Uh oh!

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

All reactions

@vstinner vstinner Jun 26, 2024

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.

No idea, I just moved code. For now, I prefer to leave it as it is. I can be reworked later.

Sorry, something went wrong.

Uh oh!

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

All reactions
@vstinner
Rename _Py_SetOptimizerAPI() to _Py_SetTier2Optimizer().
1e8a1c0
@vstinner
vstinner merged commit 9e4a81f into python:main Jun 26, 2024
@vstinner
vstinner deleted the internal_code branch June 26, 2024 11:54
@miss-islington-app

miss-islington-app Bot commented Jun 26, 2024

Copy link
Copy Markdown

Thanks @vstinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

All reactions

Sorry, something went wrong.

Uh oh!

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

@bedevere-app bedevere-app Bot removed the awaiting core review label Jun 26, 2024
@miss-islington-app

miss-islington-app Bot commented Jun 26, 2024

Copy link
Copy Markdown

Sorry, @vstinner, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 9e4a81f00fef689c6e18a64245aa064eaadc7ac7 3.13
All reactions

Sorry, something went wrong.

Uh oh!

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

@miss-islington-app miss-islington-app Bot assigned vstinner Jun 26, 2024
vstinner added a commit to vstinner/cpython that referenced this pull request Jun 26, 2024
@vstinner
pythongh-120642: Move private PyCode APIs to the internal C API (pyth…
a00e53f
…on#120643)

* Move _Py_CODEUNIT and related functions to pycore_code.h.
* Move _Py_BackoffCounter to pycore_backoff.h.
* Move Include/cpython/optimizer.h content to pycore_optimizer.h.
* Remove Include/cpython/optimizer.h.
* Remove PyUnstable_Replace_Executor().

Rename functions:

* PyUnstable_GetExecutor() => _Py_GetExecutor()
* PyUnstable_GetOptimizer() => _Py_GetOptimizer()
* PyUnstable_SetOptimizer() => _Py_SetTier2Optimizer()
* PyUnstable_Optimizer_NewCounter() => _PyOptimizer_NewCounter()
* PyUnstable_Optimizer_NewUOpOptimizer() => _PyOptimizer_NewUOpOptimizer()

(cherry picked from commit 9e4a81f)
vstinner added a commit to vstinner/cpython that referenced this pull request Jun 26, 2024
@vstinner
pythongh-120642: Move private PyCode APIs to the internal C API (pyth…
c3f2f6e
…on#120643)

* Move _Py_CODEUNIT and related functions to pycore_code.h.
* Move _Py_BackoffCounter to pycore_backoff.h.
* Move Include/cpython/optimizer.h content to pycore_optimizer.h.
* Remove Include/cpython/optimizer.h.
* Remove PyUnstable_Replace_Executor().

Rename functions:

* PyUnstable_GetExecutor() => _Py_GetExecutor()
* PyUnstable_GetOptimizer() => _Py_GetOptimizer()
* PyUnstable_SetOptimizer() => _Py_SetTier2Optimizer()
* PyUnstable_Optimizer_NewCounter() => _PyOptimizer_NewCounter()
* PyUnstable_Optimizer_NewUOpOptimizer() => _PyOptimizer_NewUOpOptimizer()

(cherry picked from commit 9e4a81f)
@bedevere-app

bedevere-app Bot commented Jun 26, 2024

Copy link
Copy Markdown

GH-121043 is a backport of this pull request to the 3.13 branch.

All reactions

Sorry, something went wrong.

Uh oh!

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

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 only security fixes label Jun 26, 2024
vstinner added a commit that referenced this pull request Jun 26, 2024
@vstinner
[3.13] gh-120642: Move private PyCode APIs to the internal C API (#12…
e26e098
…0643) (#121043)

gh-120642: Move private PyCode APIs to the internal C API (#120643)

* Move _Py_CODEUNIT and related functions to pycore_code.h.
* Move _Py_BackoffCounter to pycore_backoff.h.
* Move Include/cpython/optimizer.h content to pycore_optimizer.h.
* Remove Include/cpython/optimizer.h.
* Remove PyUnstable_Replace_Executor().

Rename functions:

* PyUnstable_GetExecutor() => _Py_GetExecutor()
* PyUnstable_GetOptimizer() => _Py_GetOptimizer()
* PyUnstable_SetOptimizer() => _Py_SetTier2Optimizer()
* PyUnstable_Optimizer_NewCounter() => _PyOptimizer_NewCounter()
* PyUnstable_Optimizer_NewUOpOptimizer() => _PyOptimizer_NewUOpOptimizer()

(cherry picked from commit 9e4a81f)
mrahtz pushed a commit to mrahtz/cpython that referenced this pull request Jun 30, 2024
@vstinner @mrahtz
pythongh-120642: Move private PyCode APIs to the internal C API (pyth…
a3adbfb
…on#120643)

* Move _Py_CODEUNIT and related functions to pycore_code.h.
* Move _Py_BackoffCounter to pycore_backoff.h.
* Move Include/cpython/optimizer.h content to pycore_optimizer.h.
* Remove Include/cpython/optimizer.h.
* Remove PyUnstable_Replace_Executor().

Rename functions:

* PyUnstable_GetExecutor() => _Py_GetExecutor()
* PyUnstable_GetOptimizer() => _Py_GetOptimizer()
* PyUnstable_SetOptimizer() => _Py_SetTier2Optimizer()
* PyUnstable_Optimizer_NewCounter() => _PyOptimizer_NewCounter()
* PyUnstable_Optimizer_NewUOpOptimizer() => _PyOptimizer_NewUOpOptimizer()
@gvanrossum

gvanrossum commented Jul 11, 2024

Copy link
Copy Markdown
Member

FYI there are two mention of _PyCode_CODE left in Include/cpython/code.h:

#define _PyCode_CODE(CO) _Py_RVALUE((_Py_CODEUNIT *)(CO)->co_code_adaptive)
#define _PyCode_NBYTES(CO) (Py_SIZE(CO) * (Py_ssize_t)sizeof(_Py_CODEUNIT))

This seems out of place, since those macros cannot work unless one also includes pycore_code.h.

All reactions

Sorry, something went wrong.

Uh oh!

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

@vstinner

vstinner commented Jul 12, 2024

Copy link
Copy Markdown
Member Author

FYI there are two mention of _PyCode_CODE left in Include/cpython/code.h

Oh correct, I wrote PR gh-121644 to move these 2 macros to internal C API.

All reactions

Sorry, something went wrong.

Uh oh!

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

estyxx pushed a commit to estyxx/cpython that referenced this pull request Jul 17, 2024
@vstinner @estyxx
pythongh-120642: Move private PyCode APIs to the internal C API (pyth…
7f14dc3
…on#120643)

* Move _Py_CODEUNIT and related functions to pycore_code.h.
* Move _Py_BackoffCounter to pycore_backoff.h.
* Move Include/cpython/optimizer.h content to pycore_optimizer.h.
* Remove Include/cpython/optimizer.h.
* Remove PyUnstable_Replace_Executor().

Rename functions:

* PyUnstable_GetExecutor() => _Py_GetExecutor()
* PyUnstable_GetOptimizer() => _Py_GetOptimizer()
* PyUnstable_SetOptimizer() => _Py_SetTier2Optimizer()
* PyUnstable_Optimizer_NewCounter() => _PyOptimizer_NewCounter()
* PyUnstable_Optimizer_NewUOpOptimizer() => _PyOptimizer_NewUOpOptimizer()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@shihai1991 shihai1991 shihai1991 left review comments
@markshannon markshannon markshannon left review comments
@Fidget-Spinner Fidget-Spinner Fidget-Spinner left review comments
@ericsnowcurrently ericsnowcurrently Awaiting requested review from ericsnowcurrently ericsnowcurrently is a code owner
@erlend-aasland erlend-aasland Awaiting requested review from erlend-aasland erlend-aasland is a code owner

Uh oh!

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

Assignees

@vstinner vstinner

Labels

None yet

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.

7 participants

@vstinner @zooba @Yhg1s @gvanrossum @shihai1991 @markshannon @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.