Skip to content

Commit ed4f755

Browse files
committed
Remove coercion with 2 types, which is only supported in ml syntax.
There are two forms of type coercion: 1 `e: t0 :> t` 2 `e :> t` The first form was never supported in .res syntax, and is now removed from parsed and typed tree. That said, coercion 1 is the only one that ever supported coercion with free variables. So this is subject to more investigation. See #6828
1 parent 2a0f3ba commit ed4f755

23 files changed

+43
-107
lines changed

jscomp/frontend/bs_ast_mapper.ml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,10 +349,8 @@ module E = struct
349349
| Pexp_for (p, e1, e2, d, e3) ->
350350
for_ ~loc ~attrs (sub.pat sub p) (sub.expr sub e1) (sub.expr sub e2) d
351351
(sub.expr sub e3)
352-
| Pexp_coerce (e, t1, t2) ->
353-
coerce ~loc ~attrs (sub.expr sub e)
354-
(map_opt (sub.typ sub) t1)
355-
(sub.typ sub t2)
352+
| Pexp_coerce (e, (), t2) ->
353+
coerce ~loc ~attrs (sub.expr sub e) (sub.typ sub t2)
356354
| Pexp_constraint (e, t) ->
357355
constraint_ ~loc ~attrs (sub.expr sub e) (sub.typ sub t)
358356
| Pexp_send (e, s) -> send ~loc ~attrs (sub.expr sub e) (map_loc sub s)

jscomp/ml/ast_helper.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ module Exp = struct
171171
let while_ ?loc ?attrs a b = mk ?loc ?attrs (Pexp_while (a, b))
172172
let for_ ?loc ?attrs a b c d e = mk ?loc ?attrs (Pexp_for (a, b, c, d, e))
173173
let constraint_ ?loc ?attrs a b = mk ?loc ?attrs (Pexp_constraint (a, b))
174-
let coerce ?loc ?attrs a b c = mk ?loc ?attrs (Pexp_coerce (a, b, c))
174+
let coerce ?loc ?attrs a c = mk ?loc ?attrs (Pexp_coerce (a, (), c))
175175
let send ?loc ?attrs a b = mk ?loc ?attrs (Pexp_send (a, b))
176176
let new_ ?loc ?attrs a = mk ?loc ?attrs (Pexp_new a)
177177
let setinstvar ?loc ?attrs a b = mk ?loc ?attrs (Pexp_setinstvar (a, b))

jscomp/ml/ast_helper.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ module Exp:
146146
-> expression
147147
val for_: ?loc:loc -> ?attrs:attrs -> pattern -> expression -> expression
148148
-> direction_flag -> expression -> expression
149-
val coerce: ?loc:loc -> ?attrs:attrs -> expression -> core_type option
149+
val coerce: ?loc:loc -> ?attrs:attrs -> expression
150150
-> core_type -> expression
151151
val constraint_: ?loc:loc -> ?attrs:attrs -> expression -> core_type
152152
-> expression

jscomp/ml/ast_iterator.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,8 @@ module E = struct
303303
| Pexp_for (p, e1, e2, _d, e3) ->
304304
sub.pat sub p; sub.expr sub e1; sub.expr sub e2;
305305
sub.expr sub e3
306-
| Pexp_coerce (e, t1, t2) ->
307-
sub.expr sub e; iter_opt (sub.typ sub) t1;
306+
| Pexp_coerce (e, (), t2) ->
307+
sub.expr sub e;
308308
sub.typ sub t2
309309
| Pexp_constraint (e, t) ->
310310
sub.expr sub e; sub.typ sub t

jscomp/ml/ast_mapper.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,8 @@ module E = struct
314314
| Pexp_for (p, e1, e2, d, e3) ->
315315
for_ ~loc ~attrs (sub.pat sub p) (sub.expr sub e1) (sub.expr sub e2) d
316316
(sub.expr sub e3)
317-
| Pexp_coerce (e, t1, t2) ->
318-
coerce ~loc ~attrs (sub.expr sub e) (map_opt (sub.typ sub) t1)
317+
| Pexp_coerce (e, (), t2) ->
318+
coerce ~loc ~attrs (sub.expr sub e)
319319
(sub.typ sub t2)
320320
| Pexp_constraint (e, t) ->
321321
constraint_ ~loc ~attrs (sub.expr sub e) (sub.typ sub t)

