Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix js ouput of bigint max, min #7088

Merged
merged 4 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion jscomp/core/lam_compile_primitive.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use E.bigint_comp here should improve the outputs

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, thanks. 77a4630

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm ok E.econd itself doesn't seem to be optimized enough yet

| [ a; b ] -> E.runtime_call Primitive_modules.bigint "max" args
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)