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 — Generate Lib/opcode.py from Python/bytecodes.c · Issue #102674 · python/cpython

Generate Lib/opcode.py from Python/bytecodes.c #102674

New issue
Copy link
New issue
Copy link
Closed
Closed
Generate Lib/opcode.py from Python/bytecodes.c#102674
Copy link
Labels
type-featureA feature request or enhancementA feature request or enhancement

Description

@gvanrossum
gvanrossum
opened on Mar 14, 2023
Issue body actions

This could also auto-generate Include/opcode.h, Include/internal/pycore_opcode.h and Python/opcode_targets.h, subsuming both Tools/build/generate_opcode_h.py and Python/makeopcodetargets.py -- although the simplest approach would probably be to just keep those tools and only ensure that they are re-run after opcode.py is updated.

Variables to generate

The auto-generatable contents of opcode.py is as follows:

  • opmap -- make up opcode numbers in a pass after reading all input; special-case CACHE = 0
  • HAVE_ARGUMENT -- done while making up opcode numbers (group argument-less ones in lower group)
  • ENABLE_SPECIALIZATION = True
  • EXTENDED_ARG -- set from opcode for EXTENDED_ARG inst, if there is one
  • opname -- invert opmap
  • pseudo opcode definitions, can add DSL syntax pseudo(NAME) = { name1, name2, ... };
  • hasarg -- can be derived from instr_format metadata
  • hasconst -- could hardcode to LOAD_CONST
  • hasname -- may have to check for occurrences of co_names in code?
  • hasjrel -- check for JUMPBY with arg that doesn't start with INLINE_CACHE_ENTRIES_
  • hasjabs-- no longer used, set to [] for backwards compatibility
  • haslocal -- opcode name contains '_FAST'
  • hascompare -- opcode name starts with COMPARE_
  • hasfree -- opcode name ends in DEREF or CELL or CLOSURE
  • hasexc -- pseudo opcode, name starts with SETUP_
  • MIN_PSEUDO_OPCODE = 256
  • MAX_PSEUDO_OPCODE -- derive from pseudo opcodes
  • __all__ -- hardcode

The following are not public but imported by dis.py so they are still needed:

  • _nb_ops -- just hardcode?
  • _specializations -- derive from families (with some adjustments)
  • _specialized_instructions -- compute from _specializations
  • _specialization_stats -- only used by test__opcode.py, move into there?
  • _cache_format -- compute from cache effects? (how to make up names?)
  • _inline_cache_entries -- compute from _cache_format

The hardcoded stuff can go in prologue and epilogue sections that are updated manually.

This project (if we decide to do it) might be a good reason to refactor generate_cases.py into a library (the code for this shouldn't be shoved into the main file).

Benefits

We can wait on this project until we are sure we need at least one of the following benefits:

  • Once we are generating the numeric opcode values it will be easier to also generate numeric values for micro-opcodes.
  • Avoid having to keep multiple definitions in sync (e.g. families, cache formats).
  • Easier to understand. E.g. where are the numeric opcode values for specialized instructions defined? (Would require also subsuming generate_opcode_h.py.)

Linked PRs

  • gh-102674: Remove _specialization_stats from Lib/opcode.py #102685
Reacted by Kirill Podoprigora, Donghee Na and Ken Jin

Activity

  1. gvanrossum
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Mar 14, 2023
  2. corona10
    added a commit that references this issue on Mar 14, 2023

    pythongh-102674: Remove _specialization_stats from Lib/opcode.py

    a1d2dfa
  3. corona10 commented on Mar 14, 2023

    @corona10
    corona10
    on Mar 14, 2023
    Member
    More actions

    https://github.com/python/cpython/blob/main/Tools/unicode/gencjkcodecs.py can be a good reference for this task.
    (Template based output)

  4. gvanrossum
    added a commit that references this issue on Mar 14, 2023

    gh-102674: Remove _specialization_stats from Lib/opcode.py (#102685)

    d77c487
  5. carljm
    added a commit that references this issue on Mar 14, 2023

    Merge branch 'main' into inlinecomp2

    6c5f269
  6. Fidget-Spinner
    added a commit that references this issue on Mar 27, 2023

    pythongh-102674: Remove _specialization_stats from Lib/opcode.py (pyt…

    b608a19
  7. iritkatriel
    added
    type-featureA feature request or enhancementA feature request or enhancement
    and removed
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Apr 4, 2023
  8. warsaw
    added a commit that references this issue on Apr 11, 2023

    pythongh-102674: Remove _specialization_stats from Lib/opcode.py (pyt…

    442bd70
  9. iritkatriel commented on Nov 29, 2023

    @iritkatriel
    iritkatriel
    on Nov 29, 2023
    Member
    More actions

    I wasn't aware of this issue and did most of this under #105481.

    I think it's all done except for _cache_format.

  10. iritkatriel commented on Nov 29, 2023

    @iritkatriel
    iritkatriel
    on Nov 29, 2023
    Member
    More actions

    I'll go ahead and close this, we left cache format out because it's not currently possible to generate it from bytecodes.c because the cache entries are not specified in a consistent way (with same names) across families. There isn't currently a good reason to resolve that.

  11. iritkatriel
    closed this as completedon Nov 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-featureA feature request or enhancementA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      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.