Skip to content

Commit

Permalink
Mark async/await as experimental.
Browse files Browse the repository at this point in the history
  • Loading branch information
cristianoc committed Sep 9, 2022
1 parent 68a3f5c commit 6e106e9
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 82 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#### :rocket: New Feature

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

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

Expand Down
60 changes: 33 additions & 27 deletions lib/4.06.1/unstable/js_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -40818,33 +40818,39 @@ and type_expect ?in_function ?recarg env sexp ty_expected =
(Cmt_format.Partial_expression exp :: previous_saved_types);
exp

and checkTypeInvariant exp =
let rec extractPromise t =
match t.desc with
| Tconstr (Pdot (Pdot (Pident {name = "Js"}, "Promise", _), "t", _), [t1], _)
| Tconstr (Pident {name = "promise"}, [t1], _)
->
Some t1
| Tlink t1 | Tsubst t1 | Tpoly (t1, []) -> extractPromise t1
| _ -> None
in
let rec findNestedPromise t =
match t.desc with
| Tlink t1 | Tsubst t1 | Tpoly (t1, []) -> findNestedPromise t1
| Tconstr (_, ts, _) -> (
match extractPromise t with
| Some t1 -> (
match extractPromise t1 with
| Some _t2 ->
let nestedType = Format.asprintf "%a" Printtyp.type_expr t in
Location.prerr_warning exp.exp_loc (Bs_nested_promise nestedType)
| None -> ts |> List.iter findNestedPromise)
| None -> ts |> List.iter findNestedPromise)
| Tarrow (_, t1, t2, _) ->
findNestedPromise t1;
findNestedPromise t2
| _ -> ()
in findNestedPromise exp.exp_type
(* NOTE: the type invariant check should have no side effects and be efficient *)
and checkTypeInvariant exp : unit =
let rec extractPromise t =
match t.desc with
| Tconstr
(Pdot (Pdot (Pident { name = "Js" }, "Promise", _), "t", _), [ t1 ], _)
| Tconstr (Pident { name = "promise" }, [ t1 ], _) ->
(* Improvement: check for type aliases, if it can be done efficiently *)
Some t1
| Tlink t1 | Tsubst t1 | Tpoly (t1, []) -> extractPromise t1
| _ -> None
in
(* Only traverse arguments of a type constructors and function types.
This should guarantee that the traversal finished quickly. *)
let rec findNestedPromise t =
match t.desc with
| Tlink t1 | Tsubst t1 | Tpoly (t1, []) -> findNestedPromise t1
| Tconstr (_, ts, _) -> (
match extractPromise t with
| Some t1 -> (
match extractPromise t1 with
| Some _t2 ->
let nestedType = Format.asprintf "%a" Printtyp.type_expr t in
Location.prerr_warning exp.exp_loc
(Bs_nested_promise nestedType)
| None -> ts |> List.iter findNestedPromise)
| None -> ts |> List.iter findNestedPromise)
| Tarrow (_, t1, t2, _) ->
findNestedPromise t1;
findNestedPromise t2
| _ -> ()
in
findNestedPromise exp.exp_type

and type_expect_ ?in_function ?(recarg=Rejected) env sexp ty_expected =
let loc = sexp.pexp_loc in
Expand Down
60 changes: 33 additions & 27 deletions lib/4.06.1/unstable/js_playground_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -40818,33 +40818,39 @@ and type_expect ?in_function ?recarg env sexp ty_expected =
(Cmt_format.Partial_expression exp :: previous_saved_types);
exp

