-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathmeta.yml
More file actions
357 lines (271 loc) · 10.4 KB
/
Copy pathmeta.yml
File metadata and controls
357 lines (271 loc) · 10.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
---
fullname: coq-dpdgraph
shortname: coq-dpdgraph
opam_name: coq-dpdgraph
organization: rocq-community
community: true
action: true
plugin: true
branch: 'coq-master'
synopsis: >-
Compute dependencies between Rocq objects (definitions, theorems) and produce graphs
description: |-
Rocq plugin that extracts the dependencies between Coq objects,
and produces files with dependency information. Includes tools
to visualize dependency graphs and find unused definitions.
authors:
- name: Anne Pacalet
- name: Yves Bertot
- name: Olivier Pons
maintainers:
- name: Yves Bertot
nickname: ybertot
opam-file-maintainer: palmskog@gmail.com
opam-file-version: dev
license:
fullname: GNU Lesser General Public License v2.1
identifier: LGPL-2.1-only
supported_rocq_versions:
text: master (use the corresponding branch or release for other Coq versions)
opam: '{= "dev"}'
supported_ocaml_versions:
text: 4.09.0 or later
opam: '{>= "4.09.0"}'
dependencies:
- opam:
name: ocamlgraph
description: |-
[OCamlgraph](https://github.com/backtracking/ocamlgraph)
tested_rocq_opam_versions:
- version: dev
action_appendix: |2-
export: 'OPAMWITHTEST'
env:
OPAMWITHTEST: true
test_target:
test-suite
namespace: dpdgraph
keywords:
- name: dependency graph
- name: dependency analysis
categories:
- name: Miscellaneous/Coq Extensions
build: |-
## What's inside?
First of all, it is a small tool (a Rocq plugin) that extracts the
dependencies between Rocq objects, and produces a file (we suggest using
the suffix .dpd) with this information.
The idea is that other small tools can be then developed to process
the .dpd files. At the moment, there is:
- `dpd2dot` that reads these .dpd files and produces a graph file
using .dot format (cf. http://www.graphviz.org/) that makes possible to view
them;
- `dpdusage`: to find unused definitions.
Hope other tools later on to do more things. Feel free to contribute!
## How to get it
You can:
- either clone it from GitHub at: https://github.com/rocq-community/coq-dpdgraph
- or get the opam package named `coq-dpdgraph` from the rocq opam archive (repository "released")
- or get the [latest distributed version](https://github.com/rocq-community/coq-dpdgraph/releases)
### Compilation
To perform you own compilation, you need that `ocamlgraph` is installed
(for instance using `opam install ocamlgraph`).
Download the archive and unpack it (or clone the repository),
and change directory to the `coq-dpdgraph` directory. The `coq-master`
branch of the repository is maintained to compile with the development
version of `rocq`. To compile with a released version of `rocq`, you need
to download the corresponding tagged version from the `git` repository.
For instance, the version that is compatible with `rocq` version 9 is
available at the tag `v1.0+9.0`.
To just compile, you should type the following command
$ make
When this compilation succeeds, the plugin is located in the compilation
directory and can be used by relying on
`-I *the directory* -R *the directory* dpdgraph`
To compile and install the plugin, type the following command
$ make && make install
When this compilation succeeds, the plugin can be used directly, and the
compilation directory can be safely removed.
### Install using opam
If you use opam with recent versions of Rocq or Coq you can install
`coq-dpdgraph` and `ocamlgraph` using
$ opam repo add coq-released https://rocq-prover.org/opam/released
$ opam install coq-dpdgraph
To install a specific release of `coq-dpdgraph` for a previous version of
Rocq or Coq, add the appropriate suffix, for example,
$ opam install coq-dpdgraph.1.0+9.0
### Test
If you install the archive by cloning the git repository, you have
a sub-directory containing test files. These can be tested using the
following command.
$ make -s test
to check if everything is ok.
documentation: |
## How to use it
### Requirements
- to have compiled the tools (see above)
- a compiled Coq file.
You can for instance use `tests/Test.v` (a modified clone of Rocq `List.v`)
and compile it doing :
```shell
$ rocq compile tests/Test.v
```
### Generation of .dpd files
The available commands are :
- Generate dependencies between a list of objects:
Print FileDependGraph <module name list>.
A module can be a file, or a sub-module in a file.
Example :
Print FileDependGraph M M2.A.B.
Take all the objects of the specified modules and build the dependencies
between them.
- Generate the dependencies of one or more objects:
Print DependGraph my_lemma my_other_lemma.
Analyse recursively the dependencies of the given objects.
- Change the name of the generated file (default is ``graph.dpd``):
Set DependGraph File "f.dpd".
Useful when one needs to build several files in one session.
**Advice:**
you need to use ``Require`` to load the module that you want to explore,
but don't use any ``Import``/``Export``
command because the tool is then unable
to properly group the nodes by modules.
**Example:**
```
$ rlwrap rocq repl -R . dpdgraph -I .
Welcome to Rocq 9.0.0
Rocq < Require dpdgraph.dpdgraph.
[Loading ML file coq-dpdgraph.plugin ... done]
Coq < From Stdlib Require List.
Coq < Print FileDependGraph List.
Print FileDependGraph List.
Fetching opaque proofs from disk for Stdlib.Lists.List
Info: output dependencies in file graph.dpd
Coq < Set DependGraph File "graph2.dpd".
^D
```
### dpd2dot: from a .dpd file to a .dot file
#### Graph generation
```
$ ./dpd2dot graph.dpd
Info: read file graph.dpd
Info: Graph output in graph.dot
```
There are some options :
```
$ ./dpd2dot -help
Usage : ./dpd2dot [options]
-o : name of output file (default: name of input file .dot)
-with-defs : show everything (default)
-without-defs : show only Prop objects
-rm-trans : remove transitive dependencies (default)
-keep-trans : keep transitive dependencies
-debug : set debug mode
-help Display this list of options
--help Display this list of options
```
If the name of the output file finishes with ``.dot``, then the name before
the ``.dot`` suffix is used as the graph name in the dot syntax. There
are two exceptions: ``graph`` and ``digraph`` will be replaced with
``escaped_graph`` and ``escaped_digraph`` respectively.
The only useful option at the moment is ``-without-defs`` that export only
``Prop`` objects to the graph (``Axiom``, ``Theorem``, ``Lemma``, etc).
#### Graph visualisation
You need :
- [graphviz](http://www.graphviz.org/) (ie. dot tool)
- a visualizer:
we tested [zgrviewer](http://zvtm.sourceforge.net/zgrviewer.html),
[xdot](https://pypi.python.org/pypi/xdot),
[kgraphviewer](https://extragear.kde.org/apps/kgraphviewer/),
but there are others.
You can also convert .dot file to .svg file using :
```
$ dot -Tsvg file.dot > file.svg
```
You can then use ``firefox`` or ``inskape`` to view the ``.svg`` graph.
The main advantage of using ``firefox`` is that the nodes are linked to
the ``coqdoc`` pages if they have been generated in the same directory.
But the navigation (zoom, moves) is very poor and slow.
#### Graph interpretation
The graph can be interpreted like this :
- edge n1 --> n2 : n1 uses n2
- node :
- green : proved lemma
- orange : axiom/admitted lemma
- dark pink : Definition, etc
- light pink : Parameter, etc
- violet : inductive,
- blue : constructor,
- multi-circled : not used (no predecessor in the graph)
- yellow box : module
- objects that are not in a yellow box are Coq objects.
### dpdusage: find unused definitions via .dpd file
You can use ``dpdusage`` command to find unused definitions.
Example:
```
$ ./dpdusage tests/graph2.dpd
Info: read file tests/graph2.dpd
Permutation_app_swap (0)
```
In the example above it reports that ``Permutation_app_swap`` was
referenced 0 times. You can specify max number of references allowed
(default 0) via ``-threshold`` command line option.
## Making new releases for each version of Rocq
- The coq-master branch is maintained to compile with the current
version of the rocq prover master branch. Rocq developers usually
take care of that. When a version of this package needs to be produced
to be used in an opam package, it is usually necessary to find in the
history the closest commit to the date of the release of rocq that is
aimed for.
- Once this commit is found it is reasonable to mark this as a branch and
use it to produce a release on github. This branch can be used to produce
a compressed tar archive as follows.
```
git checkout -b <branch-name>
git archive --format tgz -o coq-dpdgraph-1.0-9.1.tgz
```
The `tgz` file thus produced should be uploaded to a new release on github
and this file's url should be used in a new opam package description
in the opam archive.
## Development information
### Generated ``.dpd`` format description
```
graph : obj_list
obj : node | edge
node : "N: " node_id node_name node_attributes ';'
node_id : [0-9]+
node_name : '"' string '"'
node_attributes :
| empty
| '[' node_attribute_list ']'
node_attribute_list :
| empty
| node_attribute ',' node_attribute_list
node_attribute :
| kind=[cnst|inductive|construct]
| prop=[yes|no]
| path="m0.m1.m2"
| body=[yes|no]
edge : "E: " node_id node_id edge_attributes ';'
edge_attributes :
| empty
| '[' edge_attribute_list ']'
edge_attribute_list :
| empty
| edge_attribute ',' edge_attribute_list
edge_attribute :
| weight=NUM
```
The parser accept .dpd files as described above,
but also any attribute for nodes and edges having the form :
``prop=val`` or ``prop="string..."`` or ``prop=NUM``
so that the generated ``.dpd`` can have new attributes without having to change
the other tools.
Each tool can then pick the attributes that it is able to handle;
they are not supposed to raise an error whenever there is
an unknown attribute.
## More information
Also see:
- [CHANGES](CHANGES.md)
- [distributed versions](https://anne.pacalet.fr/dev/dpdgraph/)
---