Skip to content

Commit 2edf360

Browse files
committed
Remove unused Pexp_unreachable and Texp_unreachable.
1 parent feb795a commit 2edf360

27 files changed

+47
-103
lines changed

analysis/reanalyze/src/Arnold.ml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -998,9 +998,6 @@ module Compile = struct
998998
| Texp_pack _ ->
999999
notImplemented "Texp_pack";
10001000
assert false
1001-
| Texp_unreachable ->
1002-
notImplemented "Texp_unreachable";
1003-
assert false
10041001
| Texp_extension_constructor _ when true ->
10051002
notImplemented "Texp_extension_constructor";
10061003
assert false

analysis/reanalyze/src/SideEffects.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ let rec exprNoSideEffects (expr : Typedtree.expression) =
6767
| Texp_override _ -> false
6868
| Texp_letexception (_ec, e) -> e |> exprNoSideEffects
6969
| Texp_pack _ -> false
70-
| Texp_unreachable -> false
7170
| Texp_extension_constructor _ when true -> true
7271
| _ -> (* on ocaml 4.08: Texp_letop | Texp_open *) true
7372

analysis/src/Utils.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ let identifyPexp pexp =
116116
| Pexp_pack _ -> "Pexp_pack"
117117
| Pexp_extension _ -> "Pexp_extension"
118118
| Pexp_open _ -> "Pexp_open"
119-
| Pexp_unreachable -> "Pexp_unreachable"
120119

121120
let identifyPpat pat =
122121
match pat with

compiler/frontend/bs_ast_mapper.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,6 @@ module E = struct
376376
| Pexp_open (ovf, lid, e) ->
377377
open_ ~loc ~attrs ovf (map_loc sub lid) (sub.expr sub e)
378378
| Pexp_extension x -> extension ~loc ~attrs (sub.extension sub x)
379-
| Pexp_unreachable -> unreachable ~loc ~attrs ()
380379
end
381380

382381
module P = struct

compiler/ml/ast_helper.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@ module Exp = struct
181181
let pack ?loc ?attrs a = mk ?loc ?attrs (Pexp_pack a)
182182
let open_ ?loc ?attrs a b c = mk ?loc ?attrs (Pexp_open (a, b, c))
183183
let extension ?loc ?attrs a = mk ?loc ?attrs (Pexp_extension a)
184-
let unreachable ?loc ?attrs () = mk ?loc ?attrs Pexp_unreachable
185184

186185
let case lhs ?guard rhs = {pc_lhs = lhs; pc_guard = guard; pc_rhs = rhs}
187186
end

compiler/ml/ast_helper.mli

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ module Exp : sig
202202
val open_ :
203203
?loc:loc -> ?attrs:attrs -> override_flag -> lid -> expression -> expression
204204
val extension : ?loc:loc -> ?attrs:attrs -> extension -> expression
205-
val unreachable : ?loc:loc -> ?attrs:attrs -> unit -> expression
206205

207206
val case : pattern -> ?guard:expression -> expression -> case
208207
end

compiler/ml/ast_iterator.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,6 @@ module E = struct
358358
iter_loc sub lid;
359359
sub.expr sub e
360360
| Pexp_extension x -> sub.extension sub x
361-
| Pexp_unreachable -> ()
362361
end
363362

364363
module P = struct

compiler/ml/ast_mapper.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,6 @@ module E = struct
339339
| Pexp_open (ovf, lid, e) ->
340340
open_ ~loc ~attrs ovf (map_loc sub lid) (sub.expr sub e)
341341
| Pexp_extension x -> extension ~loc ~attrs (sub.extension sub x)
342-
| Pexp_unreachable -> unreachable ~loc ~attrs ()
343342
end
344343

345344
module P = struct

compiler/ml/ast_mapper_from0.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ module E = struct
347347
| Pexp_open (ovf, lid, e) ->
348348
open_ ~loc ~attrs ovf (map_loc sub lid) (sub.expr sub e)
349349
| Pexp_extension x -> extension ~loc ~attrs (sub.extension sub x)
350-
| Pexp_unreachable -> unreachable ~loc ~attrs ()
350+
| Pexp_unreachable -> assert false
351351
end
352352

