Skip to content

Commit

Permalink
Fix js ouput of bigint max, min (#7088)
Browse files Browse the repository at this point in the history
* fix js ouput of bigint max, min

* add tests

* changelog

* use bigint_comp
  • Loading branch information
mununki authored Oct 7, 2024
1 parent 1de5e7c commit 403f11d
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions jscomp/core/lam_compile_primitive.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 (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
E.econd (E.bigint_comp Cgt a b) a b
| [ a; b ] -> E.runtime_call Primitive_modules.bigint "max" args
| _ -> assert false)
| Pstringorder -> (
Expand Down
4 changes: 2 additions & 2 deletions jscomp/core/lam_convert.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions tests/tests/src/bigint_test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions tests/tests/src/bigint_test.res
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 403f11d

Please sign in to comment.