Skip to content

Commit 62522de

Browse files
committed
Tidy up handling of unimplemented features. These are expected (if undesirable) sorts of error, we should handle better than "backtrace and exit 2".
1 parent 0bd33ad commit 62522de

File tree

8 files changed

+90
-54
lines changed

8 files changed

+90
-54
lines changed

src/boot/driver/main.ml

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ let _ =
238238
;;
239239

240240

241-
let (crate:Ast.crate) =
241+
let parse_input_crate _ : Ast.crate =
242242
Session.time_inner "parse" sess
243243
begin
244244
fun _ ->
@@ -292,6 +292,15 @@ let (crate:Ast.crate) =
292292
end
293293
;;
294294

295+
let (crate:Ast.crate) =
296+
try
297+
parse_input_crate()
298+
with
299+
Not_implemented (ido, str) ->
300+
Session.report_err sess ido str;
301+
{ node = Ast.empty_crate'; id = Common.Node 0 }
302+
;;
303+
295304
exit_if_failed ()
296305
;;
297306

@@ -399,9 +408,16 @@ let main_pipeline _ =
399408
exit_if_failed ()
400409
;;
401410

402-
if sess.Session.sess_alt_backend
403-
then Glue.alt_pipeline sess sem_cx crate
404-
else main_pipeline ()
411+
try
412+
if sess.Session.sess_alt_backend
413+
then Glue.alt_pipeline sess sem_cx crate
414+
else main_pipeline ()
415+
with
416+
Not_implemented (ido, str) ->
417+
Session.report_err sess ido str
418+
;;
419+
420+
exit_if_failed ()
405421
;;
406422

407423
if sess.Session.sess_report_timing

src/boot/driver/session.ml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,19 @@ let filename_of (fo:filename option) : filename =
101101
| Some f -> f
102102
;;
103103

104+
let report_err sess ido str =
105+
let spano = match ido with
106+
None -> None
107+
| Some id -> get_span sess id
108+
in
109+
match spano with
110+
None ->
111+
fail sess "Error: %s\n%!" str
112+
| Some span ->
113+
fail sess "%s:E:Error: %s\n%!"
114+
(string_of_span span) str
115+
;;
116+
104117
(*
105118
* Local Variables:
106119
* fill-column: 78;

src/boot/fe/ast.ml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,18 @@ and crate' =
457457
and crate = crate' identified
458458
;;
459459

460+
let empty_crate' =
461+
{ crate_items = ({ view_imports = Hashtbl.create 0;
462+
view_exports = Hashtbl.create 0 },
463+
Hashtbl.create 0);
464+
crate_meta = [||];
465+
crate_auth = Hashtbl.create 0;
466+
crate_required = Hashtbl.create 0;
467+
crate_required_syms = Hashtbl.create 0;
468+
crate_main = None;
469+
crate_files = Hashtbl.create 0 }
470+
;;
471+
460472
(*
461473
* NB: names can only be type-parametric in their *last* path-entry.
462474
* All path-entries before that must be ident or idx (non-parametric).

src/boot/fe/cexp.ml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -605,14 +605,7 @@ let with_err_handling sess thunk =
605605
(Session.string_of_pos pos) cx)
606606
ps.pstate_ctxt;
607607
let apos = lexpos ps in
608-
span ps apos apos
609-
{ Ast.crate_items = (Item.empty_view, Hashtbl.create 0);
610-
Ast.crate_meta = [||];
611-
Ast.crate_auth = Hashtbl.create 0;
612-
Ast.crate_required = Hashtbl.create 0;
613-
Ast.crate_required_syms = Hashtbl.create 0;
614-
Ast.crate_main = None;
615-
Ast.crate_files = Hashtbl.create 0 }
608+
span ps apos apos Ast.empty_crate'
616609
;;
617610

618611

src/boot/llvm/lltrans.ml

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,7 @@ let trans_crate
330330

331331
| Ast.TY_tag _ | Ast.TY_iso _ | Ast.TY_idx _
332332
| Ast.TY_obj _ | Ast.TY_type ->
333-
raise (Not_implemented
334-
("trans_ty_full " ^ (Ast.sprintf_ty() ty)))
333+
Common.unimpl None "LLVM type translation for: %a" Ast.sprintf_ty ty
335334

336335
| Ast.TY_param _ | Ast.TY_named _ ->
337336
bug () "unresolved type in lltrans"
@@ -566,9 +565,10 @@ let trans_crate
566565
() (* Modules simply contain other items that are translated
567566
on their own. *)
568567

569-
| _ -> raise (Not_implemented
570-
("declare_mod_item " ^
571-
(Ast.sprintf_mod_item() (name,mod_item))))
568+
| _ ->
569+
Common.unimpl (Some id)
570+
"LLVM module declaration for: %a"
571+
Ast.sprintf_mod_item (name, mod_item)
572572
in
573573

574574
let trans_fn
@@ -715,12 +715,15 @@ let trans_crate
715715
match referent with
716716
Semant.DEFN_slot _ -> Hashtbl.find slot_to_llvalue id
717717
| Semant.DEFN_item _ -> Hashtbl.find llitems id
718-
| _ -> raise
719-
(Not_implemented
720-
("referent of " ^ (Ast.sprintf_lval() lval)))
718+
| _ ->
719+
Common.unimpl (Some id)
720+
"LLVM base-referent translation of: %a"
721+
Ast.sprintf_lval lval
721722
end
722-
| Ast.LVAL_ext _ -> raise
723-
(Not_implemented ("trans_lval " ^ (Ast.sprintf_lval() lval)))
723+
| Ast.LVAL_ext _ ->
724+
Common.unimpl (Some (Semant.lval_base_id lval))
725+
"LLVM lval translation of: %a"
726+
Ast.sprintf_lval lval
724727
in
725728

726729
let trans_atom (atom:Ast.atom) : Llvm.llvalue =
@@ -746,8 +749,10 @@ let trans_crate
746749
| Ast.BINOP_div -> Llvm.build_sdiv lllhs llrhs llid llbuilder
747750
| Ast.BINOP_mod -> Llvm.build_srem lllhs llrhs llid llbuilder
748751

749-
| _ -> raise
750-
(Not_implemented ("build_binop " ^ (Ast.sprintf_binop() op)))
752+
| _ ->
753+
Common.unimpl None
754+
"LLVM binop trranslation of: %a"
755+
Ast.sprintf_binop op
751756
in
752757

753758
let trans_binary_expr
@@ -770,9 +775,10 @@ let trans_crate
770775
build_binop op lllhs llrhs
771776
in
772777

773-
let trans_unary_expr e = raise
774-
(Not_implemented ("trans_unary_expr " ^
775-
(Ast.sprintf_expr() (Ast.EXPR_unary e))))
778+
let trans_unary_expr e =
779+
Common.unimpl None
780+
"LLVM unary-expression translation of: %a"
781+
Ast.sprintf_expr (Ast.EXPR_unary e)
776782
in
777783

778784
let trans_expr (expr:Ast.expr) : Llvm.llvalue =
@@ -945,8 +951,10 @@ let trans_crate
945951
| Ast.STMT_decl _ ->
946952
trans_tail ()
947953

948-
| _ -> raise (Not_implemented
949-
("trans_stmts " ^ (Ast.sprintf_stmt() head)))
954+
| _ ->
955+
Common.unimpl (Some head.id)
956+
"LLVM statement translation of: %a"
957+
Ast.sprintf_stmt head
950958

951959
(*
952960
* Translates an AST block to one or more LLVM basic blocks and returns

src/boot/me/semant.ml

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -261,23 +261,10 @@ let new_ctxt sess abi crate =
261261
}
262262
;;
263263

264-
let report_err cx ido str =
265-
let sess = cx.ctxt_sess in
266-
let spano = match ido with
267-
None -> None
268-
| Some id -> (Session.get_span sess id)
269-
in
270-
match spano with
271-
None ->
272-
Session.fail sess "Error: %s\n%!" str
273-
| Some span ->
274-
Session.fail sess "%s:E:Error: %s\n%!"
275-
(Session.string_of_span span) str
276-
;;
277264

278265
let bugi (cx:ctxt) (i:node_id) =
279266
let k s =
280-
report_err cx (Some i) s;
267+
Session.report_err cx.ctxt_sess (Some i) s;
281268
failwith s
282269
in Printf.ksprintf k
283270
;;
@@ -1857,7 +1844,8 @@ let run_passes
18571844
Session.time_inner name sess
18581845
(fun _ -> Array.iteri do_pass passes)
18591846
with
1860-
Semant_err (ido, str) -> report_err cx ido str
1847+
Semant_err (ido, str) ->
1848+
Session.report_err cx.ctxt_sess ido str
18611849
;;
18621850

18631851
(* Rust type -> IL type conversion. *)

src/boot/me/type.ml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -950,15 +950,14 @@ let process_crate (cx:Semant.ctxt) (crate:Ast.crate) : unit =
950950
}
951951
in
952952

953-
try
954-
Walk.walk_crate
955-
(Walk.path_managing_visitor path
956-
(Semant.mod_item_logging_visitor
957-
cx
958-
cx.Semant.ctxt_sess.Session.sess_log_type log 0 path
959-
(visitor cx Walk.empty_visitor)))
960-
crate
961-
with Common.Semant_err (ido, str) -> Semant.report_err cx ido str;
953+
let passes =
954+
[|
955+
(visitor cx Walk.empty_visitor)
956+
|]
957+
in
958+
let log_flag = cx.Semant.ctxt_sess.Session.sess_log_type in
959+
Semant.run_passes cx "type" path passes log_flag log crate
960+
;;
962961

963962
(*
964963
* Local Variables:

src/boot/util/common.ml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ let bug _ =
2626
;;
2727

2828
(* TODO: On some joyous day, remove me. *)
29-
exception Not_implemented of string
29+
exception Not_implemented of ((node_id option) * string)
3030
;;
3131

3232
exception Semant_err of ((node_id option) * string)
@@ -39,6 +39,13 @@ let err (idopt:node_id option) =
3939
Printf.ksprintf k
4040
;;
4141

42+
let unimpl (idopt:node_id option) =
43+
let k s =
44+
raise (Not_implemented (idopt, "unimplemented " ^ s))
45+
in
46+
Printf.ksprintf k
47+
;;
48+
4249
(* Some ubiquitous low-level types. *)
4350

4451
type target =

0 commit comments

Comments
 (0)