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

オープン
#584 コメント 5 件 リアクション 3 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
25/100
issue の種類
機能追加
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
rust
領域
compilers

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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

主要言語
言語のデータがありません
スター
760
フォーク
68
PR マージ指標
30日以内にマージされた PR はありません

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

rust-lang/unsafe-code-guidelines のほかの issue

rust-lang/unsafe-code-guidelines の issue をすべて見る

似ている issue

Compilers の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。