Skip to content

Commit 6d0e55d

Browse files
committed
Extract ControlSpecC to file module to allow dependency cycle breaking
1 parent f4ec418 commit 6d0e55d

File tree

4 files changed

+56
-58
lines changed

4 files changed

+56
-58
lines changed

src/framework/analyses.ml

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -328,63 +328,6 @@ struct
328328
end
329329

330330

331-
(** Reference to top-level Control Spec context first-class module. *)
332-
let control_spec_c: (module Printable.S) ref =
333-
let module Failwith = Printable.Failwith (
334-
struct
335-
let message = "uninitialized control_spec_c"
336-
end
337-
)
338-
in
339-
ref (module Failwith: Printable.S)
340-
341-
(** Top-level Control Spec context as static module, which delegates to {!control_spec_c}.
342-
This allows using top-level context values inside individual analyses. *)
343-
module ControlSpecC: Printable.S =
344-
struct
345-
type t = Obj.t (** represents [(val !control_spec_c).t] *)
346-
347-
(* The extra level of indirection allows calls to this static module to go to a dynamic first-class module. *)
348-
349-
let name () =
350-
let module C = (val !control_spec_c) in
351-
C.name ()
352-
353-
let equal x y =
354-
let module C = (val !control_spec_c) in
355-
C.equal (Obj.obj x) (Obj.obj y)
356-
let compare x y =
357-
let module C = (val !control_spec_c) in
358-
C.compare (Obj.obj x) (Obj.obj y)
359-
let hash x =
360-
let module C = (val !control_spec_c) in
361-
C.hash (Obj.obj x)
362-
let tag x =
363-
let module C = (val !control_spec_c) in
364-
C.tag (Obj.obj x)
365-
366-
let show x =
367-
let module C = (val !control_spec_c) in
368-
C.show (Obj.obj x)
369-
let pretty () x =
370-
let module C = (val !control_spec_c) in
371-
C.pretty () (Obj.obj x)
372-
let printXml f x =
373-
let module C = (val !control_spec_c) in
374-
C.printXml f (Obj.obj x)
375-
let to_yojson x =
376-
let module C = (val !control_spec_c) in
377-
C.to_yojson (Obj.obj x)
378-
379-
let arbitrary () =
380-
let module C = (val !control_spec_c) in
381-
QCheck.map ~rev:Obj.obj Obj.repr (C.arbitrary ())
382-
let relift x =
383-
let module C = (val !control_spec_c) in
384-
Obj.repr (C.relift (Obj.obj x))
385-
end
386-
387-
388331
(* Experiment to reduce the number of arguments on transfer functions and allow
389332
sub-analyses. The list sub contains the current local states of analyses in
390333
the same order as written in the dependencies list (in MCP).

src/framework/control.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ let spec_module: (module Spec) Lazy.t = lazy (
3434
|> lift (get_bool "ana.widen.tokens") (module WideningTokens.Lifter)
3535
) in
3636
GobConfig.building_spec := false;
37-
Analyses.control_spec_c := (module S1.C);
37+
ControlSpecC.control_spec_c := (module S1.C);
3838
(module S1)
3939
)
4040

src/framework/controlSpecC.ml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
module Failwith = Printable.Failwith (
2+
struct
3+
let message = "uninitialized control_spec_c"
4+
end
5+
)
6+
7+
let control_spec_c: (module Printable.S) ref = ref (module Failwith: Printable.S)
8+
9+
10+
type t = Obj.t (** represents [(val !control_spec_c).t] *)
11+
12+
(* The extra level of indirection allows calls to this static module to go to a dynamic first-class module. *)
13+
14+
let name () =
15+
let module C = (val !control_spec_c) in
16+
C.name ()
17+
18+
let equal x y =
19+
let module C = (val !control_spec_c) in
20+
C.equal (Obj.obj x) (Obj.obj y)
21+
let compare x y =
22+
let module C = (val !control_spec_c) in
23+
C.compare (Obj.obj x) (Obj.obj y)
24+
let hash x =
25+
let module C = (val !control_spec_c) in
26+
C.hash (Obj.obj x)
27+
let tag x =
28+
let module C = (val !control_spec_c) in
29+
C.tag (Obj.obj x)
30+
31+
let show x =
32+
let module C = (val !control_spec_c) in
33+
C.show (Obj.obj x)
34+
let pretty () x =
35+
let module C = (val !control_spec_c) in
36+
C.pretty () (Obj.obj x)
37+
let printXml f x =
38+
let module C = (val !control_spec_c) in
39+
C.printXml f (Obj.obj x)
40+
let to_yojson x =
41+
let module C = (val !control_spec_c) in
42+
C.to_yojson (Obj.obj x)
43+
44+
let arbitrary () =
45+
let module C = (val !control_spec_c) in
46+
QCheck.map ~rev:Obj.obj Obj.repr (C.arbitrary ())
47+
let relift x =
48+
let module C = (val !control_spec_c) in
49+
Obj.repr (C.relift (Obj.obj x))

src/framework/controlSpecC.mli

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
(** Top-level Control Spec context as static module, which delegates to {!control_spec_c}.
2+
This allows using top-level context values inside individual analyses. *)
3+
include Printable.S
4+
5+
(** Reference to top-level Control Spec context first-class module. *)
6+
val control_spec_c: (module Printable.S) ref

0 commit comments

Comments
 (0)