Skip to content

Commit 8cbaa43

Browse files
author
Shale Xiong
committed
[gen] Minor change on functions in code.ml
- Remove `assert false` in `code.ml`. - Introduce `is_diff_loc` - Change `seq_sd` return `option`.
1 parent 56689d0 commit 8cbaa43

5 files changed

Lines changed: 25 additions & 13 deletions

File tree

gen/alt.ml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ module Make(C:Builder.S)
7070
(fun f -> List.exists (equal_fence f) fs)
7171

7272
let choice_sc po_safe e1 e2 =
73+
let seq_sd e1 e2 =
74+
match Code.seq_sd e1 e2 with
75+
| None -> Warn.user_error "Unexpected UnspecLoc"
76+
| Some b -> b in
7377
let r = match e1.edge,e2.edge with
7478
(*
7579
Now accept internal with internal composition
@@ -564,7 +568,7 @@ module Make(C:Builder.S)
564568

565569
let count_ext es = count_e 0 es
566570

567-
let change_loc e = not @@ Code.is_same_loc @@ loc_sd e
571+
let change_loc e = Code.is_diff_loc @@ loc_sd e
568572

569573
let count_p p =
570574
List.fold_left ( fun acc x -> if p x then acc + 1 else acc ) 0

gen/common/code.ml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,18 +97,21 @@ let pp_sd = function
9797

9898
let is_same_loc = function
9999
| Same -> true
100-
| Diff -> false
101-
| UnspecLoc -> assert false
100+
| _ -> false
101+
102+
let is_diff_loc = function
103+
| Diff -> true
104+
| _ -> false
102105

103-
let is_both_loc = function
106+
let is_unspec_loc = function
104107
| UnspecLoc -> true
105108
| _ -> false
106109

107110
let seq_sd sd1 sd2 =
108111
match sd1,sd2 with
109-
| UnspecLoc,_|_, UnspecLoc -> assert false
110-
| Same,Same -> Same
111-
| Diff,_|_,Diff -> Diff
112+
| UnspecLoc,_|_, UnspecLoc -> None
113+
| Same,Same -> Some Same
114+
| Diff,_|_,Diff -> Some Diff
112115

113116
let fold_ie wildcard f r = let r = if wildcard then (f UnspecCom r) else r in f Ext (f Int r)
114117
let fold_sd wildcard f r = let r = if wildcard then (f UnspecLoc r) else r in f Diff (f Same r)

gen/common/code.mli

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,10 @@ val pp_ie : ie -> string
5555
val pp_dir : dir -> string
5656
val pp_extr : extr -> string
5757
val pp_sd : sd -> string
58-
val seq_sd : sd -> sd -> sd
58+
val seq_sd : sd -> sd -> sd option
5959
val is_same_loc : sd -> bool
60-
val is_both_loc : sd -> bool
60+
val is_diff_loc : sd -> bool
61+
val is_unspec_loc : sd -> bool
6162
(* The first boolean indicates whether wildcard syntax is included in the fold *)
6263
val fold_ie : bool -> (ie -> 'a -> 'a) -> 'a -> 'a
6364
val fold_extr : bool -> (extr -> 'a -> 'a) -> 'a -> 'a

gen/common/edge.ml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ let pp_dp_default tag sd e = sprintf "%s%s%s" tag (pp_sd sd) (pp_extr e)
388388
| Po (sd,_,_) | Fenced (_,sd,_,_) | Dp (_,sd,_) -> sd
389389
| Insert _|Store|Node _|Fr _|Ws _|Rf _|Hat|Rmw _|Id|Leave _|Back _ -> Same
390390

391-
let do_is_diff e = not @@ Code.is_same_loc @@ do_loc_sd e
391+
let do_is_diff e = Code.is_diff_loc @@ do_loc_sd e
392392

393393
let fold_tedges_compat f r =
394394
let r = fold_ie wildcard (fun ie -> f (Ws ie)) r in
@@ -445,7 +445,7 @@ let fold_tedges f r =
445445
let ok_non_rmw e a1 a2 =
446446
(* `do_is_diff` is safe to call when `e` is not
447447
wildcard `*`/UnspecLoc location. *)
448-
Code.is_both_loc @@ do_loc_sd e ||
448+
Code.is_unspec_loc @@ do_loc_sd e ||
449449
do_is_diff e || do_disjoint ||
450450
(overlap_atoms a1 a2 &&
451451
not (do_strict_overlap && same_access_atoms a1 a2))
@@ -1039,7 +1039,11 @@ let fold_tedges f r =
10391039

10401040
(* compact *)
10411041

1042-
let seq_sd e1 e2 = Code.seq_sd (loc_sd e1) (loc_sd e2)
1042+
let seq_sd e1 e2 =
1043+
match Code.seq_sd (loc_sd e1) (loc_sd e2) with
1044+
| None -> Warn.user_error "Unexpected UnspecLoc"
1045+
| Some b -> b
1046+
10431047

10441048
let fst_dp e1 e2 k = match e1.edge with
10451049
| Dp (d,_,_) ->

gen/cycle.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ let next_loc e ((loc0,lab0),vs) = match E.is_fetch e with
470470

471471
let same_loc e = Code.is_same_loc @@ E.loc_sd e
472472

473-
let diff_loc e = not (same_loc e)
473+
let diff_loc e = Code.is_diff_loc @@ E.loc_sd e
474474

475475
let same_proc e = E.get_ie e = Int
476476
let diff_proc e = E.get_ie e = Ext

0 commit comments

Comments
 (0)