Compiler crash (matching.ml assertion) on dict and optional-field record patterns mixing a value and `?None` on one key
メンテナーはふだん 1 日以内に返信
関連するプルリクエストがすでにマージされています。
- #8842 @cknitt による — マージ済み
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 35/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 停滞
- 技術スタック
- javascript, ocaml
- 領域
- compilers
調査の方向性
Start with compiler/ml/matching.ml at get_args_constr around line 1236, then read compiler/ml/dict_pattern.ml around lines 73–102 to understand how dict keys become optional record labels. Reproduce the crash with the supplied dict and optional record pattern examples, and inspect the existing compiler tests for matching. Done means both examples compile without an assertion failure; pull request #8842 is already open.
索引モデルが issue の本文から書いたものです。
説明
Found by adversarial experiments on semantic analysts.
What is broken
This match makes bsc crash:
let f = (d: dict<int>) =>
switch d {
| dict{"x": 1} => 0
| dict{"y": 2} => 0
| dict{"x": ?None} => 1
| _ => 2
}
$ bsc -nopervasives C1.res
Fatal error: exception File "compiler/ml/matching.ml", line 1236, characters 9-15: Assertion failed
Expected: it compiles. The compiler at ece8b148 produces:
function f(d) {
if (d.x !== 1 && d.y !== 2) {
if (d.x !== undefined) { return 2; } else { return 1; }
} else { return 0; }
}
The assertion is in get_args_constr: https://github.com/rescript-lang/rescript/blob/8d51b9ce7/compiler/ml/matching.ml#L1233-L1236
The same crash happens with a record type that has optional fields, both at master and at ece8b148:
type r = {x?: int, y?: int}
let f = (d: r) =>
switch d {
| {x: 1} => 0
| {y: 2} => 0
| {x: ?None} => 1 // `?Some(3)` crashes too
| _ => 2
}
Any two of the three cases compile. The crash needs a value pattern and an optional pattern (?None or ?Some(_)) on the same key, with a case on another key between them.
Introduced
The record crash is older. Dict patterns reach it since #8751 (e6c46f23b), which lowers every key of a match to one optional record label: https://github.com/rescript-lang/rescript/blob/8d51b9ce7/compiler/ml/dict_pattern.ml#L73-L102
Impact
The compiler crashes, with no source location, on an ordinary dict pattern match that compiled before #8751.
- 主要言語
- OCaml
- スター
- 7.5k
- フォーク
- 484
- 平均マージ
- 20時間 27分
- マージ済み PR(30日)
- 120
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
rescript-lang/rescript のほかの issue
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
rescript-lang/rescript#8833 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
rewatch watch on Linux stops watching a source folder when an overlapping recursive source folder is removed from rescript.json対応中かも @cknitt が 2 日前に担当しました。 オープン
難易度 4/5 1〜2日 初心者へのやさしさ 35/100
rescript-lang/rescript#8825 ·
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
rescript-lang/rescript#8806 ·
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
rescript-lang/rescript#8798 ·
メンテナーはふだん 1 日以内に返信
-
難易度 3/5 半日 初心者へのやさしさ 58/100
rescript-lang/rescript#8757 ·
メンテナーはふだん 1 日以内に返信
rescript-lang/rescript の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
limitlessprojects/Go-Hybrid#50 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
NationalSecurityAgency/ghidra#9884 ·
メンテナーはふだん 2 日以内に返信
-
llvm.memcpy with destination align but no source align asserts "Missed Source alignment!"対応中かも @pvelesko が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
KhronosGroup/SPIRV-LLVM-Translator#4093 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
FStarLang/karamel#784 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信