-
Notifications
You must be signed in to change notification settings - Fork 468
Introducing the bigint #6670
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
Merged
Merged
Introducing the bigint #6670
Changes from all commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
1441f59
add primitive bigint
mununki db001fa
Js_bigint adding operations
mununki 20410da
Js_json adding support of bigint
mununki 2f6217b
rename test
mununki 0b14c33
remove bigint from Js_json
mununki 4f40575
stale comment
mununki 6020820
remove unnecessary guard in pattern matching
mununki 8d95ccd
fix literal_overlaps
mununki 83070a0
primitive bigint instead of Js_bigint.t
mununki 128aa20
variant coercion for bigint
mununki c1d39b2
add error test
mununki 8835276
add optimization of comparisons
mununki 51e2ab2
add bigint_test and binding bigint methods, NaN, etc
mununki 84cf107
stale comment
mununki 0f21844
add bigint pow operator
mununki 6b01997
clean up Js_exp for bigint operations
mununki d386c4a
remove isNaN, isInfinite
mununki bc22261
remove NaN from BigInt
mununki 3b34a01
fix compare function
mununki d3032e1
fix test
mununki d3090ff
add bitwise operations
mununki 5683ca2
eta conversion for bigint
mununki da60074
optimization
mununki 41ba70b
bitwise operators in Js_bigint
mununki 3e9a471
add test for bitwise operations
mununki fee14cc
remove bigint operators from parser and pervasives
mununki fc1ea04
rebase clean up
mununki ec90078
update change log
mununki b8a5efd
fix incorrect compare bigint values
mununki 79df62c
remove leftover
mununki dd6b0cf
removed leftover
mununki 9852ad0
handling and testing bigint values with leading zeros and minus
mununki 00d741a
remove optimization const_compare from parmatch and add test
mununki 379dc31
add tests for pattern matching bigint liternal
mununki 990e5ac
support only decimal bigint literal and pattern matching
mununki 0d40dd9
fix test
mununki 79c7013
handle delimiter '_'
mununki 5748e83
throw Division_by_zero in bigint div, mod
mununki 4a43e39
call runtime only when dividing by zero
mununki e7e41c4
fix incorrect dividing by zero with non constant
mununki e8e8050
remove is_safe from Pdivbigint, Pmodbigint
mununki 5e963cd
stale comments
mununki 84eecd7
fix bigint_utils.compare
mununki 9652115
change bigint model to sign * string
mununki d82b4bc
clean up
mununki File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
jscomp/build_tests/super_errors/expected/bigint_match_literal.res.expected
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
[1;33mWarning number 11[0m | ||
[36m/.../fixtures/bigint_match_literal.res[0m:[2m3:3-4[0m | ||
|
||
1 [2m│[0m let m1 = switch 1n { | ||
2 [2m│[0m | 0001n => 1 | ||
[1;33m3[0m [2m│[0m | [1;33m1n[0m => 1 | ||
4 [2m│[0m | -0001n => -1 | ||
5 [2m│[0m | _ => 0 | ||
|
||
this match case is unused. |
10 changes: 10 additions & 0 deletions
10
jscomp/build_tests/super_errors/expected/variant_coercion_bigint.res.expected
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
[1;31mWe've found a bug for you![0m | ||
[36m/.../fixtures/variant_coercion_bigint.res[0m:[2m5:10-20[0m | ||
|
||
3 [2m│[0m let x = One(true) | ||
4 [2m│[0m | ||
[1;31m5[0m [2m│[0m let y = ([1;31mx :> bigint[0m) | ||
6 [2m│[0m | ||
|
||
Type x is not a subtype of bigint |
10 changes: 10 additions & 0 deletions
10
jscomp/build_tests/super_errors/expected/variant_coercion_bigint_as.res.expected
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
[1;31mWe've found a bug for you![0m | ||
[36m/.../fixtures/variant_coercion_bigint_as.res[0m:[2m5:10-20[0m | ||
|
||
3 [2m│[0m let x = One | ||
4 [2m│[0m | ||
[1;31m5[0m [2m│[0m let y = ([1;31mx :> bigint[0m) | ||
6 [2m│[0m | ||
|
||
Type x is not a subtype of bigint |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
jscomp/build_tests/super_errors/fixtures/bigint_match_literal.res
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
let m1 = switch 1n { | ||
| 0001n => 1 | ||
| 1n => 1 | ||
| -0001n => -1 | ||
| _ => 0 | ||
} |
5 changes: 5 additions & 0 deletions
5
jscomp/build_tests/super_errors/fixtures/variant_coercion_bigint.res
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
type x = | @as(1n) One(bool) | @as(2n) Two | ||
|
||
let x = One(true) | ||
|
||
let y = (x :> bigint) |
5 changes: 5 additions & 0 deletions
5
jscomp/build_tests/super_errors/fixtures/variant_coercion_bigint_as.res
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
type x = | @as(1n) One | Two | ||
|
||
let x = One | ||
|
||
let y = (x :> bigint) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -312,6 +312,10 @@ let obj_int_tag_literal : t = | |
|
||
let int ?comment ?c i : t = { expression_desc = Number (Int { i; c }); comment } | ||
|
||
let bigint ?comment sign i : t = { expression_desc = Number (Bigint {positive=sign; value=i}); comment} | ||
|
||
let zero_bigint_literal : t = {expression_desc = Number (Bigint {positive=true; value="0"}); comment = None} | ||
|
||
let small_int i : t = | ||
match i with | ||
| 0 -> zero_int_literal | ||
|
@@ -803,11 +807,15 @@ let tag_type = function | |
| Ast_untagged_variants.String s -> str s ~delim:DStarJ | ||
| Int i -> small_int i | ||
| Float f -> float f | ||
| Bigint i -> | ||
let sign, i = Bigint_utils.parse_bigint i in | ||
bigint sign i | ||
| Bool b -> bool b | ||
| Null -> nil | ||
| Undefined -> undefined | ||
| Untagged IntType -> str "number" | ||
| Untagged FloatType -> str "number" | ||
| Untagged BigintType -> str "bigint" | ||
| Untagged BooleanType -> str "boolean" | ||
| Untagged FunctionType -> str "function" | ||
| Untagged StringType -> str "string" | ||
|
@@ -1253,6 +1261,23 @@ let rec int32_band ?comment (e1 : J.expression) (e2 : J.expression) : | |
(* let int32_bin ?comment op e1 e2 : J.expression = *) | ||
(* {expression_desc = Int32_bin(op,e1, e2); comment} *) | ||
|
||
let bigint_op ?comment op (e1: t) (e2: t) = bin ?comment op e1 e2 | ||
|
||
let bigint_comp (cmp : Lam_compat.comparison) ?comment (e0: t) (e1: t) = | ||
bin ?comment (Lam_compile_util.jsop_of_comp cmp) e0 e1 | ||
|
||
let bigint_div ~checked ?comment (e0: t) (e1: t) = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks like the option to disable checking divide by zero is really only hidden under some ancient internal-only configuration at some point, it can be removed, perhaps in a later PR |
||
if checked then | ||
runtime_call Js_runtime_modules.bigint "div" [e0; e1] | ||
else | ||
bigint_op ?comment Div e0 e1 | ||
|
||
let bigint_mod ~checked ?comment (e0: t) (e1: t) = | ||
if checked then | ||
runtime_call Js_runtime_modules.bigint "mod_" [e0; e1] | ||
else | ||
bigint_op ?comment Mod e0 e1 | ||
|
||
(* TODO -- alpha conversion | ||
remember to add parens.. | ||
*) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just todo note. maybe it will be better to disable ansi color for test snapshot, or to checkin both colored and not