Skip to content

Commit aca77bd

Browse files
authored
Merge branch 'master' into rewatch-cli-refactor
2 parents 7742361 + 75afc52 commit aca77bd

File tree

89 files changed

+589
-347
lines changed

Some content is hidden

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

89 files changed

+589
-347
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ jobs:
450450
if: ${{ matrix.generate_api_docs }}
451451
uses: actions/upload-artifact@v4
452452
with:
453-
name: api-docs
453+
name: api
454454
path: scripts/res/apiDocs/
455455

456456
pkg-pr-new:
@@ -495,11 +495,12 @@ jobs:
495495
uses: actions/download-artifact@v4
496496
with:
497497
artifact-ids: ${{ needs.build-compiler.outputs.api-docs-artifact-id }}
498-
path: data/api
498+
path: data
499499

500500
- name: Check if repo is clean
501501
id: diffcheck
502502
run: |
503+
git status
503504
if [ -z "$(git status --porcelain)" ]; then
504505
echo "clean=true" >> $GITHUB_OUTPUT
505506
else

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,23 @@
1010
> - :house: [Internal]
1111
> - :nail_care: [Polish]
1212
13+
# 12.0.0-alpha.15 (Unreleased)
14+
15+
#### :bug: Bug fix
16+
17+
- Ignore inferred arity in functions inside `%raw` functions, leaving to `%ffi` the responsibility to check the arity since it gives an error in case of mismatch. https://github.com/rescript-lang/rescript/pull/7542
18+
- Pass the rewatch exit code through in wrapper script. https://github.com/rescript-lang/rescript/pull/7565
19+
- Prop punning when types don't match results in I/O error: _none_: No such file or directory. https://github.com/rescript-lang/rescript/pull/7533
20+
- Pass location to children prop in jsx ppx. https://github.com/rescript-lang/rescript/pull/7540
21+
22+
#### :nail_care: Polish
23+
24+
- Better error message for when trying to await something that is not a promise. https://github.com/rescript-lang/rescript/pull/7561
25+
26+
#### :house: Internal
27+
28+
- Remove `@return(undefined_to_opt)` and `%undefined_to_opt` primitive. https://github.com/rescript-lang/rescript/pull/7462
29+
1330
# 12.0.0-alpha.14
1431

1532
#### :boom: Breaking Change

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Happy hacking!
1414

