Skip to content

Commit 8e4d23f

Browse files
authored
Merge pull request rescript-lang#6699 from cknitt/11-to-master
Merge changes from 11.0_release into master
2 parents c7b3dce + 024f87a commit 8e4d23f

File tree

111 files changed

+1258
-131
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+1258
-131
lines changed

CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@
2727

2828
- Make the `--help` arg be prioritized in the CLI, so correctly prints help message and skip other commands. https://github.com/rescript-lang/rescript-compiler/pull/6667
2929

30+
# 11.1.0-rc.6
31+
32+
#### :rocket: New Feature
33+
34+
- Add experimental BigInt support. https://github.com/rescript-lang/rescript-compiler/pull/6670, https://github.com/rescript-lang/rescript-compiler/pull/6696
35+
36+
#### :bug: Bug Fix
37+
38+
- Fix mishandling of uncurried functions in super errors. https://github.com/rescript-lang/rescript-compiler/pull/6694
39+
3040
# 11.1.0-rc.5
3141

3242
#### :bug: Bug Fix

jscomp/bsc/rescript_compiler_main.ml

+45
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,48 @@ let process_file sourcefile ?(kind ) ppf =
106106
in
107107
Config.uncurried := uncurried;
108108
res
109+
110+
let reprint_source_file sourcefile =
111+
let uncurried = !Config.uncurried in
112+
let kind = Ext_file_extensions.classify_input (Ext_filename.get_extension_maybe sourcefile) in
113+
let sourcefile = set_abs_input_name sourcefile in
114+
let res = match kind with
115+
| Res ->
116+
let parseResult =
117+
Res_driver.parsingEngine.parseImplementation ~forPrinter:true ~filename:sourcefile
118+
in
119+
if parseResult.invalid then (
120+
Res_diagnostics.printReport parseResult.diagnostics parseResult.source;
121+
exit 1
122+
);
123+
Res_compmisc.init_path ();
124+
parseResult.parsetree
125+
|> Cmd_ppx_apply.apply_rewriters ~restore:false ~tool_name:Js_config.tool_name Ml
126+
|> Ppx_entry.rewrite_implementation
127+
|> Res_printer.printImplementation ~width:100 ~comments:parseResult.comments
128+
|> print_endline
129+
| Resi ->
130+
let parseResult =
131+
Res_driver.parsingEngine.parseInterface ~forPrinter:true ~filename:sourcefile
132+
in
133+
if parseResult.invalid then (
134+
Res_diagnostics.printReport parseResult.diagnostics parseResult.source;
135+
exit 1
136+
);
137+
Res_compmisc.init_path ();
138+
parseResult.parsetree
139+
|> Cmd_ppx_apply.apply_rewriters ~restore:false ~tool_name:Js_config.tool_name Mli
140+
|> Ppx_entry.rewrite_signature
141+
|> Res_printer.printInterface ~width:100 ~comments:parseResult.comments
142+
|> print_endline
143+
| _
144+
->
145+
print_endline ("Invalid input for reprinting ReScript source. Must be a ReScript file: " ^ sourcefile);
146+
exit 2
147+
in
148+
Config.uncurried := uncurried;
149+
res
150+
109151
let usage = "Usage: bsc <options> <files>\nOptions are:"
110152

111153
let ppf = Format.err_formatter
@@ -390,6 +432,9 @@ let buckle_script_flags : (string * Bsc_args.spec * string) array =
390432
"-dsource", set Clflags.dump_source,
391433
"*internal* print source";
392434

