www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Phobos import graph

reply Philippe Sigaud <philippe.sigaud gmail.com> writes:
Hi,

reading the std.all threads, I got curious as to how the different
Phobos modules import each other. A dependency graph, if you will,
though I'm sure to use that in a correct way.

Funnily, I wrote yesterday an importGraph function that, given a
module name and an optional directory where DMD is installed,
crawls the module, find import statements and recursively calls
itself with these new modules, building an import graph at the same
time. It's mostly made to give a dependency graph for a project,
but could be used on Phobos.

So, I created a stdall module importing all Phobos and got my
function to graph it (btw, it's cool to see it can read and kind-
of-parse all of Phobos and core in a few tens of ms).

For those interested, the result is there:

http://www.dsource.org/projects/dranges/browser/downloads/Phobos_gr
aph.pdf
(thanks graphviz)

A few notes:

- A ---> B means 'A imports B'.

- my parsing is primitive: I deal correctly with public/static
imports, multiline imports, renaming imports (import io =
std.stdio;) and partial imports (import std.stdio: writefln,
writef;), but don't test for comments. So modules with docs
containing import statements, mostly of themselves, will get a loop
A ---> A. You can see that in std.demangle or format, for example.

- The result is a Graph class, I have a toGraphviz function that
writes the graph as a .dot file. That's useful to debug graph
algorithms :-)

- if anyone can teach me how to use std.process to then call "dot -
Tpdf graph.dot -o graph.pdf" to generate the pdf graph from a .dot
file, I'd be most grateful. I can't get std.process to do anything,
not even creating a directory. I'm under Vista.

- There is probably a way to get the most imported modules at the
bottom of the graph, and the main 'importers' at the top. I don't
know graphviz enough. Maybe if I sort the module by number of
imports?

- I know how std.x.y works, but not core.*. When I get a core.x.y
module, I don't know where to find it. They don't seem to be all in
druntime\import\core nor in druntime\src\core. So i just create a
core.x.y node and don't open the file to parse it. So druntime is
underepresented here. It's strictly Phobos.

- the most imported modules seem to be conv (23), traits (22),
contracts (19), string(18), range(17), stdio (16), ... That does
not mean they should be imported by some
std.commonlyNeeededModules, but it's a data point.


Philippe
Jun 08 2010
next sibling parent reply "Nick Sabalausky" <a a.a> writes:
"Philippe Sigaud" <philippe.sigaud gmail.com> wrote in message 
news:humcf2$2ufd$1 digitalmars.com...
 Hi,

 reading the std.all threads, I got curious as to how the different
 Phobos modules import each other. A dependency graph, if you will,
 though I'm sure to use that in a correct way.

 Funnily, I wrote yesterday an importGraph function that, given a
 module name and an optional directory where DMD is installed,
 crawls the module, find import statements and recursively calls
 itself with these new modules, building an import graph at the same
 time. It's mostly made to give a dependency graph for a project,
 but could be used on Phobos.

Neat!
 So, I created a stdall module importing all Phobos and got my
 function to graph it (btw, it's cool to see it can read and kind-
 of-parse all of Phobos and core in a few tens of ms).

 For those interested, the result is there:

 http://www.dsource.org/projects/dranges/browser/downloads/Phobos_gr
 aph.pdf
 (thanks graphviz)

Heh, that looks like some of my breadboard projects ;)
Jun 08 2010
next sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Wed, 09 Jun 2010 17:16:47 -0400, Nick Sabalausky <a a.a> wrote:

 "Philippe Sigaud" <philippe.sigaud gmail.com> wrote in message
 news:mailman.140.1276112857.24349.digitalmars-d puremagic.com...
 On Wed, Jun 9, 2010 at 03:12, Nick Sabalausky <a a.a> wrote:


 (thanks graphviz)

 For those interested, the result is there:


 Heh, that looks like some of my breadboard projects ;)


I even saw a loop in one of the lines. Had a good laugh at that :) Semi-serious suggestion: maybe you could get that data into a good EE program that does automatic wire-trace routing. Although, I'd imagine there's got to be a program that can straighten it out without resorting to cramming it into such a specialized domain-specific app.

