No subobject provenance for arrays/slices

オープン
#622 コメント 54 件 リアクション 4 件 担当者 0 名 GitHub で見る

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

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
30/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
活発
技術スタック
rust

調査の方向性

Start by reviewing the example and the related unsafe-code-guidelines issue 419, then read the Reference wording in pull request 2338. The work is complete when the provenance policy is resolved and Miri no longer reports the demonstrated array or slice accesses as undefined behavior.

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

説明

disposition-merge proposed-final-comment-period T-opsem

https://github.com/rust-lang/unsafe-code-guidelines/issues/419 is a big topic, but there is one specific form of subobject provenance which is violated particularly often: using a reference to one element of an array/slice to access another. Even C allows this, so IMO we should commit to also allowing this in Rust.

Concretely, this means the following code has no UB:

fn main() {
    let x = &mut [1, 2, 3];
    let ptr = &mut x[0] as *mut i32;
    unsafe { ptr.add(1).write(5) };
    
    let ptr = &x[1] as *const i32;
    let _val = unsafe { ptr.sub(1).read() };
}

This is based on the observation that violations of such subobject provenance are the major kind of Stacked Borrows UB that Miri finds. I'd like to make Miri stop report this as UB, and for this I'd like to be sure that indeed we don't want to make this UB.

See https://github.com/rust-lang/reference/pull/2338 for Reference-level wording of this.

主要言語
言語のデータがありません
スター
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 を短くまとめたダイジェスト。