1515
> Most of our contributors are working on Apple machines, so all our instructions are currently macOS / Linux centric. Contributions for Windows development welcome!
1616
17-
- [Node.js](https://nodejs.org/) v20.x
17+
- [Node.js](https://nodejs.org/) v22.x
1818
- [Yarn CLI](https://yarnpkg.com/getting-started/install) (can be installed with `corepack`, Homebrew, etc)
1919
- C compiler toolchain (usually installed with `xcode` on Mac)
2020
- Python <= 3.11 (required to build ninja)

compiler/common/bs_version.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@
2121
* You should have received a copy of the GNU Lesser General Public License
2222
* along with this program; if not, write to the Free Software
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
24-
let version = "12.0.0-alpha.14"
24+
let version = "12.0.0-alpha.15"
2525
let header = "// Generated by ReScript, PLEASE EDIT WITH CARE"
2626
let package_name = ref "rescript"

compiler/core/lam.ml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,8 @@ let rec apply ?(ap_transformed_jsx = false) fn args (ap_info : ap_info) : t =
298298
Lprim
299299
{
300300
primitive =
301-
( Pundefined_to_opt | Pnull_to_opt | Pnull_undefined_to_opt
302-
| Pis_null | Pis_null_undefined | Ptypeof ) as wrap;
301+
( Pnull_to_opt | Pnull_undefined_to_opt | Pis_null
302+
| Pis_null_undefined | Ptypeof ) as wrap;
303303
args =
304304
[Lprim ({primitive = _; args = inner_args} as primitive_call)];
305305
};
@@ -442,11 +442,7 @@ let rec seq (a : t) b : t =
442442
match a with
443443
| Lprim {primitive = Pmakeblock _; args = x :: xs} ->
444444
seq (Ext_list.fold_left xs x seq) b
445-
| Lprim
446-
{
447-
primitive = Pnull_to_opt | Pundefined_to_opt | Pnull_undefined_to_opt;
448-
args = [a];
449-
} ->
445+
| Lprim {primitive = Pnull_to_opt | Pnull_undefined_to_opt; args = [a]} ->
450446
seq a b
451447
| _ -> Lsequence (a, b)
452448

@@ -719,8 +715,6 @@ let result_wrap loc (result_type : External_ffi_types.return_wrapper) result =
719715
| Return_null_to_opt -> prim ~primitive:Pnull_to_opt ~args:[result] loc
720716
| Return_null_undefined_to_opt ->
721717
prim ~primitive:Pnull_undefined_to_opt ~args:[result] loc
722-
| Return_undefined_to_opt ->
723-
prim ~primitive:Pundefined_to_opt ~args:[result] loc
724718
| Return_unset | Return_identity -> result
725719

726720
let handle_bs_non_obj_ffi ?(transformed_jsx = false)

compiler/core/lam_analysis.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ let rec no_side_effects (lam : Lam.t) : bool =
4646
| _ -> false)
4747
| Pcreate_extension _ | Ptypeof | Pis_null | Pis_not_none | Psome
4848
| Psome_not_nest | Pis_undefined | Pis_null_undefined | Pnull_to_opt
49-
| Pundefined_to_opt | Pnull_undefined_to_opt | Pjs_fn_make _
50-
| Pjs_fn_make_unit | Pjs_object_create _ | Pimport
49+
| Pnull_undefined_to_opt | Pjs_fn_make _ | Pjs_fn_make_unit
50+
| Pjs_object_create _ | Pimport
5151
(* TODO: check *)
5252
| Pmakeblock _
5353
(* whether it's mutable or not *)

compiler/core/lam_arity_analysis.ml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@ let rec get_arity (meta : Lam_stats.t) (lam : Lam.t) : Lam_arity.t =
6969
with
7070
| Submodule subs -> subs.(m) (* TODO: shall we store it as array?*)
7171
| Single _ -> Lam_arity.na)
72-
| Lprim {primitive = Praw_js_code {code_info = Exp (Js_function {arity})}} ->
73-
Lam_arity.info [arity] false
7472
| Lprim {primitive = Praise; _} -> Lam_arity.raise_arity_info
7573
| Lglobal_module _ (* TODO: fix me never going to happen *) | Lprim _ ->
7674
Lam_arity.na (* CHECK*)

compiler/core/lam_compile_primitive.ml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,6 @@ let translate output_prefix loc (cxt : Lam_compile_context.t)
9595
| Var _ | Undefined _ | Null -> Js_of_lam_option.null_to_opt e
9696
| _ -> E.runtime_call Primitive_modules.option "fromNull" args)
9797
| _ -> assert false)
98-
| Pundefined_to_opt -> (
99-
match args with
100-
| [e] -> (
101-
match e.expression_desc with
102-
| Var _ | Undefined _ | Null -> Js_of_lam_option.undef_to_opt e
103-
| _ -> E.runtime_call Primitive_modules.option "fromUndefined" args)
104-
| _ -> assert false)
10598
| Pnull_undefined_to_opt -> (
10699
match args with
107100
| [e] -> (

compiler/core/lam_convert.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ let lam_prim ~primitive:(p : Lambda.primitive) ~args loc : Lam.t =
197197
| Pisnullable -> prim ~primitive:Pis_null_undefined ~args loc
198198
| Pnull_to_opt -> prim ~primitive:Pnull_to_opt ~args loc
199199
| Pnullable_to_opt -> prim ~primitive:Pnull_undefined_to_opt ~args loc
200-
| Pundefined_to_opt -> prim ~primitive:Pundefined_to_opt ~args loc
201200
| Pis_not_none -> prim ~primitive:Pis_not_none ~args loc
202201
| Pval_from_option -> prim ~primitive:Pval_from_option ~args loc
203202
| Pval_from_option_not_nest ->

compiler/core/lam_pass_collect.ml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,8 @@ let collect_info (meta : Lam_stats.t) (lam : Lam.t) =
6464
| Lprim {primitive = Psome | Psome_not_nest; args = [v]} ->
6565
Hash_ident.replace meta.ident_tbl ident (Normal_optional v);
6666
collect v
67-
| Lprim
68-
{
69-
primitive = Praw_js_code {code_info = Exp (Js_function {arity})};
70-
args = _;
71-
} ->
72-
Hash_ident.replace meta.ident_tbl ident
73-
(FunctionId {arity = Lam_arity.info [arity] false; lambda = None})
7467
| Lprim {primitive = Pnull_to_opt; args = [(Lvar _ as l)]; _} ->
7568
Hash_ident.replace meta.ident_tbl ident (OptionalBlock (l, Null))
76-
| Lprim {primitive = Pundefined_to_opt; args = [(Lvar _ as l)]; _} ->
77-
Hash_ident.replace meta.ident_tbl ident (OptionalBlock (l, Undefined))
7869
| Lprim {primitive = Pnull_undefined_to_opt; args = [(Lvar _ as l)]} ->
7970
Hash_ident.replace meta.ident_tbl ident
8071
(OptionalBlock (l, Null_undefined))

compiler/core/lam_pass_deep_flatten.ml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,7 @@ let deep_flatten (lam : Lam.t) : Lam.t =
123123
id,
124124
(Lprim
125125
{
126-
primitive =
127-
Pnull_to_opt | Pundefined_to_opt | Pnull_undefined_to_opt;
126+
primitive = Pnull_to_opt | Pnull_undefined_to_opt;
128127
args = [Lvar _];
129128
} as arg),
130129
body ) ->
@@ -134,9 +133,7 @@ let deep_flatten (lam : Lam.t) : Lam.t =
134133
id,
135134
Lprim
136135
{
137-
primitive =
138-
(Pnull_to_opt | Pundefined_to_opt | Pnull_undefined_to_opt) as
139-
primitive;
136+
primitive = (Pnull_to_opt | Pnull_undefined_to_opt) as primitive;
140137
args = [arg];
141138
},
142139
body ) ->

