Skip to content

Allow to show specialized bytecode via dis CLI #127413

Closed

Description

@picnixz

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

Activity

  1. added
    type-featureA feature request or enhancement
    stdlibStandard Library Python modules in the Lib/ directory
    on Nov 29, 2024
  2. self-assigned this
    on Nov 29, 2024
  3. JelleZijlstra commented on Nov 29, 2024

    @JelleZijlstra
    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.

  4. picnixz commented on Nov 29, 2024

    @picnixz
    MemberAuthor

    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.

  5. picnixz commented on Nov 30, 2024

    @picnixz
    MemberAuthor

    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
  6. added a commit that references this issue on Dec 5, 2024
  7. added a commit that references this issue on Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

stdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions