diff --git a/CHANGELOG.md b/CHANGELOG.md index a85891b622..5cc6dc4a34 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/jscomp/core/js_analyzer.ml b/jscomp/core/js_analyzer.ml index f56c8b98d3..2ca6443c5a 100644 --- a/jscomp/core/js_analyzer.ml +++ b/jscomp/core/js_analyzer.ml @@ -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) -> diff --git a/jscomp/core/js_dump.ml b/jscomp/core/js_dump.ml index 412d8baaf0..454f46d9a9 100644 --- a/jscomp/core/js_dump.ml +++ b/jscomp/core/js_dump.ml @@ -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 diff --git a/jscomp/core/js_exp_make.ml b/jscomp/core/js_exp_make.ml index a40f7ad0d5..e462d6bcf9 100644 --- a/jscomp/core/js_exp_make.ml +++ b/jscomp/core/js_exp_make.ml @@ -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 @@ -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 diff --git a/jscomp/core/js_op.ml b/jscomp/core/js_op.ml index 04575cb4b4..9315f73c6d 100644 --- a/jscomp/core/js_op.ml +++ b/jscomp/core/js_op.ml @@ -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: diff --git a/jscomp/core/js_stmt_make.ml b/jscomp/core/js_stmt_make.ml index 258ce2c19d..b2550bfb99 100644 --- a/jscomp/core/js_stmt_make.ml +++ b/jscomp/core/js_stmt_make.ml @@ -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 diff --git a/jscomp/core/lam_primitive.ml b/jscomp/core/lam_primitive.ml index 1ccc636de1..3280a095d0 100644 --- a/jscomp/core/lam_primitive.ml +++ b/jscomp/core/lam_primitive.ml @@ -80,7 +80,7 @@ type t = | Psubfloat | Pmulfloat | Pdivfloat - (* Bigint operations *) + (* BigInt operations *) | Pnegbigint | Paddbigint | Psubbigint diff --git a/jscomp/ml/ast_untagged_variants.ml b/jscomp/ml/ast_untagged_variants.ml index a1fbacc8a6..262291301d 100644 --- a/jscomp/ml/ast_untagged_variants.ml +++ b/jscomp/ml/ast_untagged_variants.ml @@ -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 *) @@ -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)); @@ -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") @@ -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 () = @@ -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 diff --git a/jscomp/ml/lambda.ml b/jscomp/ml/lambda.ml index a73c8504d4..91f63a94de 100644 --- a/jscomp/ml/lambda.ml +++ b/jscomp/ml/lambda.ml @@ -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 diff --git a/jscomp/ml/lambda.mli b/jscomp/ml/lambda.mli index 902bc4aa3e..f7fac1e7a1 100644 --- a/jscomp/ml/lambda.mli +++ b/jscomp/ml/lambda.mli @@ -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 diff --git a/jscomp/ml/printlambda.ml b/jscomp/ml/printlambda.ml index 98e0ab2e9e..ee67f25087 100644 --- a/jscomp/ml/printlambda.ml +++ b/jscomp/ml/printlambda.ml @@ -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 diff --git a/jscomp/ml/variant_coercion.ml b/jscomp/ml/variant_coercion.ml index 21f6c11e5a..e2b272d2a6 100644 --- a/jscomp/ml/variant_coercion.ml +++ b/jscomp/ml/variant_coercion.ml @@ -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. @@ -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 diff --git a/jscomp/others/js.ml b/jscomp/others/js.ml index 7c41df8859..d3224d149e 100644 --- a/jscomp/others/js.ml +++ b/jscomp/others/js.ml @@ -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 diff --git a/jscomp/others/js_bigint.res b/jscomp/others/js_bigint.res index 66f83d9ba1..4288f1a40d 100644 --- a/jscomp/others/js_bigint.res +++ b/jscomp/others/js_bigint.res @@ -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 { | _ => ... } @@ -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" diff --git a/jscomp/runtime/js.ml b/jscomp/runtime/js.ml index d92826849f..c018005887 100644 --- a/jscomp/runtime/js.ml +++ b/jscomp/runtime/js.ml @@ -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 diff --git a/jscomp/test/VariantCoercion.res b/jscomp/test/VariantCoercion.res index 9286ed8d78..5c31324efc 100644 --- a/jscomp/test/VariantCoercion.res +++ b/jscomp/test/VariantCoercion.res @@ -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) } diff --git a/jscomp/test/bigint_test.res b/jscomp/test/bigint_test.res index e2439c7798..4348c8fb7d 100644 --- a/jscomp/test/bigint_test.res +++ b/jscomp/test/bigint_test.res @@ -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) diff --git a/jscomp/test/caml_compare_bigint_test.res b/jscomp/test/caml_compare_bigint_test.res index 09693cd038..1e026daaaa 100644 --- a/jscomp/test/caml_compare_bigint_test.res +++ b/jscomp/test/caml_compare_bigint_test.res @@ -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")), \"@"( diff --git a/lib/es6/js.js b/lib/es6/js.js index bdf0d39a2b..0851782dbf 100644 --- a/lib/es6/js.js +++ b/lib/es6/js.js @@ -51,7 +51,7 @@ var Float; var Int; -var Bigint; +var $$BigInt; var $$File; @@ -101,7 +101,7 @@ export { Types , Float , Int , - Bigint , + $$BigInt , $$File , $$Blob , $$Option , diff --git a/lib/js/js.js b/lib/js/js.js index 02aee0d3ba..527d6d9dcb 100644 --- a/lib/js/js.js +++ b/lib/js/js.js @@ -51,7 +51,7 @@ var Float; var Int; -var Bigint; +var $$BigInt; var $$File; @@ -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;