353353
module P = struct

compiler/ml/ast_mapper_to0.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,6 @@ module E = struct
345345
| Pexp_open (ovf, lid, e) ->
346346
open_ ~loc ~attrs ovf (map_loc sub lid) (sub.expr sub e)
347347
| Pexp_extension x -> extension ~loc ~attrs (sub.extension sub x)
348-
| Pexp_unreachable -> unreachable ~loc ~attrs ()
349348
end
350349

351350
module P = struct

compiler/ml/depend.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,6 @@ let rec add_expr bv exp =
296296
| Pstr_eval ({pexp_desc = Pexp_construct (c, None)}, _) -> add bv c
297297
| _ -> handle_extension e)
298298
| Pexp_extension e -> handle_extension e
299-
| Pexp_unreachable -> ()
300299

301300
and add_cases bv cases = List.iter (add_case bv) cases
302301

compiler/ml/parmatch.ml

Lines changed: 39 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2179,64 +2179,54 @@ let do_check_fragile_gadt = do_check_fragile_param exhaust_gadt
21792179
(********************************)
21802180

21812181
let check_unused pred casel =
2182-
if
2183-
Warnings.is_active Warnings.Unused_match
2184-
|| List.exists (fun c -> c.c_rhs.exp_desc = Texp_unreachable) casel
2185-
then
2182+
if Warnings.is_active Warnings.Unused_match then
21862183
let rec do_rec pref = function
21872184
| [] -> ()
2188-
| {c_lhs = q; c_guard; c_rhs} :: rem ->
2185+
| {c_lhs = q; c_guard} :: rem ->
21892186
let qs = [q] in
21902187
(try
21912188
let pss = get_mins le_pats (Ext_list.filter pref (compats qs)) in
21922189
(* First look for redundant or partially redundant patterns *)
21932190
let r = every_satisfiables (make_rows pss) (make_row qs) in
2194-
let refute = c_rhs.exp_desc = Texp_unreachable in
21952191
(* Do not warn for unused [pat -> .] *)
2196-
if r = Unused && refute then ()
2197-
else
2198-
let r =
2199-
(* Do not refine if there are no other lines *)
2200-
let skip =
2201-
r = Unused
2202-
|| ((not refute) && pref = [])
2203-
|| not (refute || Warnings.is_active Warnings.Unreachable_case)
2204-
in
2205-
if skip then r
2206-
else
2207-
(* Then look for empty patterns *)
2208-
let sfs = satisfiables pss qs in
2209-
if sfs = [] then Unused
2210-
else
2211-
let sfs =
2212-
List.map
2213-
(function
2214-
| [u] -> u
2215-
| _ -> assert false)
2216-
sfs
2217-
in
2218-
let u = orify_many sfs in
2219-
(*Format.eprintf "%a@." pretty_val u;*)
2220-
let pattern, constrs, labels = Conv.conv u in
2221-
let pattern =
2222-
{pattern with Parsetree.ppat_loc = q.pat_loc}
2223-
in
2224-
match pred refute constrs labels pattern with
2225-
| None when not refute ->
2226-
Location.prerr_warning q.pat_loc Warnings.Unreachable_case;
2227-
Used
2228-
| _ -> r
2192+
let r =
2193+
(* Do not refine if there are no other lines *)
2194+
let skip =
2195+
r = Unused || pref = []
2196+
|| not (Warnings.is_active Warnings.Unreachable_case)
22292197
in
2230-
match r with
2231-
| Unused -> Location.prerr_warning q.pat_loc Warnings.Unused_match
2232-
| Upartial ps ->
2233-
ps
2234-
|> List.filter (fun p ->
2235-
not
2236-
(Variant_type_spread.is_pat_from_variant_spread_attr p))
2237-
|> List.iter (fun p ->
2238-
Location.prerr_warning p.pat_loc Warnings.Unused_pat)
2239-
| Used -> ()
2198+
if skip then r
2199+
else
2200+
(* Then look for empty patterns *)
2201+
let sfs = satisfiables pss qs in
2202+
if sfs = [] then Unused
2203+
else
2204+
let sfs =
2205+
List.map
2206+
(function
2207+
| [u] -> u
2208+
| _ -> assert false)
2209+
sfs
2210+
in
2211+
let u = orify_many sfs in
2212+
(*Format.eprintf "%a@." pretty_val u;*)
2213+
let pattern, constrs, labels = Conv.conv u in
2214+
let pattern = {pattern with Parsetree.ppat_loc = q.pat_loc} in
2215+
match pred false constrs labels pattern with
2216+
| None ->
2217+
Location.prerr_warning q.pat_loc Warnings.Unreachable_case;
2218+
Used
2219+
| _ -> r
2220+
in
2221+
match r with
2222+
| Unused -> Location.prerr_warning q.pat_loc Warnings.Unused_match
2223+
| Upartial ps ->
2224+
ps
2225+
|> List.filter (fun p ->
2226+
not (Variant_type_spread.is_pat_from_variant_spread_attr p))
2227+
|> List.iter (fun p ->
2228+
Location.prerr_warning p.pat_loc Warnings.Unused_pat)
2229+
| Used -> ()
22402230
with Empty | Not_found | NoGuard -> assert false);
22412231