compiler/core/lam_primitive.ml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ type t =
161161
play safe first
162162
*)
163163
| Pjs_fn_method
164-
| Pundefined_to_opt
165164
| Pnull_to_opt
166165
| Pnull_undefined_to_opt
167166
| Pis_null
@@ -224,12 +223,12 @@ let eq_primitive_approx (lhs : t) (rhs : t) =
224223
| Pawait
225224
(* etc *)
226225
| Pjs_apply | Pjs_runtime_apply | Pval_from_option | Pval_from_option_not_nest
227-
| Pundefined_to_opt | Pnull_to_opt | Pnull_undefined_to_opt | Pis_null
228-
| Pis_not_none | Psome | Psome_not_nest | Pis_undefined | Pis_null_undefined
229-
| Pimport | Ptypeof | Pfn_arity | Pis_poly_var_block | Pdebugger | Pinit_mod
230-
| Pupdate_mod | Pduprecord | Pmakearray | Parraylength | Parrayrefu
231-
| Parraysetu | Parrayrefs | Parraysets | Pjs_fn_make_unit | Pjs_fn_method
232-
| Phash | Phash_mixstring | Phash_mixint | Phash_finalmix ->
226+
| Pnull_to_opt | Pnull_undefined_to_opt | Pis_null | Pis_not_none | Psome
227+
| Psome_not_nest | Pis_undefined | Pis_null_undefined | Pimport | Ptypeof
228+
| Pfn_arity | Pis_poly_var_block | Pdebugger | Pinit_mod | Pupdate_mod
229+
| Pduprecord | Pmakearray | Parraylength | Parrayrefu | Parraysetu
230+
| Parrayrefs | Parraysets | Pjs_fn_make_unit | Pjs_fn_method | Phash
231+
| Phash_mixstring | Phash_mixint | Phash_finalmix ->
233232
rhs = lhs
234233
| Pcreate_extension a -> (
235234
match rhs with

compiler/core/lam_primitive.mli

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ type t =
152152
| Pjs_fn_make of int
153153
| Pjs_fn_make_unit
154154
| Pjs_fn_method
155-
| Pundefined_to_opt
156155
| Pnull_to_opt
157156
| Pnull_undefined_to_opt
158157
| Pis_null

compiler/core/lam_print.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ let primitive ppf (prim : Lam_primitive.t) =
6161
| Praw_js_code _ -> fprintf ppf "[raw]"
6262
| Ptypeof -> fprintf ppf "typeof"
6363
| Pnull_to_opt -> fprintf ppf "[null->opt]"
64-
| Pundefined_to_opt -> fprintf ppf "[undefined->opt]"
6564
| Pnull_undefined_to_opt -> fprintf ppf "[null/undefined->opt]"
6665
| Pis_null -> fprintf ppf "[?null]"
6766
| Pis_not_none -> fprintf ppf "[?is-not-none]"

compiler/frontend/ast_attributes.ml

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -279,24 +279,6 @@ let set : attr = ({txt = "set"; loc = locg}, Ast_payload.empty)
279279
let internal_expansive : attr =
280280
({txt = "internal.expansive"; loc = locg}, Ast_payload.empty)
281281

282-
let bs_return_undefined : attr =
283-
( {txt = "return"; loc = locg},
284-
PStr
285-
[
286-
{
287-
pstr_desc =
288-
Pstr_eval
289-
( {
290-
pexp_desc =
291-
Pexp_ident {txt = Lident "undefined_to_opt"; loc = locg};
292-
pexp_loc = locg;
293-
pexp_attributes = [];
294-
},
295-
[] );
296-
pstr_loc = locg;
297-
};
298-
] )
299-
300282
let is_gentype (attr : attr) =
301283
match attr with
302284
| {Location.txt = "genType" | "gentype"; _}, _ -> true

compiler/frontend/ast_attributes.mli

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ val get_index : attr
5959

6060
val set : attr
6161

62-
val bs_return_undefined : attr
63-
6462
val internal_expansive : attr
6563
(* val deprecated : string -> attr *)
6664

compiler/frontend/ast_derive_abstract.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ let is_abstract (xs : Ast_payload.action list) =
5454
(** For this attributes, its type was wrapped as an option,
5555
so we can still reuse existing frame work
5656
*)
57-
let get_optional_attrs =
58-
[Ast_attributes.get; Ast_attributes.bs_return_undefined]
57+
let get_optional_attrs = [Ast_attributes.get]
5958

6059
let get_attrs = []
6160

compiler/frontend/ast_external_process.ml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ let init_st =
190190

191191
let return_wrapper loc (txt : string) : External_ffi_types.return_wrapper =
192192
match txt with
193-
| "undefined_to_opt" -> Return_undefined_to_opt
194193
| "null_to_opt" -> Return_null_to_opt
195194
| "nullable" | "null_undefined_to_opt" -> Return_null_undefined_to_opt
196195
| "identity" -> Return_identity
@@ -395,8 +394,7 @@ let check_return_wrapper loc (wrapper : External_ffi_types.return_wrapper)
395394
| Return_unset ->
396395
if Ast_core_type.is_unit result_type then Return_replaced_with_unit
397396
else wrapper
398-
| Return_undefined_to_opt | Return_null_to_opt | Return_null_undefined_to_opt
399-
->
397+
| Return_null_to_opt | Return_null_undefined_to_opt ->
400398
if Ast_core_type.is_user_option result_type then wrapper
401399
else Bs_syntaxerr.err loc Expect_opt_in_bs_return_to_opt
402400
| Return_replaced_with_unit -> assert false

compiler/frontend/external_ffi_types.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ type external_spec =
9898
type return_wrapper =
9999
| Return_unset
100100
| Return_identity
101-
| Return_undefined_to_opt
102101
| Return_null_to_opt
103102
| Return_null_undefined_to_opt
104103
| Return_replaced_with_unit

compiler/frontend/external_ffi_types.mli

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ type external_spec =
7474
type return_wrapper =
7575
| Return_unset
7676
| Return_identity
77-
| Return_undefined_to_opt
7877
| Return_null_to_opt
7978
| Return_null_undefined_to_opt
8079
| Return_replaced_with_unit

compiler/ml/ast_await.ml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,25 @@ let create_await_expression (e : Parsetree.expression) =
99
in
1010
Ast_helper.Exp.apply ~loc unsafe_await [(Nolabel, e)]
1111

12+
let is_await_expr (e : Parsetree.expression) =
13+
match e with
14+
| {
15+
pexp_loc = {loc_ghost = true};
16+
pexp_desc =
17+
Pexp_apply
18+
{
19+
funct =
20+
{
21+
pexp_loc = {loc_ghost = true};
22+
pexp_desc = Pexp_ident {txt = Ldot (Lident ident, "unsafe_await")};
23+
};
24+
args = [(Nolabel, _)];
25+
};
26+
}
27+
when ident = Primitive_modules.promise ->
28+
true
29+
| _ -> false
30+
1231
(* Transform `@res.await M` to unpack(@res.await Js.import(module(M: __M0__))) *)
1332
let create_await_module_expression ~module_type_lid (e : Parsetree.module_expr)
1433
=

compiler/ml/error_message_utils.ml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ type type_clash_context =
102102
| FunctionArgument of {optional: bool; name: string option}
103103
| Statement of type_clash_statement
104104
| ForLoopCondition
105+
| Await
105106
106107
let context_to_string = function
107108
| Some WhileCondition -> "WhileCondition"
@@ -120,6 +121,7 @@ let context_to_string = function
120121
| Some (FunctionArgument _) -> "FunctionArgument"
121122
| Some ComparisonOperator -> "ComparisonOperator"
122123
| Some IfReturn -> "IfReturn"
124+
| Some Await -> "Await"
123125
| None -> "None"
124126
125127
let fprintf = Format.fprintf
@@ -185,6 +187,10 @@ let error_expected_type_text ppf type_clash_context =
185187
"But it's being used with the @{<info>%s@} operator, which works on:"
186188
operator
187189
| Some StringConcat -> fprintf ppf "But string concatenation is expecting:"
190+
| Some Await ->
191+
fprintf ppf
192+
"But you're using @{<info>await@} on this expression, so it is expected \
193+
to be of type:"
188194
| Some MaybeUnwrapOption | None ->
189195
fprintf ppf "But it's expected to have type:"
190196
@@ -282,6 +288,14 @@ let print_extra_type_clash_help ~extract_concrete_typedecl ~env loc ppf
282288
"\n\n\
283289
\ To fix this, change the highlighted code so it evaluates to a \
284290
@{<info>bool@}."
291+
| Some Await, _ ->
292+
fprintf ppf
293+
"\n\n\
294+
\ You're trying to await something that is not a promise.\n\n\
295+
Possible solutions:\n\
296+
\ - Remove the @{<info>await@} if this is not expected to be a promise\n\
297+
\ - Wrap the expression in @{<info>Promise.resolve@} to convert the \
298+
expression to a promise"
285299
| Some IfReturn, _ ->
286300
fprintf ppf
287301
"\n\n\
@@ -533,7 +547,7 @@ let type_clash_context_from_function sexp sfunct =
533547
Some (MathOperator {for_float = true; operator; is_constant})
534548
| Pexp_ident {txt = Lident (("/" | "*" | "+" | "-") as operator)} ->
535549
Some (MathOperator {for_float = false; operator; is_constant})
536-
| _ -> None
550+
| _ -> if Ast_await.is_await_expr sexp then Some Await else None
537551
538552
let type_clash_context_for_function_argument ~label type_clash_context sarg0 =
539553
match type_clash_context with

compiler/ml/lambda.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,6 @@ type primitive =
295295
(* js *)
296296
| Pcurry_apply of int
297297
| Pjscomp of comparison
298-
| Pundefined_to_opt
299298
| Pnull_to_opt
300299
| Pnullable_to_opt
301300
| Pis_not_none

compiler/ml/lambda.mli

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,6 @@ type primitive =
264264
(* js *)
265265
| Pcurry_apply of int
266266
| Pjscomp of comparison
267-
| Pundefined_to_opt
268267
| Pnull_to_opt
269268
| Pnullable_to_opt
270269
| Pis_not_none

0 commit comments

Comments
 (0)