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

Đang mở
#584 5 bình luận 3 reaction 0 người được giao Xem trên GitHub

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
Loại issue
Tính năng
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Công nghệ
rust
Lĩnh vực
compilers

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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).

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

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của rust-lang/unsafe-code-guidelines

Tất cả issue của rust-lang/unsafe-code-guidelines

Issue tương tự

Thêm issue về Compilers

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.