There are people whose sole job is to disentangle a board layout generated by circuit diagram. I think it's an NP-complete problem. -Steve
Jun 10 2010
prev sibling parent Philippe Sigaud <philippe.sigaud gmail.com> writes:
--0015174c1030d6e1040488b1ec5d
Content-Type: text/plain; charset=ISO-8859-1

On Wed, Jun 9, 2010 at 23:16, Nick Sabalausky <a a.a> wrote:

 I even saw a loop in one of the lines. Had a good laugh at that :)

wavy import std.conv; Philippe --0015174c1030d6e1040488b1ec5d Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable <div class=3D"gmail_quote">On Wed, Jun 9, 2010 at 23:16, Nick Sabalausky <s= pan dir=3D"ltr">&lt;a a.a&gt;</span> wrote:<br><blockquote class=3D"gmail_q= uote" style=3D"margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 2= 04, 204); padding-left: 1ex;"> I even saw a loop in one of the lines. Had a good laugh at that :)<br><br><= /blockquote><div><br>Yeah, I saw it too. I guess graphviz couldn&#39;t make= its mind :-)<br>=A0</div><div>wavy import std.conv;<br><br><br>Philippe<br=

--0015174c1030d6e1040488b1ec5d--
Jun 10 2010
prev sibling parent reply Philippe Sigaud <philippe.sigaud gmail.com> writes:
--0016e6db5c3cca186004889e2c66
Content-Type: text/plain; charset=ISO-8859-1

On Wed, Jun 9, 2010 at 03:12, Nick Sabalausky <a a.a> wrote:


 (thanks graphviz)

 For those interested, the result is there:


 Heh, that looks like some of my breadboard projects ;)

disentangle this. Maybe by making the most imported modules bigger? Do dependency graphs always look like this? What I have for my own projects is not sooo far from Phobos... --0016e6db5c3cca186004889e2c66 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable <div class=3D"gmail_quote">On Wed, Jun 9, 2010 at 03:12, Nick Sabalausky <s= pan dir=3D"ltr">&lt;a a.a&gt;</span> wrote:<br><blockquote class=3D"gmail_q= uote" style=3D"margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 2= 04, 204); padding-left: 1ex;"> <br><div class=3D"im"> &gt;<br> &gt; <a href=3D"http://www.dsource.org/projects/dranges/browser/downloads/P= hobos_graph.pdf" target=3D"_blank">http://www.dsource.org/projects/dranges/= browser/downloads/Phobos_graph.pdf</a><br> &gt; (thanks graphviz)<br> &gt;<br> <br> </div>&gt; For those interested, the result is there:<br></blockquote><div>= =A0</div><blockquote class=3D"gmail_quote" style=3D"margin: 0pt 0pt 0pt 0.8= ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">Heh, tha= t looks like some of my breadboard projects ;)<br> <br></blockquote><div><br>Yeah, it&#39;s a bit hairy :-) Maybe there are op= tions in graphviz to disentangle this. Maybe by making the most imported mo= dules bigger?<br><br>Do dependency graphs always look like this? What I hav= e for my own projects is not sooo far from Phobos...<br> <br><br>=A0<br></div></div><br> --0016e6db5c3cca186004889e2c66--
Jun 09 2010
parent "Nick Sabalausky" <a a.a> writes:
"Philippe Sigaud" <philippe.sigaud gmail.com> wrote in message 
news:mailman.140.1276112857.24349.digitalmars-d puremagic.com...
 On Wed, Jun 9, 2010 at 03:12, Nick Sabalausky <a a.a> wrote:


 (thanks graphviz)

 For those interested, the result is there:


 Heh, that looks like some of my breadboard projects ;)


I even saw a loop in one of the lines. Had a good laugh at that :) Semi-serious suggestion: maybe you could get that data into a good EE program that does automatic wire-trace routing. Although, I'd imagine there's got to be a program that can straighten it out without resorting to cramming it into such a specialized domain-specific app.
Jun 09 2010