Skip to content

Commit 6e106e9

Browse files
committed
Mark async/await as experimental.
1 parent 68a3f5c commit 6e106e9

File tree

4 files changed

+100
-82
lines changed

4 files changed

+100
-82
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
#### :rocket: New Feature
2020

21-
- Add support for for `async`/`await` https://github.com/rescript-lang/rescript-compiler/pull/5537
21+
- Experimental support for for `async`/`await` https://github.com/rescript-lang/rescript-compiler/pull/5537
2222

2323
- Make `promise` a built-in type https://github.com/rescript-lang/rescript-compiler/pull/5650
2424

lib/4.06.1/unstable/js_compiler.ml

+33-27
Original file line numberDiff line numberDiff line change
@@ -40818,33 +40818,39 @@ and type_expect ?in_function ?recarg env sexp ty_expected =
4081840818
(Cmt_format.Partial_expression exp :: previous_saved_types);
4081940819
exp
4082040820

40821-
and checkTypeInvariant exp =
40822-
let rec extractPromise t =
40823-
match t.desc with
40824-
| Tconstr (Pdot (Pdot (Pident {name = "Js"}, "Promise", _), "t", _), [t1], _)
40825-
| Tconstr (Pident {name = "promise"}, [t1], _)
40826-
->
40827-
Some t1
40828-
| Tlink t1 | Tsubst t1 | Tpoly (t1, []) -> extractPromise t1
40829-
| _ -> None
40830-
in
40831-
let rec findNestedPromise t =
40832-
match t.desc with
40833-
| Tlink t1 | Tsubst t1 | Tpoly (t1, []) -> findNestedPromise t1
40834-
| Tconstr (_, ts, _) -> (
40835-
match extractPromise t with
40836-
| Some t1 -> (
40837-
match extractPromise t1 with
40838-
| Some _t2 ->
40839-
let nestedType = Format.asprintf "%a" Printtyp.type_expr t in
40840-
Location.prerr_warning exp.exp_loc (Bs_nested_promise nestedType)
40841-
| None -> ts |> List.iter findNestedPromise)
40842-
| None -> ts |> List.iter findNestedPromise)
40843-
| Tarrow (_, t1, t2, _) ->
40844-
findNestedPromise t1;
40845-
findNestedPromise t2
40846-
| _ -> ()
40847-
in findNestedPromise exp.exp_type
40821+
(* NOTE: the type invariant check should have no side effects and be efficient *)
40822+
and checkTypeInvariant exp : unit =
40823+
let rec extractPromise t =
40824+
match t.desc with
40825+
| Tconstr
40826+
(Pdot (Pdot (Pident { name = "Js" }, "Promise", _), "t", _), [ t1 ], _)
40827+
| Tconstr (Pident { name = "promise" }, [ t1 ], _) ->
40828+
(* Improvement: check for type aliases, if it can be done efficiently *)
40829+
Some t1
40830+
| Tlink t1 | Tsubst t1 | Tpoly (t1, []) -> extractPromise t1
40831+
| _ -> None
40832+
in
40833+
(* Only traverse arguments of a type constructors and function types.
40834+
This should guarantee that the traversal finished quickly. *)
40835+
let rec findNestedPromise t =
40836+
match t.desc with
40837+
| Tlink t1 | Tsubst t1 | Tpoly (t1, []) -> findNestedPromise t1
40838+
| Tconstr (_, ts, _) -> (
40839+
match extractPromise t with
40840+
| Some t1 -> (
40841+
match extractPromise t1 with
40842+
| Some _t2 ->
40843+
let nestedType = Format.asprintf "%a" Printtyp.type_expr t in
40844+
Location.prerr_warning exp.exp_loc
40845+
(Bs_nested_promise nestedType)
40846+
| None -> ts |> List.iter findNestedPromise)
40847+
| None -> ts |> List.iter findNestedPromise)
40848+
| Tarrow (_, t1, t2, _) ->
40849+
findNestedPromise t1;
40850+
findNestedPromise t2
40851+
| _ -> ()
40852+
in
40853+
findNestedPromise exp.exp_type
4084840854

4084940855
and type_expect_ ?in_function ?(recarg=Rejected) env sexp ty_expected =
4085040856
let loc = sexp.pexp_loc in

lib/4.06.1/unstable/js_playground_compiler.ml

+33-27
Original file line numberDiff line numberDiff line change
@@ -40818,33 +40818,39 @@ and type_expect ?in_function ?recarg env sexp ty_expected =
4081840818
(Cmt_format.Partial_expression exp :: previous_saved_types);
4081940819
exp
4082040820

