Thread overview
Phobos import graph
Jun 08, 2010
Philippe Sigaud
Jun 09, 2010
Nick Sabalausky
Jun 09, 2010
Philippe Sigaud
Jun 09, 2010
Nick Sabalausky
Jun 10, 2010
Philippe Sigaud
June 08, 2010
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
June 09, 2010
"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 ;)


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

>
> >
> >
> http://www.dsource.org/projects/dranges/browser/downloads/Phobos_graph.pdf
> > (thanks graphviz)
> >
>
> > For those interested, the result is there:
>


> Heh, that looks like some of my breadboard projects ;)
>
>
Yeah, it's a bit hairy :-) Maybe there are options in graphviz to 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...


June 09, 2010
"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:
>
>>
>> >
>> >
>> http://www.dsource.org/projects/dranges/browser/downloads/Phobos_graph.pdf
>> > (thanks graphviz)
>> >
>>
>> > For those interested, the result is there:
>>
>
>
>> Heh, that looks like some of my breadboard projects ;)
>>
>>
> Yeah, it's a bit hairy :-)
>

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.


June 10, 2010
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:
>>
>>>
>>> >
>>> >
>>> http://www.dsource.org/projects/dranges/browser/downloads/Phobos_graph.pdf
>>> > (thanks graphviz)
>>> >
>>>
>>> > For those interested, the result is there:
>>>
>>
>>
>>> Heh, that looks like some of my breadboard projects ;)
>>>
>>>
>> Yeah, it's a bit hairy :-)
>>
>
> 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
June 10, 2010
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 :)
>
>
Yeah, I saw it too. I guess graphviz couldn't make its mind :-)

wavy import std.conv;


Philippe