Document how to add a bytecode specialization

Aberta
#1,286 11 comentários 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
3/5
Tempo estimado
1-2 dias
Facilidade para iniciantes
74/100
Tipo de issue
Documentação
Clareza
Razoavelmente clara
Status de atividade
Ativa
Stack de tecnologia
python

Direção de pesquisa

Use PR 116385 e o esboço em nove etapas como material de referência. Comece revisando as alterações referenciadas e os arquivos mencionados—Python/bytecodes.c, Include/internal/pycore_code.h, Python/specialize.c, Lib/opcode.py e Include/internal/pycore_magic_number.h—e depois escolha o local apropriado no devguide ou na documentação do CPython. O trabalho estará concluído quando uma pessoa nova puder seguir o workflow de especialização e verificá-lo com make regen-all ou build.bat --regen.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

good first issue help wanted

How to add a new bytecode specialization is knowledge only a few of us remember right now. We should document this somewhere (devguide or CPython, I don't mind). Hopefully a new contributor can pick this up!

There reference is this PR: https://github.com/python/cpython/pull/116385/files

Assuming you found an instruction that serves as a good specialization candidate. Let's use the example of CONTAINS_OP:

  1. Set the original CONTAINS_OP to a uop by changing it from CONTAINS_OP to _CONTAINS_OP in Python/bytecodes.c. The instruction definition should also change from inst to op.
  2. Add the uop that calls a specializing function. In this case _SPECIALIZE_CONTAINS_OP.
  3. The original CONTAINS_OP is now a new macro consisting of _SPECIALIZE_CONTAINS_OP + _CONTAINS_OP.
  4. Define the cache structure in Include/internal/pycore_code.h. At the very least, a 16-bit counter is needed.
  5. Write the specializing function itself in Python/specialize.c. Refer to any other function in that file for the format.
  6. Remember to update operation stats by calling add_stat_dict in Python/specialize.c.
  7. Add the cache layout in Lib/opcode.py so that Python's dis module will know how to represent it properly.
  8. Bump magic number in Include/internal/pycore_magic_number.h.
  9. Run make regen-all on *nix or build.bat --regen on PC.
Linguagem predominante
Python
Estrelas
2.1k
Forks
1k
Merge médio
2d 12h
PRs com merge (30d)
12

Guia de contribuição

Abrir o guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de python/devguide

Todas as issues de python/devguide

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.