40821-
and checkTypeInvariant exp =
40822-
let rec extractPromise t =
40823-
match t.desc with
40824-
| Tconstr (Pdot (Pdot (Pident {name = "Js"}, "Promise", _), "t", _), [t1], _)
40825-
| Tconstr (Pident {name = "promise"}, [t1], _)
40826-
->
40827-
Some t1
40828-
| Tlink t1 | Tsubst t1 | Tpoly (t1, []) -> extractPromise t1
40829-
| _ -> None
40830-
in
40831-
let rec findNestedPromise t =
40832-
match t.desc with
40833-
| Tlink t1 | Tsubst t1 | Tpoly (t1, []) -> findNestedPromise t1
40834-
| Tconstr (_, ts, _) -> (
40835-
match extractPromise t with
40836-
| Some t1 -> (
40837-
match extractPromise t1 with
40838-
| Some _t2 ->
40839-
let nestedType = Format.asprintf "%a" Printtyp.type_expr t in
40840-
Location.prerr_warning exp.exp_loc (Bs_nested_promise nestedType)
40841-
| None -> ts |> List.iter findNestedPromise)
40842-
| None -> ts |> List.iter findNestedPromise)
40843-
| Tarrow (_, t1, t2, _) ->
40844-
findNestedPromise t1;
40845-
findNestedPromise t2
40846-
| _ -> ()
40847-
in findNestedPromise exp.exp_type
40821+
(* NOTE: the type invariant check should have no side effects and be efficient *)
40822+
and checkTypeInvariant exp : unit =
40823+
let rec extractPromise t =
40824+
match t.desc with
40825+
| Tconstr
40826+
(Pdot (Pdot (Pident { name = "Js" }, "Promise", _), "t", _), [ t1 ], _)
40827+
| Tconstr (Pident { name = "promise" }, [ t1 ], _) ->
40828+
(* Improvement: check for type aliases, if it can be done efficiently *)
40829+
Some t1
40830+
| Tlink t1 | Tsubst t1 | Tpoly (t1, []) -> extractPromise t1
40831+
| _ -> None
40832+
in
40833+
(* Only traverse arguments of a type constructors and function types.
40834+
This should guarantee that the traversal finished quickly. *)
40835+
let rec findNestedPromise t =
40836+
match t.desc with
40837+
| Tlink t1 | Tsubst t1 | Tpoly (t1, []) -> findNestedPromise t1
40838+
| Tconstr (_, ts, _) -> (
40839+
match extractPromise t with
40840+
| Some t1 -> (
40841+
match extractPromise t1 with
40842+
| Some _t2 ->
40843+
let nestedType = Format.asprintf "%a" Printtyp.type_expr t in
40844+
Location.prerr_warning exp.exp_loc
40845+
(Bs_nested_promise nestedType)
40846+
| None -> ts |> List.iter findNestedPromise)
40847+
| None -> ts |> List.iter findNestedPromise)
40848+
| Tarrow (_, t1, t2, _) ->
40849+
findNestedPromise t1;
40850+
findNestedPromise t2
40851+
| _ -> ()
40852+
in
40853+
findNestedPromise exp.exp_type
4084840854

4084940855
and type_expect_ ?in_function ?(recarg=Rejected) env sexp ty_expected =
4085040856
let loc = sexp.pexp_loc in

lib/4.06.1/whole_compiler.ml

+33-27
Original file line numberDiff line numberDiff line change
@@ -217205,33 +217205,39 @@ and type_expect ?in_function ?recarg env sexp ty_expected =
217205217205
(Cmt_format.Partial_expression exp :: previous_saved_types);
217206217206
exp
217207217207

217208-
and checkTypeInvariant exp =
217209-
let rec extractPromise t =
217210-
match t.desc with
217211-
| Tconstr (Pdot (Pdot (Pident {name = "Js"}, "Promise", _), "t", _), [t1], _)
217212-
| Tconstr (Pident {name = "promise"}, [t1], _)
217213-
->
217214-
Some t1
217215-
| Tlink t1 | Tsubst t1 | Tpoly (t1, []) -> extractPromise t1
217216-
| _ -> None
217217-
in
217218-
let rec findNestedPromise t =
217219-
match t.desc with
217220-
| Tlink t1 | Tsubst t1 | Tpoly (t1, []) -> findNestedPromise t1
217221-
| Tconstr (_, ts, _) -> (
217222-
match extractPromise t with
217223-
| Some t1 -> (
217224-
match extractPromise t1 with
217225-
| Some _t2 ->
217226-
let nestedType = Format.asprintf "%a" Printtyp.type_expr t in
217227-
Location.prerr_warning exp.exp_loc (Bs_nested_promise nestedType)
217228-
| None -> ts |> List.iter findNestedPromise)
217229-
| None -> ts |> List.iter findNestedPromise)
217230-
| Tarrow (_, t1, t2, _) ->
217231-
findNestedPromise t1;
217232-
findNestedPromise t2
217233-
| _ -> ()
217234-
in findNestedPromise exp.exp_type
217208+
(* NOTE: the type invariant check should have no side effects and be efficient *)
217209+
and checkTypeInvariant exp : unit =
217210+
let rec extractPromise t =
217211+
match t.desc with
217212+
| Tconstr
217213+
(Pdot (Pdot (Pident { name = "Js" }, "Promise", _), "t", _), [ t1 ], _)
217214+
| Tconstr (Pident { name = "promise" }, [ t1 ], _) ->
217215+
(* Improvement: check for type aliases, if it can be done efficiently *)
217216+
Some t1
217217+
| Tlink t1 | Tsubst t1 | Tpoly (t1, []) -> extractPromise t1
217218+
| _ -> None
217219+
in
217220+
(* Only traverse arguments of a type constructors and function types.
217221+
This should guarantee that the traversal finished quickly. *)
217222+
let rec findNestedPromise t =
217223+
match t.desc with
217224+
| Tlink t1 | Tsubst t1 | Tpoly (t1, []) -> findNestedPromise t1
217225+
| Tconstr (_, ts, _) -> (
217226+
match extractPromise t with
217227+
| Some t1 -> (
217228+
match extractPromise t1 with
217229+
| Some _t2 ->
217230+
let nestedType = Format.asprintf "%a" Printtyp.type_expr t in
217231+
Location.prerr_warning exp.exp_loc
217232+
(Bs_nested_promise nestedType)
217233+
| None -> ts |> List.iter findNestedPromise)
217234+
| None -> ts |> List.iter findNestedPromise)
217235+
| Tarrow (_, t1, t2, _) ->
217236+
findNestedPromise t1;
217237+
findNestedPromise t2
217238+
| _ -> ()
217239+
in
217240+
findNestedPromise exp.exp_type
217235217241

217236217242
and type_expect_ ?in_function ?(recarg=Rejected) env sexp ty_expected =
217237217243
let loc = sexp.pexp_loc in

0 commit comments

Comments
 (0)