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
- 派生
- 484
- 平均合并
- 1 天 1 小时
- 30 天内合并 PR
- 120
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
rescript-lang/rescript 的其他 Issue
-
难度 5/5 一周以上 新手友好度 25/100
rescript-lang/rescript#8833 · 1 个 reaction ·
维护者通常 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 一周以上 新手友好度 35/100
rescript-lang/rescript#8806 ·
维护者通常 1 天内回复
-
难度 5/5 一周以上 新手友好度 35/100
rescript-lang/rescript#8798 ·
维护者通常 1 天内回复
-
难度 3/5 半天 新手友好度 58/100
rescript-lang/rescript#8757 ·
维护者通常 1 天内回复
查看 rescript-lang/rescript 的全部 Issue
相似的 Issue
-
draft
难度 2/5 1-3 小时 新手友好度 66/100
维护者通常 1 天内回复
-
bot-triaged module: activation checkpointing module: inductor oncall: pt2 triaged
难度 2/5 1-3 小时 新手友好度 62/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
calcit-lang/calcit#2075 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 5 天内回复