435+
"-reprint-source", string_call reprint_source_file,
436+
"*internal* transform the target ReScript file using PPXes provided, and print the transformed ReScript code to stdout";
437+
393438
"-format", string_call format_file,
394439
"*internal* Format as Res syntax";
395440

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
We've found a bug for you!
3+
/.../fixtures/UncurriedArgsNotApplied.res:3:15-21
4+
5+
1 │ let apply = (fn: (. unit) => option<int>) => fn(. ())
6+
2 │
7+
3 │ let _ = apply(Some(1))
8+
4 │
9+
10+
This value might need to be wrapped in a function that takes an extra
11+
parameter of type unit
12+
13+
Here's the original error message
14+
This has type: option<'a>
15+
But it's expected to have type: (. unit) => option<int>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
Warning number 11
3+
/.../fixtures/bigint_match_literal.res:3:3-4
4+
5+
1 │ let m1 = switch 1n {
6+
2 │ | 0001n => 1
7+
3 │ | 1n => 1
8+
4 │ | -0001n => -1
9+
5 │ | _ => 0
10+
11+
this match case is unused.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
We've found a bug for you!
3+
/.../fixtures/variant_coercion_bigint.res:5:10-20
4+
5+
3 │ let x = One(true)
6+
4 │
7+
5 │ let y = (x :> bigint)
8+
6 │
9+
10+
Type x is not a subtype of bigint
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
We've found a bug for you!
3+
/.../fixtures/variant_coercion_bigint_as.res:5:10-20
4+
5+
3 │ let x = One
6+
4 │
7+
5 │ let y = (x :> bigint)
8+
6 │
9+
10+
Type x is not a subtype of bigint

jscomp/build_tests/super_errors/expected/warnings4.res.expected

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010
14 │
1111

1212
You forgot to handle a possible case here, for example:
13-
| #second(_) | #fourth | #third
13+
| #second(_) | #fourth | #third

jscomp/build_tests/super_errors/expected/warnings5.res.expected

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,4 @@ Either bind these labels explicitly or add ', _' to the pattern.
187187
60 │
188188

189189
You forgot to handle a possible case here, for example:
190-
| (_, true)
190+
| (_, true)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
let apply = (fn: (. unit) => option<int>) => fn(. ())
2+
3+
let _ = apply(Some(1))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
let m1 = switch 1n {
2+
| 0001n => 1
3+
| 1n => 1
4+
| -0001n => -1
5+
| _ => 0
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
type x = | @as(1n) One(bool) | @as(2n) Two
2+
3+
let x = One(true)
4+
5+
let y = (x :> bigint)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
type x = | @as(1n) One | Two
2+
3+
let x = One
4+
5+
let y = (x :> bigint)

jscomp/core/js_analyzer.ml

+2
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ let rec eq_expression ({ expression_desc = x0 } : J.expression)
158158
| Undefined x -> y0 = Undefined x
159159
| Number (Int { i }) -> (
160160
match y0 with Number (Int { i = j }) -> i = j | _ -> false)
161+
| Number (BigInt {positive = p0; value = v0}) -> (
162+
match y0 with Number (BigInt {positive = p1; value = v1}) -> p0 = p1 && v0 = v1 | _ -> false)
161163
| Number (Float _) -> false
162164
(* begin match y0 with
163165
| Number (Float j) ->

jscomp/core/js_dump.ml

+1
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,7 @@ and expression_desc cxt ~(level : int) f x : cxt =
664664
Int32.to_string i
665665
(* check , js convention with ocaml lexical convention *)
666666
| Uint i -> Format.asprintf "%lu" i
667+
| BigInt {positive; value} -> Format.asprintf "%sn" (Bigint_utils.to_string positive value)
667668
in
668669
let need_paren =
669670
if s.[0] = '-' then level > 13

jscomp/core/js_exp_make.ml

+25
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,10 @@ let obj_int_tag_literal : t =
312312

313313
let int ?comment ?c i : t = { expression_desc = Number (Int { i; c }); comment }
314314

315+
let bigint ?comment sign i : t = { expression_desc = Number (BigInt {positive=sign; value=i}); comment}
316+
317+
let zero_bigint_literal : t = {expression_desc = Number (BigInt {positive=true; value="0"}); comment = None}
318+
315319
let small_int i : t =
316320
match i with
317321
| 0 -> zero_int_literal
@@ -803,11 +807,15 @@ let tag_type = function
803807
| Ast_untagged_variants.String s -> str s ~delim:DStarJ
804808
| Int i -> small_int i
805809
| Float f -> float f
810+
| BigInt i ->
811+
let sign, i = Bigint_utils.parse_bigint i in
812+
bigint sign i
806813
| Bool b -> bool b
807814
| Null -> nil
808815
| Undefined -> undefined
809816
| Untagged IntType -> str "number"
810817
| Untagged FloatType -> str "number"
818+
| Untagged BigintType -> str "bigint"
811819
| Untagged BooleanType -> str "boolean"
812820
| Untagged FunctionType -> str "function"
813821
| Untagged StringType -> str "string"
@@ -1253,6 +1261,23 @@ let rec int32_band ?comment (e1 : J.expression) (e2 : J.expression) :
12531261
(* let int32_bin ?comment op e1 e2 : J.expression = *)
12541262
(* {expression_desc = Int32_bin(op,e1, e2); comment} *)
12551263

1264+
let bigint_op ?comment op (e1: t) (e2: t) = bin ?comment op e1 e2
1265+
1266+
let bigint_comp (cmp : Lam_compat.comparison) ?comment (e0: t) (e1: t) =
1267+
bin ?comment (Lam_compile_util.jsop_of_comp cmp) e0 e1
1268+
1269+
let bigint_div ~checked ?comment (e0: t) (e1: t) =
1270+
if checked then
1271+
runtime_call Js_runtime_modules.bigint "div" [e0; e1]
1272+
else
1273+
bigint_op ?comment Div e0 e1
1274+
1275+
let bigint_mod ~checked ?comment (e0: t) (e1: t) =
1276+
if checked then
1277+
runtime_call Js_runtime_modules.bigint "mod_" [e0; e1]
1278+
else
1279+
bigint_op ?comment Mod e0 e1
1280+
12561281
(* TODO -- alpha conversion
12571282
remember to add parens..
12581283
*)

jscomp/core/js_exp_make.mli

+12
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ val uint32 : ?comment:string -> int32 -> t
111111

112112
val small_int : int -> t
113113

114+
val bigint : ?comment:string -> bool -> string -> t
115+
114116
val float : ?comment:string -> string -> t
115117

116118
(* val empty_string_literal : t *)
@@ -121,6 +123,8 @@ val zero_int_literal : t
121123
val zero_float_lit : t
122124
(* val obj_int_tag_literal : t *)
123125

126+
val zero_bigint_literal : t
127+
124128
val is_out : ?comment:string -> t -> t -> t
125129
(** [is_out e range] is equivalent to [e > range or e <0]
126130
@@ -272,6 +276,14 @@ val string_comp : Js_op.binop -> ?comment:string -> t -> t -> t
272276

273277
val float_comp : Lam_compat.comparison -> ?comment:string -> t -> t -> t
274278

279+
val bigint_op : ?comment: string -> Js_op.binop -> t -> t -> t
280+
281+
val bigint_comp : Lam_compat.comparison -> ?comment:string -> t -> t -> t
282+
283+
val bigint_div : checked:bool -> ?comment:string -> t -> t -> t
284+
285+
val bigint_mod : checked:bool -> ?comment:string -> t -> t -> t
286+
275287
val js_comp : Lam_compat.comparison -> ?comment:string -> t -> t -> t
276288

277289
val not : t -> t

jscomp/core/js_op.ml

+4
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ type binop =
4848
| Mul
4949
| Div
5050
| Mod
51+
| Pow
5152
| InstanceOf
5253

5354
(**
@@ -125,10 +126,13 @@ type 'a access = Getter | Setter
125126
(* literal char *)
126127
type float_lit = { f : string } [@@unboxed]
127128

129+
type bigint_lit = { positive: bool; value: string }
130+
128131
type number =
129132
| Float of float_lit
130133
| Int of { i : int32; c : int option }
131134
| Uint of int32
135+
| BigInt of bigint_lit
132136

133137
(* becareful when constant folding +/-,
134138
since we treat it as js nativeint, bitwise operators:

jscomp/core/js_op_util.ml

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ let op_prec (op : Js_op.binop) =
4040
| Band -> (7, 7, 7)
4141
| Lsl | Lsr | Asr -> (10, 10, 11)
4242
| Plus | Minus -> (11, 11, 12)
43-
| Mul | Div | Mod -> (12, 12, 13)
43+
| Mul | Div | Mod | Pow -> (12, 12, 13)
4444

4545
let op_int_prec (op : Js_op.int_op) =
4646
match op with
@@ -64,6 +64,7 @@ let op_str (op : Js_op.binop) =
6464
| Mul -> "*"
6565
| Div -> "/"
6666
| Mod -> "%"
67+
| Pow -> "**"
6768
| Eq -> "="
6869
| Or -> "||"
6970
| And -> "&&"

jscomp/core/js_stmt_make.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ let string_switch ?(comment : string option)
138138
match switch_case with
139139
| String s ->
140140
if s = txt then Some x.switch_body else None
141-
| Int _ | Float _| Bool _ | Null | Undefined | Untagged _ ->
141+
| Int _ | Float _ | BigInt _ | Bool _ | Null | Undefined | Untagged _ ->
142142
None)
143143
with
144144
| Some case -> case

jscomp/core/lam.ml

+2-1
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,7 @@ let prim ~primitive:(prim : Lam_primitive.t) ~args loc : t =
506506
(* FIXME: could raise? *)
507507
Lift.bool
508508
(Lam_compat.cmp_float cmp (float_of_string a) (float_of_string b))
509+
| Pbigintcomp cmp, Const_bigint _, Const_bigint _ -> default ()
509510
| Pintcomp ((Ceq | Cneq) as op), Const_pointer a, Const_pointer b ->
510511
Lift.bool
511512
(match op with
@@ -641,7 +642,7 @@ let rec eval_const_as_bool (v : Lam_constant.t) : bool =
641642
| Const_int64 x -> x <> 0L
642643
| Const_js_false | Const_js_null | Const_module_alias | Const_js_undefined _ ->
643644
false
644-
| Const_js_true | Const_string _ | Const_pointer _ | Const_float _
645+
| Const_js_true | Const_string _ | Const_pointer _ | Const_float _ | Const_bigint _
645646
| Const_block _ | Const_float_array _ ->
646647
true
647648
| Const_some b -> eval_const_as_bool b

jscomp/core/lam_analysis.ml

+6-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ let not_zero_constant (x : Lam_constant.t) =
2727
match x with
2828
| Const_int { i } -> i <> 0l
2929
| Const_int64 i -> i <> 0L
30+
| Const_bigint (_, i) -> i <> "0"
3031
| _ -> false
3132

3233
let rec no_side_effects (lam : Lam.t) : bool =
@@ -53,7 +54,7 @@ let rec no_side_effects (lam : Lam.t) : bool =
5354
_ ) ->
5455
true
5556
| _, _ -> false)
56-
| Pmodint | Pdivint | Pdivint64 | Pmodint64 -> (
57+
| Pmodint | Pdivint | Pdivint64 | Pmodint64 | Pdivbigint | Pmodbigint -> (
5758
match args with
5859
| [ _; Lconst cst ] -> not_zero_constant cst
5960
| _ -> false)
@@ -76,6 +77,9 @@ let rec no_side_effects (lam : Lam.t) : bool =
7677
| Pintoffloat | Pfloatofint | Pnegfloat
7778
(* | Pabsfloat *)
7879
| Paddfloat | Psubfloat | Pmulfloat | Pdivfloat | Pfloatcomp _ | Pjscomp _
80+
| Pnegbigint | Paddbigint | Psubbigint | Pmulbigint | Ppowbigint
81+
| Pandbigint | Porbigint | Pxorbigint | Plslbigint | Pasrbigint
82+
| Pbigintcomp _
7983
(* String operations *)
8084
| Pstringlength | Pstringrefu | Pstringrefs | Pbyteslength | Pbytesrefu
8185
| Pbytesrefs | Pmakearray | Parraylength | Parrayrefu | Parrayrefs
@@ -193,7 +197,7 @@ let rec size (lam : Lam.t) =
193197

194198
and size_constant x =
195199
match x with
196-
| Const_int _ | Const_char _ | Const_float _ | Const_int64 _ | Const_pointer _
200+
| Const_int _ | Const_char _ | Const_float _ | Const_int64 _ | Const_bigint _ | Const_pointer _
197201
| Const_js_null | Const_js_undefined _ | Const_module_alias | Const_js_true
198202
| Const_js_false ->
199203
1

0 commit comments

Comments
 (0)