Break the ABI promise around `MaybeUninit`

Abierto
#631 7 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
10/100
Tipo de issue
Nueva funcionalidad
Claridad
Necesita aclaración
Estado de actividad
Activo
Stack tecnológico
rust
Área
compilers

Línea de trabajo

Start with the MaybeUninit API docs and the ABI compatibility list linked above, then read the earlier ptr::copy debate in unsafe-code-guidelines#518. The open question is whether to replace the blanket ABI promise with an integer/SIMD allowlist or a narrower denylist; the proposed lint firing on MaybeUninit in extern "C" declarations is the concrete entry point for ecosystem exploration. Done would mean an agreed policy plus crater/lint evidence, not a newcomer patch.

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

Descripción

We keep discovering that the MaybeUninit ABI promise (which didn't make it to this list but is mentioned in the MaybeUninit API docs) is causing problems:

  • For bool, the LLVM IR we generate is not in a shape where LLVM would guarantee ABI compatibility to us. Fixing this would require non-trivial changes on the LLVM side, if it is practical at all, and would also entirely preclude some hypothetical ABIs.
  • For float types, upholding the promise will become pretty much impossible when we migrate to the byte type. We need MaybeUninit<f64> to map to b64 on the LLVM side to ensure that partially initialized f64 have their initialized bytes preserved, but LLVM has no way of knowing that this particular b64 should be passed as a float rather than an int. Maybe LLVM could be extended to make that work, but it's not clear if upstream LLVM is really open to this idea.
  • Doing a copyof type T via ptr::copy is not the same as doing the copy at type MaybeUninit<T>: the latter erases padding. That's very surprising and not at all intentional. (This was the topic of a previous debate in https://github.com/rust-lang/unsafe-code-guidelines/issues/518.)

It seems fairly inevitable that we have to break our ABI promise at least a little bit. In the opsem meeting, people ere generally on-board with exploring the option of replacing the promise of ABI compatibility for all types with a promise that only covers a particular set of types (in particular integers, and hopefully SIMD vectors of integers). There's an alternative where we only take back the promise for bool and float types and structs containing bool or float types, but even assembling that list would be quite non-trivial, and there's a non-trivial risk that more surprises are lurking in this space. So if we can get away with it, having an allowlist would be much better than a denylist.

To see whether this is feasible, we're going to have to do a bit of ecosystem exploration.

  • @joshlf is letting the LLMs lose on this to try and find impacted code.
  • We agreed to do a crater run with a lint that fires on MaybeUninit in extern "C" function declarations. (Someone still has to volunteer to write that lint. :)
Lenguaje dominante
Sin datos de lenguaje
Estrellas
760
Forks
68
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

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.

Más de rust-lang/unsafe-code-guidelines

Todos los issues de rust-lang/unsafe-code-guidelines

Issues similares

Más issues de Compilers

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.