Skip to content

Commit 1bdf1e0

Browse files
Improve error handling: replace assert false with ICE and fix SList dead code elimination
Two improvements to internal error handling and optimization consistency: 1. Replace bare `assert false` in Info.ml with a proper ICE.internal_compiler_error call that includes the offending type in the error message. This produces a helpful diagnostic with a link to the issue tracker instead of a generic assertion failure if this unreachable branch is ever hit. 2. Fix inconsistent SList handling in dead_code_elim: Block and Profile both collapse to Skip when all children are eliminated, but SList was left as an empty SList []. This is inconsistent and produces unnecessary nodes that Mir_utils.cleanup_stmts already treats as equivalent to Skip (line 435).
1 parent 0121e19 commit 1bdf1e0

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

src/analysis_and_optimization/Optimize.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ let dead_code_elimination (mir : Program.Typed.t) =
805805
if List.length l' = 0 then Skip else Block l'
806806
| SList l ->
807807
let l' = List.filter ~f:(fun x -> x.pattern <> Skip) l in
808-
SList l' in
808+
if List.is_empty l' then Skip else SList l' in
809809
let dead_code_elim_stmt =
810810
map_rec_stmt_loc_num flowgraph_to_mir dead_code_elim_stmt_base in
811811
dead_code_elim_stmt (Map.find_exn flowgraph_to_mir 1) in

src/frontend/Info.ml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ let rec unsized_basetype_json t =
1919
`Assoc
2020
[ ("type", `List (List.map ~f:unsized_basetype_json internals))
2121
; ("dimensions", `Int dims) ]
22-
| UMathLibraryFunction | UFun _ | UArray _ -> assert false
22+
| (UMathLibraryFunction | UFun _ | UArray _) as t ->
23+
Common.ICE.internal_compiler_error
24+
[%message
25+
"Unexpected unsized type in unsized_basetype_json" (t : UnsizedType.t)]
2326

2427
let basetype_dims t = SizedType.to_unsized t |> unsized_basetype_json
2528

0 commit comments

Comments
 (0)