Skip to content

Commit d09ce4d

Browse files
vouillonhhugo
authored andcommitted
Check additional code and source map invariants
1 parent 8654d30 commit d09ce4d

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

compiler/lib/code.ml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,12 @@ let invariant { blocks; start; _ } =
909909
| Array_set (_x, _y, _z) -> ()
910910
| Event _ -> ()
911911
in
912+
let rec check_events l =
913+
match l with
914+
| (Event _, _) :: (Event _, _) :: _ -> assert false
915+
| _ :: r -> check_events r
916+
| [] -> ()
917+
in
912918
let check_last (l, _loc) =
913919
match l with
914920
| Return _ -> ()
@@ -928,5 +934,6 @@ let invariant { blocks; start; _ } =
928934
(fun _pc block ->
929935
List.iter block.params ~f:define;
930936
List.iter block.body ~f:check_instr;
937+
check_events block.body;
931938
check_last block.branch)
932939
blocks)

compiler/lib/source_map.ml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -565,10 +565,24 @@ module Standard = struct
565565
let to_file m file = Yojson.Raw.to_file file (json m)
566566

567567
let invariant
568-
{ version; file = _; sourceroot = _; names; sources_content; sources; mappings; _ }
569-
=
568+
{ version
569+
; file = _
570+
; sourceroot = _
571+
; names
572+
; sources_content
573+
; sources
574+
; mappings
575+
; ignore_list
576+
} =
570577
if not (version_is_valid version)
571578
then invalid_arg "Source_map.Standard.invariant: invalid version";
579+
(if not (List.is_empty ignore_list)
580+
then
581+
let s = StringSet.of_list sources in
582+
if List.exists ~f:(fun nm -> not (StringSet.mem nm s)) ignore_list
583+
then
584+
invalid_arg
585+
"Source_map.Standard.invariant: ignore list should be a subset of sources");
572586
match sources_content with
573587
| None -> ()
574588
| Some x ->

0 commit comments

Comments
 (0)