Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.
/ druntime Public archive

Comments

Allow configuration of cycle detection via command line parameters.#1668

Merged
MartinNowak merged 5 commits intodlang:stablefrom
schveiguy:allowcycles
Oct 7, 2016
Merged

Allow configuration of cycle detection via command line parameters.#1668
MartinNowak merged 5 commits intodlang:stablefrom
schveiguy:allowcycles

Conversation

@schveiguy
Copy link
Member

@schveiguy schveiguy commented Oct 5, 2016

Changes in this:

  1. Allow ignoring/just printing of cycles
  2. Remove all GC usage except when throwing an exception.
  3. Because edges are needed every time we print a cycle, I'm mallocing them at the beginning, and only use the hashtable there (findModule goes away).

NOTE: I have NOT tested this properly, because I cannot build dmd on MacOS, see https://issues.dlang.org/show_bug.cgi?id=16536. I'd like to add tests for the switches, but I'm not sure how to do this, especially since I cannot build. I'm throwing this in the mix to at least test the default functionality.

I will add a changelog once this is more solid.

Update: Was able to download binary of MacOS dmd and run unit tests.

@schveiguy
Copy link
Member Author

Added tests for new switches. Working on changelog...

@schveiguy
Copy link
Member Author

Hm... changelog is already cleared. @MartinNowak, can you set up the changelog properly for this? I'll work on updating the docs.

@schveiguy schveiguy changed the title [WIP, Do not pull] Allow configuration of cycle detection via command line parameters. Allow configuration of cycle detection via command line parameters. Oct 5, 2016
@schveiguy
Copy link
Member Author

OK, I can set up changelog when I add docs. So I can do all this. This PR is probably OK to merge, I just need to do docs/changelog.

@schveiguy
Copy link
Member Author

Changelog and docs done.

- directly compare pointers instead of module indices
- rename e (edge) -> imp (import)
src/rt/minfo.d Outdated
// print the message
buildCycleMessage(idx, midx, (string x) {
import core.stdc.stdio : fprintf, stderr;
fprintf(stderr, "%.*s", x.length, x.ptr);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cast(int)x.length


// build the edges between each module. We may need this for printing,
// and also allows avoiding keeping a hash around for module lookups.
int[][] edges = (cast(int[]*)malloc((int[]).sizeof * _modules.length))[0 .. _modules.length];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that really such a good idea?
Space for all edges could be quite big, right?
And we almost never need to print cycles.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will test against phobos and a vibe-d project.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

11KB phobos, 7KB dub-registry (uses pretty much all of vibe.d).
Time for sorting phobos went from 1000µs -> 500µs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The edges are all integers, and I'm only allocating enough for unique edges (I realloc to shrink after processing each module), and it's only for direct imports. If we have 1000 modules and conservatively estimate that each one imports 15 other modules, that's only 15,000 * 4 = 60kb.

Time for sorting phobos went from 1000µs -> 500µs

Nice!

src/rt/minfo.d Outdated
// preallocate enough space to store all the indexes
int *edge = cast(int*)malloc(int.sizeof * _modules.length);
size_t nEdges = 0;
foreach (e; m.importedModules)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think imp would be easier to understand.

src/rt/minfo.d Outdated
{
if(auto impidx = e in modIndexes)
{
if (*impidx != i)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could continue before the hash lookup.
if (e is m) continue; // self-import

$(ROOT)/cycle_abort.done: RETCODE=1
$(ROOT)/cycle_abort.done: LINES=5
$(ROOT)/cycle_print.done: RETCODE=0
$(ROOT)/cycle_print.done: LINES=8
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

- %.*s expects an int length
@MartinNowak
Copy link
Member

Hm... changelog is already cleared. @MartinNowak, can you set up the changelog properly for this? I'll work on updating the docs.

Yes, shouldn't have done that. Need to improve the changed tool to automatically gather the project changelog files.

@MartinNowak
Copy link
Member

Auto-merge toggled on

buildCycleMessage(idx, midx, (string x) {
import core.stdc.stdio : fprintf, stderr;
fprintf(stderr, "%.*s", x.length, x.ptr);
fprintf(stderr, "%.*s", cast(int) x.length, x.ptr);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@MartinNowak MartinNowak merged commit 45f2014 into dlang:stable Oct 7, 2016
@schveiguy schveiguy deleted the allowcycles branch October 7, 2016 23:23
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants