Stdlib soundness of option returning functions
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 25/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- ocaml
- Lĩnh vực
- backend-api-design
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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())
- Ngôn ngữ chính
- OCaml
- Star
- 7.5k
- Fork
- 484
- Merge trung bình
- 17 giờ 9 phút
- Pull request đã merge (30 ngày)
- 264
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của rescript-lang/rescript
-
Exception analysis does not know the Temporal `fromStringOrThrow` functionsCó thể đã có người làm @cknitt đã nhận 1 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
rescript-lang/rescript#9182 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 55/100
rescript-lang/rescript#9230 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 72/100
rescript-lang/rescript#9229 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 44/100
rescript-lang/rescript#9228 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
rescript-lang/rescript#9227 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của rescript-lang/rescript
Issue tương tự
-
bug severity:low
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 2 ngày
-
needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
No Code Attached Yet
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
joomla/joomla-cms#48786 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Type: Bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
eyalgolan/statecraft-israel#2732 ·
Maintainer thường phản hồi trong vòng 1 ngày