jscomp/ml/depend.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,8 @@ let rec add_expr bv exp =
218218
| Pexp_while(e1, e2) -> add_expr bv e1; add_expr bv e2
219219
| Pexp_for( _, e1, e2, _, e3) ->
220220
add_expr bv e1; add_expr bv e2; add_expr bv e3
221-
| Pexp_coerce(e1, oty2, ty3) ->
221+
| Pexp_coerce(e1, (), ty3) ->
222222
add_expr bv e1;
223-
add_opt add_type bv oty2;
224223
add_type bv ty3
225224
| Pexp_constraint(e1, ty2) ->
226225
add_expr bv e1;

jscomp/ml/parser.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ let mkstrexp e attrs =
241241
let mkexp_constraint e (t1, t2) =
242242
match t1, t2 with
243243
| Some t, None -> ghexp(Pexp_constraint(e, t))
244-
| _, Some t -> ghexp(Pexp_coerce(e, t1, t))
244+
| _, Some t -> ghexp(Pexp_coerce(e, (), t))
245245
| None, None -> assert false
246246

247247
let mkexp_opt_constraint e = function
@@ -6554,7 +6554,7 @@ let yyact = [|
65546554
# 648 "ml/parser.mly"
65556555
( mkmod ~attrs:_3
65566556
(Pmod_unpack(
6557-
ghexp(Pexp_coerce(_4, Some(ghtyp(Ptyp_package _6)),
6557+
ghexp(Pexp_coerce(_4, (),
65586558
ghtyp(Ptyp_package _8))))) )
65596559
# 6565 "ml/parser.ml"
65606560
: 'paren_module_expr))
@@ -6566,7 +6566,7 @@ let yyact = [|
65666566
# 653 "ml/parser.mly"
65676567
( mkmod ~attrs:_3
65686568
(Pmod_unpack(
6569-
ghexp(Pexp_coerce(_4, None, ghtyp(Ptyp_package _6))))) )
6569+
ghexp(Pexp_coerce(_4, (), ghtyp(Ptyp_package _6))))) )
65706570
# 6576 "ml/parser.ml"
65716571
: 'paren_module_expr))
65726572
; (fun __caml_parser_env ->

jscomp/ml/parser.mly

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ let mkstrexp e attrs =
135135
let mkexp_constraint e (t1, t2) =
136136
match t1, t2 with
137137
| Some t, None -> ghexp(Pexp_constraint(e, t))
138-
| _, Some t -> ghexp(Pexp_coerce(e, t1, t))
138+
| _, Some t -> ghexp(Pexp_coerce(e, (), t))
139139
| None, None -> assert false
140140

141141
let mkexp_opt_constraint e = function

jscomp/ml/parsetree.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,9 +307,8 @@ and expression_desc =
307307
*)
308308
| Pexp_constraint of expression * core_type
309309
(* (E : T) *)
310-
| Pexp_coerce of expression * core_type option * core_type
310+
| Pexp_coerce of expression * unit * core_type
311311
(* (E :> T) (None, T)
312-
(E : T0 :> T) (Some T0, T)
313312
*)
314313
| Pexp_send of expression * label loc
315314
(* E # m *)

jscomp/ml/pprintast.ml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -707,9 +707,8 @@ and simple_expr ctxt f x =
707707
pp f "@[<hov2>(%a)@]" (list (simple_expr ctxt) ~sep:",@;") l
708708
| Pexp_constraint (e, ct) ->
709709
pp f "(%a : %a)" (expression ctxt) e (core_type ctxt) ct
710-
| Pexp_coerce (e, cto1, ct) ->
711-
pp f "(%a%a :> %a)" (expression ctxt) e
712-
(option (core_type ctxt) ~first:" : " ~last:" ") cto1 (* no sep hint*)
710+
| Pexp_coerce (e, (), ct) ->
711+
pp f "(%a :> %a)" (expression ctxt) e
713712
(core_type ctxt) ct
714713
| Pexp_variant (l, None) -> pp f "`%s" l
715714
| Pexp_record (l, eo) ->

0 commit comments

Comments
 (0)