22422232
if c_guard <> None then do_rec pref rem else do_rec ([q] :: pref) rem

compiler/ml/parsetree.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,8 @@ and expression_desc =
310310
(* M.(E)
311311
let open M in E
312312
let! open M in E *)
313-
| Pexp_extension of extension (* [%id] *)
314-
| Pexp_unreachable
313+
| Pexp_extension of extension
314+
(* [%id] *)
315315
(* . *)
316316

317317
and case = {

compiler/ml/pprintast.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,6 @@ and expression ctxt f x =
661661
| Pexp_variant (l,Some eo) ->
662662
pp f "@[<2>`%s@;%a@]" l (simple_expr ctxt) eo
663663
| Pexp_extension e -> extension ctxt f e
664-
| Pexp_unreachable -> pp f "."
665664
| _ -> expression1 ctxt f x
666665

667666
and expression1 ctxt f x =

compiler/ml/printast.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,6 @@ and expression i ppf x =
346346
| Pexp_extension (s, arg) ->
347347
line i ppf "Pexp_extension \"%s\"\n" s.txt;
348348
payload i ppf arg
349-
| Pexp_unreachable -> line i ppf "Pexp_unreachable"
350349

351350
and value_description i ppf x =
352351
line i ppf "value_description %a %a\n" fmt_string_loc x.pval_name fmt_location

compiler/ml/printtyped.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,6 @@ and expression i ppf x =
375375
| Texp_pack me ->
376376
line i ppf "Texp_pack";
377377
module_expr i ppf me
378-
| Texp_unreachable -> line i ppf "Texp_unreachable"
379378
| Texp_extension_constructor (li, _) ->
380379
line i ppf "Texp_extension_constructor %a" fmt_longident li
381380

compiler/ml/rec_check.ml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,8 @@ let rec classify_expression : Typedtree.expression -> sd =
198198
| Texp_ident _ | Texp_for _ | Texp_constant _ | Texp_new _ | Texp_instvar _
199199
| Texp_tuple _ | Texp_array _ | Texp_construct _ | Texp_variant _
200200
| Texp_record _ | Texp_setfield _ | Texp_while _ | Texp_setinstvar _
201-
| Texp_pack _ | Texp_function _ | Texp_lazy _ | Texp_unreachable
202-
| Texp_extension_constructor _ ->
201+
| Texp_pack _ | Texp_function _ | Texp_lazy _ | Texp_extension_constructor _
202+
->
203203
Static
204204
| Texp_apply ({exp_desc = Texp_ident (_, _, vd)}, _) when is_ref vd -> Static
205205
| Texp_apply _ | Texp_match _ | Texp_ifthenelse _ | Texp_send _ | Texp_field _
@@ -300,7 +300,6 @@ let rec expression : Env.env -> Typedtree.expression -> Use.t =
300300
match Typeopt.classify_lazy_argument e with
301301
| `Constant_or_function | `Identifier _ | `Float -> expression env e
302302
| `Other -> Use.delay (expression env e))
303-
| Texp_unreachable -> Use.empty
304303
| Texp_extension_constructor _ -> Use.empty
305304

