Break the ABI promise around `MaybeUninit`

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

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

評価

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

調査の方向性

Start with the MaybeUninit API docs and the ABI compatibility list linked above, then read the earlier ptr::copy debate in unsafe-code-guidelines#518. The open question is whether to replace the blanket ABI promise with an integer/SIMD allowlist or a narrower denylist; the proposed lint firing on MaybeUninit in extern "C" declarations is the concrete entry point for ecosystem exploration. Done would mean an agreed policy plus crater/lint evidence, not a newcomer patch.

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

説明

We keep discovering that the MaybeUninit ABI promise (which didn't make it to this list but is mentioned in the MaybeUninit API docs) is causing problems:

  • For bool, the LLVM IR we generate is not in a shape where LLVM would guarantee ABI compatibility to us. Fixing this would require non-trivial changes on the LLVM side, if it is practical at all, and would also entirely preclude some hypothetical ABIs.
  • For float types, upholding the promise will become pretty much impossible when we migrate to the byte type. We need MaybeUninit<f64> to map to b64 on the LLVM side to ensure that partially initialized f64 have their initialized bytes preserved, but LLVM has no way of knowing that this particular b64 should be passed as a float rather than an int. Maybe LLVM could be extended to make that work, but it's not clear if upstream LLVM is really open to this idea.
  • Doing a copyof type T via ptr::copy is not the same as doing the copy at type MaybeUninit<T>: the latter erases padding. That's very surprising and not at all intentional. (This was the topic of a previous debate in https://github.com/rust-lang/unsafe-code-guidelines/issues/518.)

It seems fairly inevitable that we have to break our ABI promise at least a little bit. In the opsem meeting, people ere generally on-board with exploring the option of replacing the promise of ABI compatibility for all types with a promise that only covers a particular set of types (in particular integers, and hopefully SIMD vectors of integers). There's an alternative where we only take back the promise for bool and float types and structs containing bool or float types, but even assembling that list would be quite non-trivial, and there's a non-trivial risk that more surprises are lurking in this space. So if we can get away with it, having an allowlist would be much better than a denylist.

To see whether this is feasible, we're going to have to do a bit of ecosystem exploration.

  • @joshlf is letting the LLMs lose on this to try and find impacted code.
  • We agreed to do a crater run with a lint that fires on MaybeUninit in extern "C" function declarations. (Someone still has to volunteer to write that lint. :)
主要言語
言語のデータがありません
スター
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 を短くまとめたダイジェスト。