Skip to content
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

Allow to show specialized bytecode via dis CLI #127413

Closed
picnixz opened this issue Nov 29, 2024 · 3 comments
Closed

Allow to show specialized bytecode via dis CLI #127413

picnixz opened this issue Nov 29, 2024 · 3 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@picnixz
Copy link
Contributor

picnixz commented Nov 29, 2024

Feature or enhancement

Proposal:

It's already possible to show specialized bytecode using dis.dis(code, adaptive=True) but it's not possible to do it from the CLI. I think we can add a flag -S that does it (most of the other flags are exposed to the CLI).

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

@picnixz picnixz added type-feature A feature request or enhancement stdlib Python modules in the Lib dir labels Nov 29, 2024
@picnixz picnixz self-assigned this Nov 29, 2024
@JelleZijlstra
Copy link
Member

Doesn't bytecode only get specialized after it is run? The CLI will show bytecode for code that's never run, so it will never be specialized.

@picnixz
Copy link
Contributor Author

picnixz commented Nov 29, 2024

The CLI will show bytecode for code that's never run, so it will never be specialized.

Actually, dis.dis(adaptive=True) does show specialized bytecode. Or maybe I'm not using the correct terminology? For instance, a simple x = None shows a LOAD_CONST and not a LOAD_CONST_IMMORTAL, which is what I found weird.

@picnixz
Copy link
Contributor Author

picnixz commented Nov 30, 2024

An example:

Non-specialized bytecode

echo 'x = None' | ./python -m dis
  0           RESUME                   0

  1           LOAD_CONST               0 (None)
              STORE_NAME               0 (x)
              LOAD_CONST               0 (None)
              RETURN_VALUE

Specialized bytecode

echo 'x = None' | ./python -m dis -S
  0           RESUME                   0

  1           LOAD_CONST_IMMORTAL      0 (None)
              STORE_NAME               0 (x)
              LOAD_CONST_IMMORTAL      0 (None)
              RETURN_VALUE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants