Skip to content

Rename Js.Bigint -> Js.BigInt #6696

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 2 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#### :rocket: New Feature

- Add the primitive bigint type https://github.com/rescript-lang/rescript-compiler/pull/6670
- Add the primitive bigint type https://github.com/rescript-lang/rescript-compiler/pull/6670 https://github.com/rescript-lang/rescript-compiler/pull/6696

#### :bug: Bug Fix

Expand Down
4 changes: 2 additions & 2 deletions jscomp/core/js_analyzer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ let rec eq_expression ({ expression_desc = x0 } : J.expression)
| Undefined x -> y0 = Undefined x
| Number (Int { i }) -> (
match y0 with Number (Int { i = j }) -> i = j | _ -> false)
| Number (Bigint {positive = p0; value = v0}) -> (
match y0 with Number (Bigint {positive = p1; value = v1}) -> p0 = p1 && v0 = v1 | _ -> false)
| Number (BigInt {positive = p0; value = v0}) -> (
match y0 with Number (BigInt {positive = p1; value = v1}) -> p0 = p1 && v0 = v1 | _ -> false)
| Number (Float _) -> false
(* begin match y0 with
| Number (Float j) ->
Expand Down
2 changes: 1 addition & 1 deletion jscomp/core/js_dump.ml
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ and expression_desc cxt ~(level : int) f x : cxt =
Int32.to_string i
(* check , js convention with ocaml lexical convention *)
| Uint i -> Format.asprintf "%lu" i
| Bigint {positive; value} -> Format.asprintf "%sn" (Bigint_utils.to_string positive value)
| BigInt {positive; value} -> Format.asprintf "%sn" (Bigint_utils.to_string positive value)
in
let need_paren =
if s.[0] = '-' then level > 13
Expand Down
6 changes: 3 additions & 3 deletions jscomp/core/js_exp_make.ml
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,9 @@ 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 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 zero_bigint_literal : t = {expression_desc = Number (BigInt {positive=true; value="0"}); comment = None}

let small_int i : t =
match i with
Expand Down Expand Up @@ -807,7 +807,7 @@ let tag_type = function
| Ast_untagged_variants.String s -> str s ~delim:DStarJ
| Int i -> small_int i
| Float f -> float f
| Bigint i ->
| BigInt i ->
let sign, i = Bigint_utils.parse_bigint i in
bigint sign i
| Bool b -> bool b
Expand Down
2 changes: 1 addition & 1 deletion jscomp/core/js_op.ml
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ type number =
| Float of float_lit
| Int of { i : int32; c : int option }
| Uint of int32
| Bigint of bigint_lit
| BigInt of bigint_lit

(* becareful when constant folding +/-,
since we treat it as js nativeint, bitwise operators:
Expand Down
2 changes: 1 addition & 1 deletion jscomp/core/js_stmt_make.ml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ let string_switch ?(comment : string option)
match switch_case with
| String s ->
if s = txt then Some x.switch_body else None
| Int _ | Float _ | Bigint _ | Bool _ | Null | Undefined | Untagged _ ->
| Int _ | Float _ | BigInt _ | Bool _ | Null | Undefined | Untagged _ ->
None)
with
| Some case -> case
Expand Down
2 changes: 1 addition & 1 deletion jscomp/core/lam_primitive.ml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ type t =
| Psubfloat
| Pmulfloat
| Pdivfloat
(* Bigint operations *)
(* BigInt operations *)
| Pnegbigint
| Paddbigint
| Psubbigint
Expand Down
10 changes: 5 additions & 5 deletions jscomp/ml/ast_untagged_variants.ml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ type tag_type =
| String of string
| Int of int
| Float of string
| Bigint of string
| BigInt of string
| Bool of bool
| Null
| Undefined (* literal or tagged block *)
Expand Down Expand Up @@ -126,7 +126,7 @@ let process_tag_type (attrs : Parsetree.attributes) =
| Some f -> st := Some (Float f));
(match Ast_payload.is_single_bigint payload with
| None -> ()
| Some i -> st := Some (Bigint i));
| Some i -> st := Some (BigInt i));
(match Ast_payload.is_single_bool payload with
| None -> ()
| Some b -> st := Some (Bool b));
Expand Down Expand Up @@ -291,7 +291,7 @@ let checkInvariant ~isUntaggedDef ~(consts : (Location.t * tag) list)
| Some (String s) -> addStringLiteral ~loc s
| Some (Int i) -> addNonstringLiteral ~loc (string_of_int i)
| Some (Float f) -> addNonstringLiteral ~loc f
| Some (Bigint i) -> addNonstringLiteral ~loc i
| Some (BigInt i) -> addNonstringLiteral ~loc i
| Some Null -> addNonstringLiteral ~loc "null"
| Some Undefined -> addNonstringLiteral ~loc "undefined"
| Some (Bool b) -> addNonstringLiteral ~loc (if b then "true" else "false")
Expand Down Expand Up @@ -398,7 +398,7 @@ module DynamicChecks = struct
in
let literals_overlaps_with_bigint () =
Ext_list.exists literal_cases (function
| Bigint _ -> true
| BigInt _ -> true
| _ -> false)
in
let literals_overlaps_with_boolean () =
Expand Down Expand Up @@ -488,5 +488,5 @@ module DynamicChecks = struct
| Untagged UnknownType ->
(* This should not happen because unknown must be the only non-literal case *)
assert false
| Bool _ | Float _ | Int _ | Bigint _ | String _ | Null | Undefined -> x
| Bool _ | Float _ | Int _ | BigInt _ | String _ | Null | Undefined -> x
end
2 changes: 1 addition & 1 deletion jscomp/ml/lambda.ml
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ type primitive =
| Pnegfloat | Pabsfloat
| Paddfloat | Psubfloat | Pmulfloat | Pdivfloat
| Pfloatcomp of comparison
(* Bigint operations *)
(* BigInt operations *)
| Pnegbigint | Paddbigint | Psubbigint | Ppowbigint
| Pmulbigint | Pdivbigint | Pmodbigint
| Pandbigint | Porbigint | Pxorbigint
Expand Down
2 changes: 1 addition & 1 deletion jscomp/ml/lambda.mli
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ type primitive =
| Pnegfloat | Pabsfloat
| Paddfloat | Psubfloat | Pmulfloat | Pdivfloat
| Pfloatcomp of comparison
(* Bigint operations *)
(* BigInt operations *)
| Pnegbigint | Paddbigint | Psubbigint | Ppowbigint
| Pmulbigint | Pdivbigint | Pmodbigint
| Pandbigint | Porbigint | Pxorbigint
Expand Down
2 changes: 1 addition & 1 deletion jscomp/ml/printlambda.ml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ let print_boxed_integer_conversion ppf bi1 bi2 =
fprintf ppf "%s_of_%s" (boxed_integer_name bi2) (boxed_integer_name bi1)

let boxed_integer_mark name = function
| Pbigint -> Printf.sprintf "Bigint.%s" name
| Pbigint -> Printf.sprintf "BigInt.%s" name
| Pint32 -> Printf.sprintf "Int32.%s" name
| Pint64 -> Printf.sprintf "Int64.%s" name

Expand Down
4 changes: 2 additions & 2 deletions jscomp/ml/variant_coercion.ml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ let variant_has_same_runtime_representation_as_target ~(targetPath : Path.t)
path_same Predef.path_string
|| (* unboxed Number(float) :> float *)
path_same Predef.path_float
|| (* unboxed Bigint(bigint) :> bigint *)
|| (* unboxed BigInt(bigint) :> bigint *)
path_same Predef.path_bigint
| Cstr_tuple [] -> (
(* Check that @as payloads match with the target path to coerce to.
Expand All @@ -48,7 +48,7 @@ let variant_has_same_runtime_representation_as_target ~(targetPath : Path.t)
| None | Some (String _) -> Path.same targetPath Predef.path_string
| Some (Int _) -> Path.same targetPath Predef.path_int
| Some (Float _) -> Path.same targetPath Predef.path_float
| Some (Bigint _) -> Path.same targetPath Predef.path_bigint
| Some (BigInt _) -> Path.same targetPath Predef.path_bigint
| Some (Null | Undefined | Bool _ | Untagged _) -> false)
| _ -> false
in
Expand Down
2 changes: 1 addition & 1 deletion jscomp/others/js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ module Float = Js_float
module Int = Js_int
(** Provide utilities for int *)

module Bigint = Js_bigint
module BigInt = Js_bigint
(** Provide utilities for bigint *)

module File = Js_file
Expand Down
18 changes: 9 additions & 9 deletions jscomp/others/js_bigint.res
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ number as a `bigint` if successfully parsed. Uncaught syntax exception otherwise

```rescript
/* returns 123n */
Js.Bigint.fromStringExn("123")
Js.BigInt.fromStringExn("123")

/* returns 0n */
Js.Bigint.fromStringExn("")
Js.BigInt.fromStringExn("")

/* returns 17n */
Js.Bigint.fromStringExn("0x11")
Js.BigInt.fromStringExn("0x11")

/* returns 3n */
Js.Bigint.fromStringExn("0b11")
Js.BigInt.fromStringExn("0b11")

/* returns 9n */
Js.Bigint.fromStringExn("0o11")
Js.BigInt.fromStringExn("0o11")

/* catch exception */
try {
Js.Bigint.fromStringExn("a")
Js.BigInt.fromStringExn("a")
} catch {
| _ => ...
}
Expand Down Expand Up @@ -62,20 +62,20 @@ See [`toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referen

```rescript
/* prints "123" */
Js.Bigint.toString(123n)->Js.log
Js.BigInt.toString(123n)->Js.log
```
*/
external toString: bigint => string = "toString"

@send
/**
Returns a string with a language-sensitive representation of this Bigint value.
Returns a string with a language-sensitive representation of this BigInt value.

## Examples

```rescript
/* prints "123" */
Js.Bigint.toString(123n)->Js.log
Js.BigInt.toString(123n)->Js.log
```
*/
external toLocaleString: bigint => string = "toLocaleString"
2 changes: 1 addition & 1 deletion jscomp/runtime/js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ module Float = Js_float
module Int = Js_int
(** Provide utilities for int *)

module Bigint = Js_bigint
module BigInt = Js_bigint
(** Provide utilities for bigint *)

module File = Js_file
Expand Down
4 changes: 2 additions & 2 deletions jscomp/test/VariantCoercion.res
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ module CoerceFromFloatToVariant = {
}

module CoerceFromBigintToVariant = {
@unboxed type bigints = Bigint(bigint) | @as(1n) First | @as(2n) Second | @as(3n) Third
@unboxed type bigints = BigInt(bigint) | @as(1n) First | @as(2n) Second | @as(3n) Third
let a = 100n
let aa = 1n
let b: bigints = (a :> bigints)
let bb: bigints = (aa :> bigints)

@unboxed type mixed = Bigint(bigint) | @as(1n) One | @as(null) Null | Two
@unboxed type mixed = BigInt(bigint) | @as(1n) One | @as(null) Null | Two
let c = 120n
let cc: mixed = (c :> mixed)
}
10 changes: 5 additions & 5 deletions jscomp/test/bigint_test.res
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ let bigint_lessequal = (x: bigint, y) => x <= y
let generic_lessequal = \"<="
let bigint_greaterequal = (x: bigint, y) => x >= y
let generic_greaterequal = \">="
let bigint_land = Js.Bigint.land
let bigint_lor = Js.Bigint.lor
let bigint_lxor = Js.Bigint.lxor
let bigint_lsl = Js.Bigint.lsl
let bigint_asr = Js.Bigint.asr
let bigint_land = Js.BigInt.land
let bigint_lor = Js.BigInt.lor
let bigint_lxor = Js.BigInt.lxor
let bigint_lsl = Js.BigInt.lsl
let bigint_asr = Js.BigInt.asr

let () = {
eq(__LOC__, bigint_compare(1n, 1n), 0)
Expand Down
2 changes: 1 addition & 1 deletion jscomp/test/caml_compare_bigint_test.res
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ let isEqual = (title, num1, num2) => list{

let five = bigint("5")

/** Not comparing floats and Bigint; not sure this is correct since works in JavaScript */
/** Not comparing floats and BigInt; not sure this is correct since works in JavaScript */
let suites: Mt.pair_suites = \"@"(
isLessThan("123 and 555555", bigint("123"), bigint("555555")),
\"@"(
Expand Down
4 changes: 2 additions & 2 deletions lib/es6/js.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var Float;

var Int;

var Bigint;
var $$BigInt;

var $$File;

Expand Down Expand Up @@ -101,7 +101,7 @@ export {
Types ,
Float ,
Int ,
Bigint ,
$$BigInt ,
$$File ,
$$Blob ,
$$Option ,
Expand Down
4 changes: 2 additions & 2 deletions lib/js/js.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var Float;

var Int;

var Bigint;
var $$BigInt;

var $$File;

Expand Down Expand Up @@ -100,7 +100,7 @@ exports.TypedArray2 = TypedArray2;
exports.Types = Types;
exports.Float = Float;
exports.Int = Int;
exports.Bigint = Bigint;
exports.$$BigInt = $$BigInt;
exports.$$File = $$File;
exports.$$Blob = $$Blob;
exports.$$Option = $$Option;
Expand Down