Skip to content

Commit 393c4c2

Browse files
committed
Add edge labels to auto-generated Mermaid diagram
- Add label parameter to Registry.add_edge - flatMap, join, union edges labeled with combinator name - fixpoint edges labeled as 'roots' and 'edges' - Regenerate reactive-pipeline-full.mmd with labels
1 parent 8635190 commit 393c4c2

File tree

2 files changed

+98
-86
lines changed

2 files changed

+98
-86
lines changed

analysis/reactive/src/Reactive.ml

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ module Registry = struct
9696
}
9797

9898
let nodes : (string, node_info) Hashtbl.t = Hashtbl.create 64
99+
let edges : (string * string, string) Hashtbl.t = Hashtbl.create 128
99100
let dirty_nodes : string list ref = ref []
100101

101102
let register ~name ~level ~process ~stats =
@@ -113,7 +114,8 @@ module Registry = struct
113114
Hashtbl.replace nodes name info;
114115
info
115116

116-
let add_edge ~from_name ~to_name =
117+
let add_edge ~from_name ~to_name ~label =
118+
Hashtbl.replace edges (from_name, to_name) label;
117119
(match Hashtbl.find_opt nodes from_name with
118120
| Some info -> info.downstream <- to_name :: info.downstream
119121
| None -> ());
@@ -130,6 +132,7 @@ module Registry = struct
130132

131133
let clear () =
132134
Hashtbl.clear nodes;
135+
Hashtbl.clear edges;
133136
dirty_nodes := []
134137

135138
(** Generate Mermaid diagram of the pipeline *)
@@ -141,11 +144,20 @@ module Registry = struct
141144
(* Node with level annotation *)
142145
Buffer.add_string buf
143146
(Printf.sprintf " %s[%s L%d]\n" name name info.level);
144-
(* Edges *)
147+
(* Edges with labels *)
145148
List.iter
146149
(fun downstream ->
147-
Buffer.add_string buf
148-
(Printf.sprintf " %s --> %s\n" name downstream))
150+
let label =
151+
match Hashtbl.find_opt edges (name, downstream) with
152+
| Some l -> l
153+
| None -> ""
154+
in
155+
if label = "" then
156+
Buffer.add_string buf
157+
(Printf.sprintf " %s --> %s\n" name downstream)
158+
else
159+
Buffer.add_string buf
160+
(Printf.sprintf " %s -->|%s| %s\n" name label downstream))
149161
info.downstream)
150162
nodes;
151163
Buffer.contents buf
@@ -458,7 +470,7 @@ let flatMap ~name (src : ('k1, 'v1) t) ~f ?merge () : ('k2, 'v2) t =
458470
let _info =
459471
Registry.register ~name ~level:my_level ~process ~stats:my_stats
460472
in
461-
Registry.add_edge ~from_name:src.name ~to_name:name;
473+
Registry.add_edge ~from_name:src.name ~to_name:name ~label:"flatMap";
462474

