Stdlib soundness of option returning functions
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 25/100
- Issue 类型
- 功能
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
- 技术栈
- ocaml
调研方向
Start by examining the standard library bindings for Array.shift, Array.pop, Array.get, and Map.get, then trace how option-returning functions are represented and compiled. The issue proposes several competing approaches, so first determine which behavior maintainers want; done means the selected approach makes these functions sound while addressing the interop edge cases raised.
由索引模型根据 Issue 内容生成。
描述
Array.shift, Array.pop, Array.get, Map.get, and likely others are unsound, see Playground.
Here is what a correct version of shift could be:
let shiftSafe = xs =>
if xs->Array.isEmpty {
None
} else {
let value = xs->Array.getUnsafe(0)
let _ = xs->Array.shift
Some(value)
}
This is a common mistake when writing JS bindings and can be unexpected to users who expect ReScript to be a safe language.
I couldn't find a previous discussion, but I believe this needs a bit of consideration. The choices I see are:
- Implement safe ReScript version of
Stdlibfunctions, rename the zero overhead toshiftUnsafe,getUnsafe, etc. - Fix the compiler's handling of option-returning functions.
- Fix the representation of options.
Unfortunately, I think there will always be edge-cases that make (2) a losing battle. Even with correct code generation, people often use imprecise types for interop making compile-time information insufficient to prevent unexpected results. For example, users storing undefined containing data in a JSON type.
Similar to the previous reasoning, (3) is likely going to cause too many issues from users that are relying on a particular option implementation.
So I believe (1) is the correct choice for the standard library. However, this still makes the "obvious" implementation of JS bindings written by users prone to errors. One idea would be to generate a fixture by default unless disabled:
@send external shift: array<'a> => option<'a> = "shift"
@send @noInterop external shiftUnsafe: array<'a> => option<'a> = "shift"
// Stdlib_Array.bs.js
let shift = t => Primitive_option.some(t.shift())
- 主要语言
- OCaml
- 星标
- 7.5k
- 派生
- 485
- 平均合并
- 17 小时 9 分钟
- 30 天内合并 PR
- 264
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
rescript-lang/rescript 的其他 Issue
-
Exception analysis does not know the Temporal `fromStringOrThrow` functions可能已有人在做 @cknitt 于 1 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
rescript-lang/rescript#9182 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 55/100
rescript-lang/rescript#9230 ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 72/100
rescript-lang/rescript#9229 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 44/100
rescript-lang/rescript#9228 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 45/100
rescript-lang/rescript#9227 ·
维护者通常 1 天内回复
查看 rescript-lang/rescript 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
NVIDIA-RTX/NRI#312 ·
维护者通常 1 天内回复
-
502 on Node 26: ERR_INVALID_ARG_VALUE: Setting the TLS ServerName to an IP address is not permitted未关闭
难度 2/5 1-3 小时 新手友好度 76/100
-
难度 2/5 1-3 小时 新手友好度 64/100
NucleusFramework/Nucleus#912 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 71/100
streetcomplete/StreetComplete#7364 · 7 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复