306305
and option : 'a. (Env.env -> 'a -> Use.t) -> Env.env -> 'a option -> Use.t =

compiler/ml/tast_iterator.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,6 @@ let expr sub {exp_extra; exp_desc; exp_env; _} =
211211
| Texp_assert exp -> sub.expr sub exp
212212
| Texp_lazy exp -> sub.expr sub exp
213213
| Texp_pack mexpr -> sub.module_expr sub mexpr
214-
| Texp_unreachable -> ()
215214
| Texp_extension_constructor _ -> ()
216215

217216
let package_type sub {pack_fields; _} =

compiler/ml/tast_mapper.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,6 @@ let expr sub x =
251251
| Texp_assert exp -> Texp_assert (sub.expr sub exp)
252252
| Texp_lazy exp -> Texp_lazy (sub.expr sub exp)
253253
| Texp_pack mexpr -> Texp_pack (sub.module_expr sub mexpr)
254-
| Texp_unreachable -> Texp_unreachable
255254
| Texp_extension_constructor _ as e -> e
256255
in
257256
{x with exp_extra; exp_desc; exp_env}

compiler/ml/translcore.ml

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ open Typedtree
2424
open Typeopt
2525
open Lambda
2626

27-
type error = Unknown_builtin_primitive of string | Unreachable_reached
27+
type error = Unknown_builtin_primitive of string
2828

2929
exception Error of Location.t * error
3030

@@ -986,7 +986,6 @@ and transl_exp0 (e : Typedtree.expression) : Lambda.lambda =
986986
optimize the translation just as Lazy.lazy_from_val would
987987
do *)
988988
Lprim (Pmakeblock Blk_lazy_general, [transl_exp e], e.exp_loc)
989-
| Texp_unreachable -> raise (Error (e.exp_loc, Unreachable_reached))
990989

991990
and transl_list expr_list = List.map transl_exp expr_list
992991

@@ -998,11 +997,7 @@ and transl_guard guard rhs =
998997

999998
and transl_case {c_lhs; c_guard; c_rhs} = (c_lhs, transl_guard c_guard c_rhs)
1000999

1001-
and transl_cases cases =
1002-
let cases =
1003-
Ext_list.filter cases (fun c -> c.c_rhs.exp_desc <> Texp_unreachable)
1004-
in
1005-
List.map transl_case cases
1000+
and transl_cases cases = List.map transl_case cases
10061001

10071002
and transl_case_try {c_lhs; c_guard; c_rhs} =
10081003
match c_lhs.pat_desc with
@@ -1013,11 +1008,7 @@ and transl_case_try {c_lhs; c_guard; c_rhs} =
10131008
(fun () -> Hashtbl.remove try_ids id)
10141009
| _ -> (c_lhs, transl_guard c_guard c_rhs)
10151010

1016-
and transl_cases_try cases =
1017-
let cases =
1018-
Ext_list.filter cases (fun c -> c.c_rhs.exp_desc <> Texp_unreachable)
1019-
in
1020-
List.map transl_case_try cases
1011+
and transl_cases_try cases = List.map transl_case_try cases
10211012

10221013
and transl_apply ?(inlined = Default_inline)
10231014
?(uncurried_partial_application = None) lam sargs loc =
@@ -1342,7 +1333,6 @@ open Format
13421333
let report_error ppf = function
13431334
| Unknown_builtin_primitive prim_name ->
13441335
fprintf ppf "Unknown builtin primitive \"%s\"" prim_name
1345-
| Unreachable_reached -> fprintf ppf "Unreachable expression was reached"
13461336