463475
(* Subscribe to source: just accumulate *)
464476
src.subscribe (fun delta ->
@@ -697,8 +709,8 @@ let join ~name (left : ('k1, 'v1) t) (right : ('k2, 'v2) t) ~key_of ~f ?merge ()
697709
let _info =
698710
Registry.register ~name ~level:my_level ~process ~stats:my_stats
699711
in
700-
Registry.add_edge ~from_name:left.name ~to_name:name;
701-
Registry.add_edge ~from_name:right.name ~to_name:name;
712+
Registry.add_edge ~from_name:left.name ~to_name:name ~label:"join";
713+
Registry.add_edge ~from_name:right.name ~to_name:name ~label:"join";
702714

703715
(* Subscribe to sources: just accumulate *)
704716
left.subscribe (fun delta ->
@@ -830,8 +842,8 @@ let union ~name (left : ('k, 'v) t) (right : ('k, 'v) t) ?merge () : ('k, 'v) t
830842
let _info =
831843
Registry.register ~name ~level:my_level ~process ~stats:my_stats
832844
in
833-
Registry.add_edge ~from_name:left.name ~to_name:name;
834-
Registry.add_edge ~from_name:right.name ~to_name:name;
845+
Registry.add_edge ~from_name:left.name ~to_name:name ~label:"union";
846+
Registry.add_edge ~from_name:right.name ~to_name:name ~label:"union";
835847

836848
(* Subscribe to sources: just accumulate *)
837849
left.subscribe (fun delta ->
@@ -1032,8 +1044,8 @@ let fixpoint ~name ~(init : ('k, unit) t) ~(edges : ('k, 'k list) t) () :
10321044
let _info =
10331045
Registry.register ~name ~level:my_level ~process ~stats:my_stats
10341046
in
1035-
Registry.add_edge ~from_name:init.name ~to_name:name;
1036-
Registry.add_edge ~from_name:edges.name ~to_name:name;
1047+
Registry.add_edge ~from_name:init.name ~to_name:name ~label:"roots";
1048+
Registry.add_edge ~from_name:edges.name ~to_name:name ~label:"edges";
10371049

10381050
(* Subscribe to sources: just accumulate *)
10391051
init.subscribe (fun delta ->
Lines changed: 75 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,127 +1,127 @@
11
graph TD
22
annotations[annotations L2]
3-
annotations --> solver.incorrect_dead_decls
4-
annotations --> liveness.annotated_roots
3+
annotations -->|join| solver.incorrect_dead_decls
4+
annotations -->|join| liveness.annotated_roots
55
exc_refs.exception_decls[exc_refs.exception_decls L3]
6-
exc_refs.exception_decls --> exc_refs.resolved_refs
6+
exc_refs.exception_decls -->|join| exc_refs.resolved_refs
77
type_deps.same_path_refs[type_deps.same_path_refs L4]
8-
type_deps.same_path_refs --> type_deps.u1
8+
type_deps.same_path_refs -->|union| type_deps.u1
99
file_collection[file_collection L0]
10-
file_collection --> file_data_collection
10+
file_collection -->|flatMap| file_data_collection
1111
decl_refs.value_decl_refs[decl_refs.value_decl_refs L7]
12-
decl_refs.value_decl_refs --> decl_refs.with_value_refs
12+
decl_refs.value_decl_refs -->|join| decl_refs.with_value_refs
1313
type_deps.combined_refs_to[type_deps.combined_refs_to L7]
14-
type_deps.combined_refs_to --> type_deps.all_type_refs_from
14+
type_deps.combined_refs_to -->|flatMap| type_deps.all_type_refs_from
1515
type_deps.all_type_refs_from[type_deps.all_type_refs_from L8]
16-
type_deps.all_type_refs_from --> liveness.type_refs_from
16+
type_deps.all_type_refs_from -->|union| liveness.type_refs_from
1717
type_deps.impl_needing_path2[type_deps.impl_needing_path2 L4]
18-
type_deps.impl_needing_path2 --> type_deps.impl_to_intf_refs_path2
18+
type_deps.impl_needing_path2 -->|join| type_deps.impl_to_intf_refs_path2
1919
exc_refs.resolved_refs_from[exc_refs.resolved_refs_from L5]
20-
exc_refs.resolved_refs_from --> liveness.value_refs_from
20+
exc_refs.resolved_refs_from -->|union| liveness.value_refs_from
2121
exc_refs.resolved_refs[exc_refs.resolved_refs L4]
22-
exc_refs.resolved_refs --> exc_refs.resolved_refs_from
22+
exc_refs.resolved_refs -->|flatMap| exc_refs.resolved_refs_from
2323
type_deps.impl_to_intf_refs_path2[type_deps.impl_to_intf_refs_path2 L5]
24-
type_deps.impl_to_intf_refs_path2 --> type_deps.u2
24+
type_deps.impl_to_intf_refs_path2 -->|union| type_deps.u2
2525
file_deps_map[file_deps_map L2]
2626
decl_refs.with_value_refs[decl_refs.with_value_refs L8]
27-
decl_refs.with_value_refs --> decl_refs.combined
27+
decl_refs.with_value_refs -->|join| decl_refs.combined
2828
type_deps.u1[type_deps.u1 L5]
29-
type_deps.u1 --> type_deps.u2
29+
type_deps.u1 -->|union| type_deps.u2
3030
cross_file_items[cross_file_items L2]
31-
cross_file_items --> exception_refs_collection
31+
cross_file_items -->|flatMap| exception_refs_collection
3232
decl_refs.decls_by_file[decl_refs.decls_by_file L3]
33-
decl_refs.decls_by_file --> decl_refs.type_decl_refs
34-
decl_refs.decls_by_file --> decl_refs.value_decl_refs
33+
decl_refs.decls_by_file -->|join| decl_refs.type_decl_refs
34+
decl_refs.decls_by_file -->|join| decl_refs.value_decl_refs
3535
type_deps.impl_to_intf_refs[type_deps.impl_to_intf_refs L4]
36-
type_deps.impl_to_intf_refs --> type_deps.u1
36+
type_deps.impl_to_intf_refs -->|union| type_deps.u1
3737
solver.issues_by_file[solver.issues_by_file L17]
38-
solver.issues_by_file --> solver.modules_with_reported
38+
solver.issues_by_file -->|flatMap| solver.modules_with_reported
3939
liveness.annotated_roots[liveness.annotated_roots L3]
40-
liveness.annotated_roots --> liveness.all_roots
40+
liveness.annotated_roots -->|union| liveness.all_roots
4141
solver.incorrect_dead_decls[solver.incorrect_dead_decls L16]
4242
type_deps.intf_to_impl_refs[type_deps.intf_to_impl_refs L4]
43-
type_deps.intf_to_impl_refs --> type_deps.combined_refs_to
43+
type_deps.intf_to_impl_refs -->|union| type_deps.combined_refs_to
4444
type_deps.decl_by_path[type_deps.decl_by_path L3]
45-
type_deps.decl_by_path --> type_deps.intf_to_impl_refs
46-
type_deps.decl_by_path --> type_deps.impl_to_intf_refs_path2
47-
type_deps.decl_by_path --> type_deps.impl_needing_path2
48-
type_deps.decl_by_path --> type_deps.impl_to_intf_refs
49-
type_deps.decl_by_path --> type_deps.same_path_refs
45+
type_deps.decl_by_path -->|join| type_deps.intf_to_impl_refs
46+
type_deps.decl_by_path -->|join| type_deps.impl_to_intf_refs_path2
47+
type_deps.decl_by_path -->|join| type_deps.impl_needing_path2
48+
type_deps.decl_by_path -->|join| type_deps.impl_to_intf_refs
49+
type_deps.decl_by_path -->|flatMap| type_deps.same_path_refs
5050
type_deps.u2[type_deps.u2 L6]
51-
type_deps.u2 --> type_deps.combined_refs_to
51+
type_deps.u2 -->|union| type_deps.combined_refs_to
5252
solver.live_decls[solver.live_decls L15]
53-
solver.live_decls --> solver.incorrect_dead_decls
54-
solver.live_decls --> solver.modules_with_live
53+
solver.live_decls -->|join| solver.incorrect_dead_decls
54+
solver.live_decls -->|flatMap| solver.modules_with_live
5555
type_deps.impl_decls[type_deps.impl_decls L3]
56-
type_deps.impl_decls --> type_deps.impl_needing_path2
57-
type_deps.impl_decls --> type_deps.impl_to_intf_refs
56+
type_deps.impl_decls -->|join| type_deps.impl_needing_path2
57+
type_deps.impl_decls -->|join| type_deps.impl_to_intf_refs
5858
liveness.all_roots[liveness.all_roots L12]
59-
liveness.all_roots --> liveness.live
59+
liveness.all_roots -->|roots| liveness.live
6060
solver.dead_modules[solver.dead_modules L17]
61-
solver.dead_modules --> solver.dead_module_issues
61+
solver.dead_modules -->|join| solver.dead_module_issues
6262
liveness.external_type_refs[liveness.external_type_refs L10]
63-
liveness.external_type_refs --> liveness.externally_referenced
63+
liveness.external_type_refs -->|union| liveness.externally_referenced
6464
decl_refs.combined[decl_refs.combined L12]
65-
decl_refs.combined --> liveness.edges
65+
decl_refs.combined -->|flatMap| liveness.edges
6666
type_refs_from[type_refs_from L2]
67-
type_refs_from --> liveness.type_refs_from
67+
type_refs_from -->|union| liveness.type_refs_from
6868
liveness.type_refs_from[liveness.type_refs_from L9]
69-
liveness.type_refs_from --> liveness.external_type_refs
70-
liveness.type_refs_from --> decl_refs.type_decl_refs
69+
liveness.type_refs_from -->|join| liveness.external_type_refs
70+
liveness.type_refs_from -->|join| decl_refs.type_decl_refs
7171
solver.dead_decls_by_file[solver.dead_decls_by_file L16]
72-
solver.dead_decls_by_file --> solver.issues_by_file
72+
solver.dead_decls_by_file -->|flatMap| solver.issues_by_file
7373
liveness.external_value_refs[liveness.external_value_refs L7]
74-
liveness.external_value_refs --> liveness.externally_referenced
74+
liveness.external_value_refs -->|union| liveness.externally_referenced
7575
liveness.value_refs_from[liveness.value_refs_from L6]
76-
liveness.value_refs_from --> liveness.external_value_refs
77-
liveness.value_refs_from --> decl_refs.value_decl_refs
76+
liveness.value_refs_from -->|join| liveness.external_value_refs
77+
liveness.value_refs_from -->|join| decl_refs.value_decl_refs
7878
value_refs_from[value_refs_from L2]
79-
value_refs_from --> liveness.value_refs_from
79+
value_refs_from -->|union| liveness.value_refs_from
8080
solver.modules_with_dead[solver.modules_with_dead L16]
81-
solver.modules_with_dead --> solver.dead_modules
81+
solver.modules_with_dead -->|join| solver.dead_modules
8282
solver.dead_decls[solver.dead_decls L15]
83-
solver.dead_decls --> solver.dead_decls_by_file
84-
solver.dead_decls --> solver.modules_with_dead
83+
solver.dead_decls -->|flatMap| solver.dead_decls_by_file
84+
solver.dead_decls -->|flatMap| solver.modules_with_dead
8585
exception_refs_collection[exception_refs_collection L3]
86-
exception_refs_collection --> exc_refs.resolved_refs
86+
exception_refs_collection -->|join| exc_refs.resolved_refs
8787
type_deps.intf_decls[type_deps.intf_decls L3]
88-
type_deps.intf_decls --> type_deps.intf_to_impl_refs
88+
type_deps.intf_decls -->|join| type_deps.intf_to_impl_refs
8989
file_data_collection[file_data_collection L1]
90-
file_data_collection --> files
91-
file_data_collection --> file_deps_map
92-
file_data_collection --> cross_file_items
93-
file_data_collection --> type_refs_from
94-
file_data_collection --> value_refs_from
95-
file_data_collection --> annotations
96-
file_data_collection --> decls
90+
file_data_collection -->|flatMap| files
91+
file_data_collection -->|flatMap| file_deps_map
92+
file_data_collection -->|flatMap| cross_file_items
93+
file_data_collection -->|flatMap| type_refs_from
94+
file_data_collection -->|flatMap| value_refs_from
95+
file_data_collection -->|flatMap| annotations
96+
file_data_collection -->|flatMap| decls
9797
solver.dead_module_issues[solver.dead_module_issues L19]
9898
decl_refs.with_type_refs[decl_refs.with_type_refs L11]
99-
decl_refs.with_type_refs --> decl_refs.combined
99+
decl_refs.with_type_refs -->|join| decl_refs.combined
100100
solver.modules_with_live[solver.modules_with_live L16]
101-
solver.modules_with_live --> solver.dead_modules
101+
solver.modules_with_live -->|join| solver.dead_modules
102102
decl_refs.type_decl_refs[decl_refs.type_decl_refs L10]
103-
decl_refs.type_decl_refs --> decl_refs.with_type_refs
103+
decl_refs.type_decl_refs -->|join| decl_refs.with_type_refs
104104
files[files L2]
105105
solver.modules_with_reported[solver.modules_with_reported L18]
106-
solver.modules_with_reported --> solver.dead_module_issues
106+
solver.modules_with_reported -->|join| solver.dead_module_issues
107107
liveness.externally_referenced[liveness.externally_referenced L11]
108-
liveness.externally_referenced --> liveness.all_roots
108+
liveness.externally_referenced -->|union| liveness.all_roots
109109
liveness.edges[liveness.edges L13]
110-
liveness.edges --> liveness.live
110+
liveness.edges -->|edges| liveness.live
111111
liveness.live[liveness.live L14]
112-
liveness.live --> solver.live_decls
113-
liveness.live --> solver.dead_decls
112+
liveness.live -->|join| solver.live_decls
113+
liveness.live -->|join| solver.dead_decls
114114
decls[decls L2]
115-
decls --> solver.live_decls
116-
decls --> solver.dead_decls
117-
decls --> liveness.annotated_roots
118-
decls --> liveness.external_type_refs
119-
decls --> liveness.external_value_refs
120-
decls --> decl_refs.with_type_refs
121-
decls --> decl_refs.with_value_refs
122-
decls --> decl_refs.decls_by_file
123-
decls --> exc_refs.exception_decls
124-
decls --> type_deps.intf_decls
125-
decls --> type_deps.impl_decls
126-
decls --> type_deps.decl_by_path
115+
decls -->|join| solver.live_decls
116+
decls -->|join| solver.dead_decls
117+
decls -->|join| liveness.annotated_roots
118+
decls -->|join| liveness.external_type_refs
119+
decls -->|join| liveness.external_value_refs
120+
decls -->|join| decl_refs.with_type_refs
121+
decls -->|join| decl_refs.with_value_refs
122+
decls -->|flatMap| decl_refs.decls_by_file
123+
decls -->|flatMap| exc_refs.exception_decls
124+
decls -->|flatMap| type_deps.intf_decls
125+
decls -->|flatMap| type_deps.impl_decls
126+
decls -->|flatMap| type_deps.decl_by_path
127127

0 commit comments

Comments
 (0)