python / python/devguide

Document how to add a bytecode specialization

Abierto
#1,286 11 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

good first issue help wanted
Lenguaje dominante
Python
Estrellas
2.1k
Forks
1k
Merge medio
2 d 12 h
PR fusionados (30 d)
12

Descripción

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.

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Usa PR 116385 y el esquema de nueve pasos como material de referencia. Empieza revisando los cambios mencionados y los archivos indicados—Python/bytecodes.c, Include/internal/pycore_code.h, Python/specialize.c, Lib/opcode.py y Include/internal/pycore_magic_number.h—y después elige la ubicación adecuada en la devguide o en la documentación de CPython. El trabajo estará terminado cuando una persona nueva pueda seguir el flujo de trabajo de especialización y verificarlo con make regen-all o build.bat --regen.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
python
Área
compilers, documentation
Tipo de issue
Documentación
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Activo
Claridad
Bastante claro
Aptitud para principiantes
74/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.