13471337
let () =
13481338
Location.register_error_of_exn (function

compiler/ml/typecore.ml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ let iter_expression f e =
184184
expr e;
185185
module_expr me
186186
| Pexp_pack me -> module_expr me
187-
| Pexp_unreachable -> ()
188187
and case {pc_lhs = _; pc_guard; pc_rhs} =
189188
may expr pc_guard;
190189
expr pc_rhs
@@ -3299,16 +3298,6 @@ and type_expect_ ?type_clash_context ?in_function ?(recarg = Rejected) env sexp
32993298
| _ -> raise (Error (loc, env, Invalid_extension_constructor_payload)))
33003299
| Pexp_extension ext ->
33013300
raise (Error_forward (Builtin_attributes.error_of_extension ext))
3302-
| Pexp_unreachable ->
3303-
re
3304-
{
3305-
exp_desc = Texp_unreachable;
3306-
exp_loc = loc;
3307-
exp_extra = [];
3308-
exp_type = instance env ty_expected;
3309-
exp_attributes = sexp.pexp_attributes;
3310-
exp_env = env;
3311-
}
33123301
33133302
and type_function ?in_function loc attrs env ty_expected l caselist =
33143303
let loc_fun, ty_fun =
@@ -4014,7 +4003,6 @@ and type_cases ?root_type_clash_context ?in_function env ty_arg ty_res
40144003
in
40154004
let needs_exhaust_check =
40164005
match caselist with
4017-
| [{pc_rhs = {pexp_desc = Pexp_unreachable}}] -> true
40184006
| [{pc_lhs}] when is_var pc_lhs -> false
40194007
| _ -> true
40204008
in

compiler/ml/typedtree.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ and expression_desc =
117117
| Texp_assert of expression
118118
| Texp_lazy of expression
119119
| Texp_pack of module_expr
120-
| Texp_unreachable
121120
| Texp_extension_constructor of Longident.t loc * Path.t
122121

123122
and meth = Tmeth_name of string

compiler/ml/typedtree.mli

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,6 @@ and expression_desc =
219219
| Texp_assert of expression
220220
| Texp_lazy of expression
221221
| Texp_pack of module_expr
222-
| Texp_unreachable
223222
| Texp_extension_constructor of Longident.t loc * Path.t
224223

225224
and meth = Tmeth_name of string

compiler/ml/typedtreeIter.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,6 @@ end = struct
297297
| Texp_assert exp -> iter_expression exp
298298
| Texp_lazy exp -> iter_expression exp
299299
| Texp_pack mexpr -> iter_module_expr mexpr
300-
| Texp_unreachable -> ()
301300
| Texp_extension_constructor _ -> ());
302301
Iter.leave_expression exp
303302

compiler/ml/untypeast.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,6 @@ let expression sub exp =
395395
| Texp_assert exp -> Pexp_assert (sub.expr sub exp)
396396
| Texp_lazy exp -> Pexp_lazy (sub.expr sub exp)
397397
| Texp_pack mexpr -> Pexp_pack (sub.module_expr sub mexpr)
398-
| Texp_unreachable -> Pexp_unreachable
399398
| Texp_extension_constructor (lid, _) ->
400399
Pexp_extension
401400
( {txt = "ocaml.extension_constructor"; loc},

compiler/syntax/src/res_ast_debugger.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,6 @@ module SexpAst = struct
717717
]
718718
| Pexp_extension ext ->
719719
Sexp.list [Sexp.atom "Pexp_extension"; extension ext]
720-
| Pexp_unreachable -> Sexp.atom "Pexp_unreachable"
721720
in
722721
Sexp.list [Sexp.atom "expression"; desc]
723722

compiler/syntax/src/res_printer.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3190,7 +3190,6 @@ and print_expression ~state (e : Parsetree.expression) cmt_tbl =
31903190
else if ParsetreeViewer.is_binary_expression e then
31913191
print_binary_expression ~state e cmt_tbl
31923192
else print_pexp_apply ~state e cmt_tbl
3193-
| Pexp_unreachable -> Doc.dot
31943193
| Pexp_field (expr, longident_loc) ->
31953194
let lhs =
31963195
let doc = print_expression_with_comments ~state expr cmt_tbl in

0 commit comments

Comments
 (0)