From 4ceb964d3aef72c0f96d76630e221e11dd2c51a5 Mon Sep 17 00:00:00 2001 From: mununki Date: Mon, 7 Oct 2024 11:02:43 +0900 Subject: [PATCH 1/4] fix js ouput of bigint max, min --- jscomp/core/lam_compile_primitive.ml | 2 +- jscomp/core/lam_convert.ml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/jscomp/core/lam_compile_primitive.ml b/jscomp/core/lam_compile_primitive.ml index 7090269767..469c706474 100644 --- a/jscomp/core/lam_compile_primitive.ml +++ b/jscomp/core/lam_compile_primitive.ml @@ -416,7 +416,7 @@ let translate output_prefix loc (cxt : Lam_compile_context.t) | _ -> assert false) | Pbigintmax -> ( match args with - | [ { expression_desc = Number (Float _) } as a; { expression_desc = Number (Float _) } as b ] + | [ { expression_desc = Number (BigInt _) } as a; { expression_desc = Number (BigInt _) } as b ] when Js_analyzer.is_okay_to_duplicate a && Js_analyzer.is_okay_to_duplicate b -> E.econd (E.js_comp Cgt a b) a b | [ a; b ] -> E.runtime_call Primitive_modules.bigint "max" args diff --git a/jscomp/core/lam_convert.ml b/jscomp/core/lam_convert.ml index 40c0d1ca52..92651252c2 100644 --- a/jscomp/core/lam_convert.ml +++ b/jscomp/core/lam_convert.ml @@ -305,8 +305,8 @@ let lam_prim ~primitive:(p : Lambda.primitive) ~args loc : Lam.t = | Pasrbigint -> prim ~primitive:Pasrbigint ~args loc | Pbigintcomp x -> prim ~primitive:(Pbigintcomp x) ~args loc | Pbigintorder -> prim ~primitive:Pbigintorder ~args loc - | Pbigintmin -> prim ~primitive:Pbigintorder ~args loc - | Pbigintmax -> prim ~primitive:Pbigintorder ~args loc + | Pbigintmin -> prim ~primitive:Pbigintmin ~args loc + | Pbigintmax -> prim ~primitive:Pbigintmax ~args loc | Pintcomp x -> prim ~primitive:(Pintcomp x) ~args loc | Poffsetint x -> prim ~primitive:(Poffsetint x) ~args loc | Poffsetref x -> prim ~primitive:(Poffsetref x) ~args loc From 40ff5b79db266d5780f8f321b83404e26bad2023 Mon Sep 17 00:00:00 2001 From: mununki Date: Mon, 7 Oct 2024 11:11:42 +0900 Subject: [PATCH 2/4] add tests --- tests/tests/src/bigint_test.js | 4 ++++ tests/tests/src/bigint_test.res | 2 ++ 2 files changed, 6 insertions(+) diff --git a/tests/tests/src/bigint_test.js b/tests/tests/src/bigint_test.js index d12969b47a..27d88ca9cd 100644 --- a/tests/tests/src/bigint_test.js +++ b/tests/tests/src/bigint_test.js @@ -148,6 +148,10 @@ eq("File \"bigint_test.res\", line 165, characters 5-12", (-9n >> 1n), -5n); eq("File \"bigint_test.res\", line 166, characters 5-12", (-9n >> -1n), -18n); +eq("File \"bigint_test.res\", line 167, characters 5-12", 9n > 1n ? 9n : 1n, 9n); + +eq("File \"bigint_test.res\", line 168, characters 5-12", 9n < 1n ? 9n : 1n, 1n); + Mt.from_pair_suites("Bigint_test", suites.contents); exports.test_id = test_id; diff --git a/tests/tests/src/bigint_test.res b/tests/tests/src/bigint_test.res index c39bce036d..70b3f16d91 100644 --- a/tests/tests/src/bigint_test.res +++ b/tests/tests/src/bigint_test.res @@ -164,6 +164,8 @@ let () = { eq(__LOC__, bigint_asr(9n, -1n), 18n) eq(__LOC__, bigint_asr(-9n, 1n), -5n) eq(__LOC__, bigint_asr(-9n, -1n), -18n) + eq(__LOC__, max(9n, 1n), 9n) + eq(__LOC__, min(9n, 1n), 1n) } let () = Mt.from_pair_suites(__MODULE__, suites.contents) From d01c73da8835667c806d48457150268ee3db5275 Mon Sep 17 00:00:00 2001 From: mununki Date: Mon, 7 Oct 2024 11:14:06 +0900 Subject: [PATCH 3/4] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a8e756cbf2..f263c6fed1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ - Fix tuple coercion. https://github.com/rescript-lang/rescript-compiler/pull/7024 - Fix attribute printing. https://github.com/rescript-lang/rescript-compiler/pull/7025 - Fix "rescript format" with many files. https://github.com/rescript-lang/rescript-compiler/pull/7081 +- Fix bigint max, min https://github.com/rescript-lang/rescript-compiler/pull/7088 #### :nail_care: Polish From 77a46307c78cf832f2cb5d127846c7d8a4d7b63d Mon Sep 17 00:00:00 2001 From: mununki Date: Mon, 7 Oct 2024 11:30:39 +0900 Subject: [PATCH 4/4] use bigint_comp --- jscomp/core/lam_compile_primitive.ml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jscomp/core/lam_compile_primitive.ml b/jscomp/core/lam_compile_primitive.ml index 469c706474..da69377810 100644 --- a/jscomp/core/lam_compile_primitive.ml +++ b/jscomp/core/lam_compile_primitive.ml @@ -411,14 +411,14 @@ let translate output_prefix loc (cxt : Lam_compile_context.t) match args with | [ { expression_desc = Number (BigInt _) } as a; { expression_desc = Number (BigInt _) } as b ] when Js_analyzer.is_okay_to_duplicate a && Js_analyzer.is_okay_to_duplicate b -> - E.econd (E.js_comp Clt a b) a b + E.econd (E.bigint_comp Clt a b) a b | [ a; b ] -> E.runtime_call Primitive_modules.bigint "min" args | _ -> assert false) | Pbigintmax -> ( match args with | [ { expression_desc = Number (BigInt _) } as a; { expression_desc = Number (BigInt _) } as b ] when Js_analyzer.is_okay_to_duplicate a && Js_analyzer.is_okay_to_duplicate b -> - E.econd (E.js_comp Cgt a b) a b + E.econd (E.bigint_comp Cgt a b) a b | [ a; b ] -> E.runtime_call Primitive_modules.bigint "max" args | _ -> assert false) | Pstringorder -> (