Does `MaybeDangling<&[mut] T>` make any requirements about the pointer's provenance?
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 25/100
Hướng nghiên cứu
Start with the concrete Rust example, the quoted RFC language, and the current aliasing-model candidates; compare the stated Miri behavior with the two proposed resolutions. Done means reaching consensus on whether MaybeDangling<&[mut] T> preserves provenance and permissions, then recording that decision so future model changes are noticed.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Concretely, is this code well-defined?
fn main() {
// Under the current models, we do not forbid writing through
// `MaybeDangling<&i32>`. That's not yet finally decided, but meanwhile
// ensure we document this and notice when it changes.
unsafe {
let mutref = &mut 0;
write_through_shr(mem::transmute(mutref));
}
fn write_through_shr(x: MaybeDangling<&i32>) {
unsafe {
let y: *mut i32 = mem::transmute(x);
y.write(1);
}
}
}
This "launders" a mutable reference through a MaybeDangling<&i32>. Miri says this is okay since MaybeDangling suppresses retags, meaning the provenance returned by the transmute in write_through_shr is exactly the same as the one that was passed into the transmute in main -- it is a Tree Borrows tag that has write permission.
To me, this is a natural consequence of the RFC:
MaybeDangling is a way to "truncate" T to its by-value invariant, which changes nothing for most types, but means that references and boxes are allowed as long as their bit patterns are fine
The above code not being UB means that we can not add LLVM attributes like captures(readonly) to MaybeDangling<&i32> arguments.
@wafflelapkin was quite surprised by this, so let's make sure we have consensus on how to resolve this question.
If we wanted to make this code UB, I can imagine two ways of achieving that:
- We actually still do retags inside
MaybeDangling, but we make those retags behave differently so that they don't fail for dangling pointers. IMO this is a bad idea; I think Rust should have a type that entirely suppresses the implicit move constructor that comes with references and boxes (i.e., the retags), and I thinkMaybeDanglingis the most natural candidate for that type. - When checking whether a shared reference is valid, we require its tag to not have write permission (with some suitable exception for
UnsafeCell). This would make transmutes from mutable references to shared references UB, unless we somehow make it so that we only check this validity requirement after all retags (if any) have happened. But even then this would lead to the odd situation where transmuting&mut Tto&Tis fine but transmuting it toMaybeDangling<&T>is UB, which seems broken for a type that is intended to let unsafe code do more stuff and avoid UB.
I think the 2nd point is how many people already think shared references work, e.g. I think it is the reason for @nikic's surprise here: the assumption is that the type itself requires the reference to be read-only. But currently that's not what the aliasing model candidates say; they say that shared references become read-only when they get retagged, but without a retag we can't say anything about their permissions.
@rust-lang/opsem what do you think?
- Ngôn ngữ chính
- Không có dữ liệu ngôn ngữ
- Star
- 760
- Fork
- 68
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của rust-lang/unsafe-code-guidelines
-
I-opsem-nominated
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
rust-lang/unsafe-code-guidelines#634 · 5 bình luận ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 15/100
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 12/100
rust-lang/unsafe-code-guidelines#632 · 8 bình luận · 1 reaction ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 10/100
rust-lang/unsafe-code-guidelines#631 · 7 bình luận ·
-
I-opsem-nominated
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 20/100
rust-lang/unsafe-code-guidelines#630 · 1 reaction ·
Tất cả issue của rust-lang/unsafe-code-guidelines
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
leanprover/lean4#16876 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Claiming namespace `nexfield`Đang mởnamespace team:operations
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
EclipseFdn/open-vsx.org#16434 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 90/100
eclipse-tractusx/tractusx-starter-kit#31 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
redact: SendGrid pattern masks Python identifiers like SG.rebound_binding_fields (agents misread code as corrupted)Có thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởarea/auth comp/agent P3 type/bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
NousResearch/hermes-agent#161417 ·
Maintainer thường phản hồi trong vòng 1 ngày