Skip to content

Commit d8fbd67

Browse files
committed
bu/wbu now with sound narrowing per origin at globals
1 parent 8574229 commit d8fbd67

File tree

2 files changed

+51
-27
lines changed

2 files changed

+51
-27
lines changed

src/framework/bu.ml

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ module FwdBuSolver (System: FwdGlobConstrSys) = struct
1414
module GM = Hashtbl.Make(System.GVar)
1515
module LM = Hashtbl.Make(System.LVar)
1616

17+
(*
1718
module OM = LM
1819
let source x = x
19-
(*
20+
*)
21+
2022
module OM = Hashtbl.Make(Node)
2123
let source = System.LVar.node
22-
*)
2324
let gas_default = ref (10,3)
2425

2526
let lwarrow (a,delay,gas,narrow) b =
@@ -66,7 +67,8 @@ module FwdBuSolver (System: FwdGlobConstrSys) = struct
6667
let _ = work := (xs,s) in
6768
Some x
6869

69-
type glob = {value : G.t; init : G.t; infl : LS.t ; from : (G.t * int * int * bool) OM.t}
70+
type glob = {value : G.t; init : G.t; infl : LS.t ; last: G.t LM.t;
71+
from : (G.t * int * int * bool * LS.t) OM.t}
7072

7173
let glob: glob GM.t = GM.create 100
7274

@@ -77,7 +79,7 @@ module FwdBuSolver (System: FwdGlobConstrSys) = struct
7779
with _ ->
7880
(
7981
if tracing then trace "unknownsize" "Number of globals so far: %d" (GM.length glob);
80-
let rglob = {value = G.bot (); init = G.bot (); infl = LS.empty; from = OM.create 10} in
82+
let rglob = {value = G.bot (); init = G.bot (); infl = LS.empty; last = LM.create 10; from = OM.create 10} in
8183
GM.add glob g rglob;
8284
rglob
8385
)
@@ -87,17 +89,23 @@ module FwdBuSolver (System: FwdGlobConstrSys) = struct
8789
value = d;
8890
init = d;
8991
infl = LS.empty;
92+
last = LM.create 10;
9093
from = OM.create 10
9194
}
9295

93-
let get_global_value init from = OM.fold (fun _ (b,_,_,_) a -> G.join a b) from init
96+
let get_global_value init from = OM.fold (fun _ (b,_,_,_,_) a -> G.join a b) from init
9497

95-
let get_old_global_value x from =
96-
try OM.find from x
98+
let get_old_global_value orig from =
99+
try OM.find from orig
97100
with _ ->
98101
let (delay,gas) = !gas_default in
99-
OM.add from x (G.bot (),delay,gas,false);
100-
(G. bot (),delay,gas,false)
102+
OM.add from orig (G.bot (),delay,gas,false,LS.empty);
103+
(G.bot (),delay,gas,false,LS.empty)
104+
105+
let get_last_contrib orig set last =
106+
LS.fold (fun x d -> G.join d (LM.find last x)) set (G.bot())
107+
108+
(* determine the join of all last contribs of unknowns with same orig *)
101109

102110
(* now the getters for globals *)
103111

@@ -161,22 +169,26 @@ module FwdBuSolver (System: FwdGlobConstrSys) = struct
161169
*)
162170
in
163171
(* if tracing then trace "set_global" "set_global: \n From: %a \nOn:%a \n Value: %a" System.LVar.pretty_trace x System.GVar.pretty_trace g G.pretty d; *)
164-
let {value;init;infl;from} = get_global_ref g in
165-
let (old_xg,delay,gas,narrow) = get_old_global_value sx from in
166-
let (new_xg,delay,gas,narrow) = gwarrow (old_xg,delay,gas,narrow) d in
172+
let {value;init;infl;last;from} = get_global_ref g in
173+
let (old_xg,delay,gas,narrow,set) = get_old_global_value sx from in
174+
let () = LM.add last x d in
175+
let set = LS.add x set in
176+
let d_new = get_last_contrib sx set last in
177+
let (new_xg,delay,gas,narrow) = gwarrow (old_xg,delay,gas,narrow) d_new in
178+
let () = OM.replace from sx (new_xg,delay,gas,narrow,set) in
167179
if G.equal new_xg old_xg then (
168-
if tracing then trace "set_globalc" "no change!"
180+
if tracing then trace "set_globalc" "no change!";
169181
)
170182
else
171183
begin
172184
if tracing then trace "set_globalc" "new contribution registered!";
173-
let _ = OM.replace from sx (new_xg,delay,gas,narrow) in
174185
let new_g = get_global_value init from in
175186
if G.equal value new_g then
176187
()
177188
else
189+
let () = GM.replace glob g {value = new_g; init = init; infl = LS.empty;last;from} in
178190
let work = infl in
179-
let _ = GM.replace glob g {value = new_g; init = init; infl = LS.empty; from} in
191+
let _ = GM.replace glob g {value = new_g; init = init; infl = LS.empty; last; from} in
180192
let doit x =
181193
let r = get_local_ref x in
182194
if !(r.called) then r.aborted := true

