Compiler crash (matching.ml assertion) on dict and optional-field record patterns mixing a value and `?None` on one key
維護者通常 1 天內回覆
已經有一個關聯 PR 被合併了。
- #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
- 分支
- 483
- 平均合併
- 19 小時 35 分鐘
- 30 天內合併 PR
- 208
環境準備
在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
rescript-lang/rescript 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 75/100
rescript-lang/rescript#9037 ·
維護者通常 1 天內回覆
-
Per-constructor @unboxed is not compared across interfaces or coercions可能已有人在做 @cknitt 今天認領。 未關閉
難度 4/5 3-5 天 新手友好度 25/100
rescript-lang/rescript#9038 ·
維護者通常 1 天內回覆
-
難度 5/5 一週以上 新手友好度 35/100
rescript-lang/rescript#9006 · 1 個 reaction ·
維護者通常 1 天內回覆
-
難度 3/5 1-2 天 新手友好度 70/100
rescript-lang/rescript#8997 ·
維護者通常 1 天內回覆
-
難度 3/5 1-2 天 新手友好度 68/100
rescript-lang/rescript#8994 ·
維護者通常 1 天內回覆
查看 rescript-lang/rescript 的全部 Issue
相似的 Issue
-
area:codegen backend:cuda backend:hip bug direction:input
難度 2/5 1-3 小時 新手友好度 78/100
CrossGL/crosstl#3061 · 1 則留言 ·
維護者通常 1 天內回覆
-
bug
難度 2/5 1-3 小時 新手友好度 85/100
-
難度 2/5 1-3 小時 新手友好度 78/100
-
build
難度 2/5 1-3 小時 新手友好度 65/100
AOMediaCodec/SVT-AV1#2500 ·
-
SIGSEGV in symex on __builtin_constant_p of a void expression可能已有人在做 關聯的 PR 仍在進行中或已合併。 未關閉bug goto-symex
難度 2/5 1-3 小時 新手友好度 83/100
維護者通常 1 天內回覆