Encapsulate slice-DST size formulas behind a private invariant-bearing type
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 35/100
Línea de trabajo
Comienza localizando el módulo responsable de TrailingSliceLayout y sus consumidores de composición de DstLayout, padding, casting, proyección, asignación y división; después inspecciona la cobertura existente de Kani y la documentación de KnownLayout. Se considera terminado cuando los campos de las fórmulas son privados, los consumidores utilizan operaciones de abstracción comprobadas, las pruebas de regresión cubren offsets físicos e internos diferentes y el comportamiento público no cambia.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Context
#3630 fixes #3617 by representing a slice DST’s total-size sequence
independently from the physical offset of its trailing slice. After that
change, TrailingSliceLayout carries sibling pub(crate) fields for the
physical trailing-slice offset, trailing element size, and a normalized
formula:
size(elems) = prefix + round_up(offset + elems * elem_size, alignment)
where alignment is nonzero and a power of two and prefix < alignment.
This distinction is safety-critical. Packing can change a field’s physical
placement without changing trailing padding internal to the field’s type.
#3617 arose from conflating those concepts.
The representation and normalization arithmetic are currently exposed as
individual crate-visible fields. Callers can destructure, reconstruct, or
partially update them, making it possible for future changes to preserve one
coordinate while invalidating the other.
Proposal
Introduce a private invariant-bearing abstraction for the normalized
total-size sequence, conceptually:
struct SliceSizeFormula<E = usize> {
prefix: usize,
offset: usize,
elem_size: E,
alignment: NonZeroUsize,
}
struct TrailingSliceLayout<E = usize> {
trailing_slice_offset: usize,
size: SliceSizeFormula<E>,
}
Names and exact field division are open to bikeshedding. The important
properties are:
- Formula fields are private to the smallest practical leaf module.
- The physical trailing-field offset is represented separately from the
formula’s internal offset. - Code outside that module cannot directly construct or partially mutate a
formula. - Consumers use checked proof-oriented operations rather than reproducing
normalization arithmetic.
Candidate operations include checked construction/normalization,
size_for_elems, exact-size-to-metadata inversion, equality of complete size
sequences, checked prefix composition/formula shifting, padding/alignment
composition, trailing-element-size access, and separate physical trailing-slice
offset/end computations. Operations used in constants must preserve the
project’s MSRV and const-evaluation requirements.
Invariants
The abstraction should make these properties local and reviewable:
alignmentis nonzero and a power of two;prefix < alignment;size_for_elems(n)implements the documented normalized formula whenever
checked arithmetic succeeds;- construction, composition, and padding preserve normalization;
- the physical trailing-slice range is never inferred from the formula’s
internal offset; - for layouts admitted by
KnownLayout, the physical trailing-slice end is no
greater than the computed total object size; and - overflow remains explicit rather than hidden by normalization.
DstLayout may retain its existing public-contract posture; this proposal
shrinks the crate-internal region that can manipulate the safety-critical
formula representation.
Acceptance criteria
- No production code outside the owning module directly constructs or mutates
formula fields. DstLayoutcomposition, padding, casting, projection, allocation, and split
consumers use the abstraction’s operations.- Tests cover formulas whose physical trailing offset differs from the internal
rounding origin, including #3617’s nested-packed regression. - Existing Kani coverage is moved or extended to checked construction,
normalization, composition, padding, inversion, and sequence equivalence
over their stated domains. KnownLayoutdocumentation describes the same canonical formula and
physical-offset distinction.- Public behavior and supported layout domains do not change.
Non-goals
- Re-fixing #3617; #3630 supplies that semantic repair.
- Exposing the new representation publicly.
- Broadly replacing derive logic with meta-types; that remains #1948.
- Completing #3199’s formal-verification work, though this abstraction should
make it smaller and more local.
Related: #3617, #3630, #3199, #1948, #2541.
Authored by an AI agent acting on Josh Liebow-Feeser's behalf.
- Lenguaje dominante
- Rust
- Estrellas
- 2.6k
- Forks
- 194
- Merge medio
- 18 h 15 min
- PR fusionados (30 d)
- 14
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de google/zerocopy
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
Los mantenedores suelen responder en 1 día
-
Features to support optional defmt for the byteorder typesPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abiertocustomer-request
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
google/zerocopy#3914 · 1 comentario · 1 reacción ·
Los mantenedores suelen responder en 1 día
-
Misaligned pointer dereference in `Ref` due to incomplete `ByteSlice` move-stability contractAbierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
google/zerocopy#3766 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 64/100
Los mantenedores suelen responder en 1 día
Todos los issues de google/zerocopy
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
swc-project/swc-next-issues#533 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
Los mantenedores suelen responder en 5 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
eandualem/agent-interface#290 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 1 día