Pointer shared by all enum variants loses `noalias`, `align` and `dereferenceable` attributes
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 14/100
Direzione di ricerca
This is compiler-internals work: two places must agree, the enum layout in rustc_abi (where the shared field offset and pointee type are derived) and the call-ABI attribute computation in rustc_codegen_llvm, which today only special-cases a null niche like Option<&mut i32>. Start by reproducing the two -Copt-level=3 -Cno-prepopulate-passes IR dumps in the issue and diffing both_mut against option_mut, then read how the reference attributes (noalias, dereferenceable, align, readonly) are attached for a plain reference. Done means each row of the issue's table emits the listed attributes, checked by a codegen test under tests/codegen.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
When every variant of an enum stores a reference at the same offset, rustc emits that pointer to LLVM as an opaque ptr, without the attributes it would get on its own or inside Option.
#![crate_type = "lib"]
pub enum BothMut<'a> {
A(&'a mut i32),
B(&'a mut i32),
}
#[no_mangle]
pub fn both_mut(x: BothMut<'_>) {}
#[no_mangle]
pub fn option_mut(x: Option<&mut i32>) {}
With rustc 1.102.0-nightly (9c5648833 2026-11-10) and -Copt-level=3 -Cno-prepopulate-passes on aarch64-apple-darwin:
define void @both_mut(i64 noundef range(i64 0, 2) %x.0, ptr noundef %x.1)
define void @option_mut(ptr noalias nofree noundef align 4 dereferenceable_or_null(4) %x)
The second field of BothMut is a &mut i32 whichever variant is active, so it could be marked noalias nofree noundef align 4 dereferenceable_or_null(4), just like Option<&mut i32>. The same goes for shared references, which could also get readonly. Loads of the pointer miss !align metadata too:
#[derive(Clone, Copy)]
pub enum BothShared<'a> {
A(&'a i32),
B(&'a i32),
}
#[no_mangle]
pub fn load_both_shared<'a>(x: &BothShared<'a>) -> BothShared<'a> {
*x
}
%_0.1 = load ptr, ptr %0, align 8, !noundef !5
where !align !{i64 4} could be added.
Expected behaviour
If every inhabited variant has a pointer at the offset, the enum should get what all of them agree on:
- the smaller pointee size and alignment;
- the shared pointer kind, e.g. two
&mut Tstay&mut T,Box<T>and&mut Tmeet atBox<T>, while&Tand&mut Thave nothing in common beyond size and alignment; - nothing if any inhabited variant has a non-pointer, or nothing, at that offset.
Uninhabited variants can be ignored, and a null niche variant (as today) is compatible with any pointer.
| Type | Today | Could be |
|---|---|---|
enum { A(&mut i32), B(&mut i32) } |
noundef |
noalias nofree noundef align 4 dereferenceable_or_null(4) |
enum { A(&i32), B(&i32) } |
noundef |
noalias nofree noundef readonly align 4 captures(address, read_provenance) dereferenceable_or_null(4) |
enum { A(&mut u32), B(&mut [u64; 4]) } |
noundef |
noalias nofree noundef align 4 dereferenceable_or_null(4) |
enum { A(&mut i32), B(&i32) } |
noundef |
noundef align 4 dereferenceable_or_null(4) |
enum { A(Box<i32>), B(&mut i32) } |
noundef |
noalias noundef align 4 dereferenceable_or_null(4) |
enum { A(&mut i32), B(*mut i32) } |
noundef |
noundef |
enum { A(&i32), B(usize) } |
noundef |
noundef |
enum { A(&mut i32), B(u64, Infallible) } |
noundef |
noalias nofree noundef align 4 dereferenceable_or_null(4) |
enum { A(&mut i32), B, C(Infallible) } |
noundef |
noalias nofree noundef align 4 dereferenceable_or_null(4) |
The last one is passed as a single pointer, like Option<&mut i32>, but misses out because it has three variants.
- Lingua principale
- Rust
- Stelle
- 123k
- Fork
- 16.6k
- Merge medio
- 2g 17h
- PR unite (30g)
- 532
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di rust-lang/rust
-
C-bug needs-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
rust-lang/rust#166722 · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
A-attributes relnotes relnotes-needs-review relnotes-tracking-issue T-compiler T-lang
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
A-run-make C-bug T-bootstrap
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
I maintainer di solito rispondono entro 1 giorno
-
Tracking issue for release notes of #161531: Remove `T: Send + Sync` bound from `Arc::downcast`Apertarelnotes relnotes-tracking-issue T-libs
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
A-str A-Unicode relnotes relnotes-tracking-issue T-libs
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 70/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di rust-lang/rust
Issue simili
-
Thai project names become 'project', 'project-2'… (slug keeps ASCII only)Forse già presa @mastel2 l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
storytold/craft-anything#2538 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
compiler-explorer/compiler-explorer#9738 ·
I maintainer di solito rispondono entro 2 giorni
-
area: runtime enhancement good first issue help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
hffgzktbcc-blip/ounce-core#663 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 73/100
zellij-org/zellij#6026 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
tamatebako/tebako#1155 ·
I maintainer di solito rispondono entro 1 giorno