src/framework/wbu.ml

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ module FwdWBuSolver (System: FwdGlobConstrSys) = struct
1414
module GM = Hashtbl.Make(System.GVar)
1515
module LM = Hashtbl.Make(System.LVar)
1616

17+
(*
1718
module OM = LM
1819
let source x = x
19-
(*
20+
*)
2021
module OM = Hashtbl.Make(Node)
2122
let source = System.LVar.node
22-
*)
23+
2324
let gas_default = ref (10,3)
2425

2526
let lwarrow (a,delay,gas,narrow) b =
@@ -89,7 +90,9 @@ module FwdWBuSolver (System: FwdGlobConstrSys) = struct
8990
Some x
9091
)
9192

92-
type glob = {value : G.t; init : G.t; infl : LS.t ; from : (G.t * int * int * bool) OM.t}
93+
type glob = {value : G.t; init : G.t; infl : LS.t ; last: G.t LM.t;
94+
from : (G.t * int * int * bool * LS.t) OM.t}
95+
9396

9497
let glob: glob GM.t = GM.create 100
9598

@@ -100,7 +103,7 @@ module FwdWBuSolver (System: FwdGlobConstrSys) = struct
100103
with _ ->
101104
(
102105
if tracing then trace "unknownsize" "Number of globals so far: %d" (GM.length glob);
103-
let rglob = {value = G.bot (); init = G.bot (); infl = LS.empty; from = OM.create 10} in
106+
let rglob = {value = G.bot (); init = G.bot (); infl = LS.empty; last = LM.create 10; from = OM.create 10} in
104107
GM.add glob g rglob;
105108
rglob
106109
)
@@ -110,17 +113,23 @@ module FwdWBuSolver (System: FwdGlobConstrSys) = struct
110113
value = d;
111114
init = d;
112115
infl = LS.empty;
116+
last = LM.create 10;
113117
from = OM.create 10
114118
}
115119

116-
let get_global_value init from = OM.fold (fun _ (b,_,_,_) a -> G.join a b) from init
120+
let get_global_value init from = OM.fold (fun _ (b,_,_,_,_) a -> G.join a b) from init
117121

118122
let get_old_global_value x from =
119123
try OM.find from x
120124
with _ ->
121125
let (delay,gas) = !gas_default in
122-
OM.add from x (G.bot (),delay,gas,false);
123-
(G. bot (),delay,gas,false)
126+
OM.add from x (G.bot (),delay,gas,false,LS.empty);
127+
(G. bot (),delay,gas,false,LS.empty)
128+
129+
let get_last_contrib orig set last =
130+
LS.fold (fun x d -> G.join d (LM.find last x)) set (G.bot())
131+
132+
(* determine the join of all last contribs of unknowns with same orig *)
124133

125134
(* now the getters for globals *)
126135

@@ -184,22 +193,25 @@ module FwdWBuSolver (System: FwdGlobConstrSys) = struct
184193
*)
185194
in
186195
(* if tracing then trace "set_global" "set_global: \n From: %a \nOn:%a \n Value: %a" System.LVar.pretty_trace x System.GVar.pretty_trace g G.pretty d; *)
187-
let {value;init;infl;from} = get_global_ref g in
188-
let (old_xg,delay,gas,narrow) = get_old_global_value sx from in
189-
let (new_xg,delay,gas,narrow) = gwarrow (old_xg,delay,gas,narrow) d in
196+
let {value;init;infl;last;from} = get_global_ref g in
197+
let (old_xg,delay,gas,narrow,set) = get_old_global_value sx from in
198+
let () = LM.add last x d in
199+
let set = LS.add x set in
200+
let d_new = get_last_contrib sx set last in
201+
let (new_xg,delay,gas,narrow) = gwarrow (old_xg,delay,gas,narrow) d_new in
202+
let () = OM.replace from sx (new_xg,delay,gas,narrow,set) in
190203
if G.equal new_xg old_xg then (
191204
if tracing then trace "set_globalc" "no change!"
192205
)
193206
else
194207
begin
195208
if tracing then trace "set_globalc" "new contribution registered!";
196-
let _ = OM.replace from sx (new_xg,delay,gas,narrow) in
197209
let new_g = get_global_value init from in
198210
if G.equal value new_g then
199211
()
200212
else
201213
let work = infl in
202-
let _ = GM.replace glob g {value = new_g; init = init; infl = LS.empty; from} in
214+
let _ = GM.replace glob g {value = new_g; init = init; infl = LS.empty; last; from} in
203215
let doit x =
204216
let r = get_local_ref x in
205217
if !(r.called) then r.aborted := true

0 commit comments

Comments
 (0)