[BUG] A value whose type names an interior origin is checked as if it were a reference
メンテナーはふだん 2 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 35/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 領域
- compilers
調査の方向性
The payload names no source files. Start by searching the lifetime checker for the diagnostics use of invalidated interior reference and use of a never-initialized interior reference, and find where a value whose type mentions origin_of(args[0]) is treated as forming a reference into args. Reproduce with the first program in the issue. Done when both sample programs compile and a pointer held across a real mutation of args is still rejected.
索引モデルが issue の本文から書いたものです。
説明
Bug description
A value can name a container's interior origin in its type without holding any reference into the container. The common case is an empty list of element pointers that is filled in afterwards. The lifetime checker treats creating such a value as forming a reference, so ordinary code that builds a table of element pointers is rejected even though the container is never mutated.
This matters because spelling the element type with the element's origin (origin_of(args[0])) is exactly what callers are asked to do as standard library types move to interior origins. The argv array that the standard library builds for posix_spawnp has this shape, and it starts failing as soon as its pointers carry an interior origin.
Actual behavior
Appending a pointer to an element:
def main():
var args: List[String] = ["a", "b"]
var ptrs = List[Pointer[String, ImmOrigin(origin_of(args[0]))]]()
ptrs.append(Pointer(to=args[0]))
print(len(ptrs))
error: use of invalidated interior reference 'args["element"]'
ptrs.append(Pointer(to=args[0]))
^
note: origin was defined here, after the reference was formed
ptrs.append(Pointer(to=args[0]))
^
Using the value before anything indexes args:
def main():
var args: List[String] = ["a", "b"]
var ptrs = List[Pointer[String, ImmOrigin(origin_of(args[0]))]]()
print(len(ptrs))
error: use of a never-initialized interior reference 'args["element"]'
print(len(ptrs))
^
The usual loop form, for i in range(len(args)): ptrs.append(Pointer(to=args[i])), fails the same way as the first program.
Expected behavior
Both programs compile. Creating a value whose type names args["element"], without deriving anything from args, should not count as forming a reference. A pointer held across a real mutation of args must still be rejected.
Workaround
Index the container once before creating the value. This compiles and prints 2, but it depends on statement order in a way nobody would guess:
def main():
var args: List[String] = ["a", "b"]
_ = Pointer(to=args[0]) # establish the origin first
var ptrs = List[Pointer[String, ImmOrigin(origin_of(args[0]))]]()
for i in range(len(args)):
ptrs.append(Pointer(to=args[i]))
print(len(ptrs))
The other workaround, spelling the whole-container origin origin_of(args) and casting each pointer to it, gives up invalidation tracking for those pointers.
System information
Reproduces on main built from source (Linux x86_64).
- 主要言語
- Mojo
- スター
- 30.2k
- フォーク
- 3.2k
- 平均マージ
- 5日 18時間
- マージ済み PR(30日)
- 27
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
modular/modular のほかの issue
-
accepted bug bug_feature_triaged good first issue mojo Team: Mojo Libraries
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 2 日以内に返信
-
accepted bug bug_feature_triaged good first issue mojo Team: Mojo Libraries
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 2 日以内に返信
-
bug_feature_triaged Team: Mojo Libraries
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 2 日以内に返信
-
bug_feature_triaged Team: Mojo Libraries
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
メンテナーはふだん 2 日以内に返信
-
bug_feature_triaged
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 2 日以内に返信
modular/modular の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
Deltakit/deltakit-compile#27 ·
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
メンテナーはふだん 1 日以内に返信
-
new issue
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
llvm/llvm-project#245835 ·
メンテナーはふだん 1 日以内に返信
-
enhancement needs triage
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
メンテナーはふだん 1 日以内に返信