and checkTypeInvariant exp =
let rec extractPromise t =
match t.desc with
| Tconstr (Pdot (Pdot (Pident {name = "Js"}, "Promise", _), "t", _), [t1], _)
| Tconstr (Pident {name = "promise"}, [t1], _)
->
Some t1
| Tlink t1 | Tsubst t1 | Tpoly (t1, []) -> extractPromise t1
| _ -> None
in
let rec findNestedPromise t =
match t.desc with
| Tlink t1 | Tsubst t1 | Tpoly (t1, []) -> findNestedPromise t1
| Tconstr (_, ts, _) -> (
match extractPromise t with
| Some t1 -> (
match extractPromise t1 with
| Some _t2 ->
let nestedType = Format.asprintf "%a" Printtyp.type_expr t in
Location.prerr_warning exp.exp_loc (Bs_nested_promise nestedType)
| None -> ts |> List.iter findNestedPromise)
| None -> ts |> List.iter findNestedPromise)
| Tarrow (_, t1, t2, _) ->
findNestedPromise t1;
findNestedPromise t2
| _ -> ()
in findNestedPromise exp.exp_type
(* NOTE: the type invariant check should have no side effects and be efficient *)
and checkTypeInvariant exp : unit =
let rec extractPromise t =
match t.desc with
| Tconstr
(Pdot (Pdot (Pident { name = "Js" }, "Promise", _), "t", _), [ t1 ], _)
| Tconstr (Pident { name = "promise" }, [ t1 ], _) ->
(* Improvement: check for type aliases, if it can be done efficiently *)
Some t1
| Tlink t1 | Tsubst t1 | Tpoly (t1, []) -> extractPromise t1
| _ -> None
in
(* Only traverse arguments of a type constructors and function types.
This should guarantee that the traversal finished quickly. *)
let rec findNestedPromise t =
match t.desc with
| Tlink t1 | Tsubst t1 | Tpoly (t1, []) -> findNestedPromise t1
| Tconstr (_, ts, _) -> (
match extractPromise t with
| Some t1 -> (
match extractPromise t1 with
| Some _t2 ->
let nestedType = Format.asprintf "%a" Printtyp.type_expr t in
Location.prerr_warning exp.exp_loc
(Bs_nested_promise nestedType)
| None -> ts |> List.iter findNestedPromise)
| None -> ts |> List.iter findNestedPromise)
| Tarrow (_, t1, t2, _) ->
findNestedPromise t1;
findNestedPromise t2
| _ -> ()
in
findNestedPromise exp.exp_type

and type_expect_ ?in_function ?(recarg=Rejected) env sexp ty_expected =
let loc = sexp.pexp_loc in
Expand Down
60 changes: 33 additions & 27 deletions lib/4.06.1/whole_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -217205,33 +217205,39 @@ and type_expect ?in_function ?recarg env sexp ty_expected =
(Cmt_format.Partial_expression exp :: previous_saved_types);
exp

and checkTypeInvariant exp =
let rec extractPromise t =
match t.desc with
| Tconstr (Pdot (Pdot (Pident {name = "Js"}, "Promise", _), "t", _), [t1], _)
| Tconstr (Pident {name = "promise"}, [t1], _)
->
Some t1
| Tlink t1 | Tsubst t1 | Tpoly (t1, []) -> extractPromise t1
| _ -> None
in
let rec findNestedPromise t =
match t.desc with
| Tlink t1 | Tsubst t1 | Tpoly (t1, []) -> findNestedPromise t1
| Tconstr (_, ts, _) -> (
match extractPromise t with
| Some t1 -> (
match extractPromise t1 with
| Some _t2 ->
let nestedType = Format.asprintf "%a" Printtyp.type_expr t in
Location.prerr_warning exp.exp_loc (Bs_nested_promise nestedType)
| None -> ts |> List.iter findNestedPromise)
| None -> ts |> List.iter findNestedPromise)
| Tarrow (_, t1, t2, _) ->
findNestedPromise t1;
findNestedPromise t2
| _ -> ()
in findNestedPromise exp.exp_type
(* NOTE: the type invariant check should have no side effects and be efficient *)
and checkTypeInvariant exp : unit =
let rec extractPromise t =
match t.desc with
| Tconstr
(Pdot (Pdot (Pident { name = "Js" }, "Promise", _), "t", _), [ t1 ], _)
| Tconstr (Pident { name = "promise" }, [ t1 ], _) ->
(* Improvement: check for type aliases, if it can be done efficiently *)
Some t1
| Tlink t1 | Tsubst t1 | Tpoly (t1, []) -> extractPromise t1
| _ -> None
in
(* Only traverse arguments of a type constructors and function types.
This should guarantee that the traversal finished quickly. *)
let rec findNestedPromise t =
match t.desc with
| Tlink t1 | Tsubst t1 | Tpoly (t1, []) -> findNestedPromise t1
| Tconstr (_, ts, _) -> (
match extractPromise t with
| Some t1 -> (
match extractPromise t1 with
| Some _t2 ->
let nestedType = Format.asprintf "%a" Printtyp.type_expr t in
Location.prerr_warning exp.exp_loc
(Bs_nested_promise nestedType)
| None -> ts |> List.iter findNestedPromise)
| None -> ts |> List.iter findNestedPromise)
| Tarrow (_, t1, t2, _) ->
findNestedPromise t1;
findNestedPromise t2
| _ -> ()
in
findNestedPromise exp.exp_type

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

0 comments on commit 6e106e9

Please sign in to comment.