Can (and should) we make use of LLVM's `writable` for reference arguments?

Abierto
#584 5 comentarios 3 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
25/100
Tipo de issue
Nueva funcionalidad
Claridad
Necesita aclaración
Estado de actividad
Estancado
Stack tecnológico
rust
Área
compilers

Línea de trabajo

Start by reading LLVM's writable attribute discussion and the linked unsafe-code-guidelines issue 450. Compare its implications for mutable references with examples such as slice::as_mut_ptr, ArrayVec::as_mut_ptr, and SmallVec::as_mut_ptr. Done means producing or documenting a resolved model and API decision; the issue currently does not define a concrete patch.

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

Descripción

A-aliasing-model

@nikic brought this up on Zulip before but I don't think we have an issue for this:

LLVM now has a writable attribute that allows the compiler to insert spurious writes up to the size of the dereferenceable attribute on the same pointer. It sure would be nice to use this for mutable references. OTOH, we almost certainly don't want functions like slice::as_mut_ptr to have their argument marked as "writable" -- at least if the aliasing model is anything like SB or TB, where a pointer's "derived from" identity matters until the end of the program, not just until the end of some scope (https://github.com/rust-lang/unsafe-code-guidelines/issues/450).

So it seems like we almost inevitably need some sort of attribute or so to control whether a function may do spurious writes to its &mut arguments. (Well, really this asks for having two types of mutable references, but I see no way that it'd actually make sense to introduce a new type here.) This would be a soundness-critical attribute (in the sense that removing the attribute can introduce UB into a program; adding it should always be fine).

That's a pretty big hammer. So far we haven't actually changed the language to experiment with SB/TB. If we add this attribute, it'll be needed in user code (e.g. ArrayVec::as_mut_ptr, SmallVec::as_mut_ptr). OTOH I don't see us stabilizing such an attribute any time soon. Crates may use cfg_attr(miri, rustc_two_phase_mutable_ref_arguments) but then we'd still add the writable attribute for normal non-Miri builds so that's not great.

The alternative would be to say, we must have a model where writable is sound for all mutable references. That kind of kills Tree Borrows. OTOH if we accept Tree Borrows as the model, that allows code which is incompatible with writable, so it's not really possible to add this back later (except with a per-function opt-in which is terrible).

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.