Thread overview
[Issue 16265] unittest imports should not be counted as dependencies for static ctors
Oct 03, 2016
anonymous4
[Issue 16265] batter detection of real module cycles
Oct 04, 2016
Martin Nowak
Nov 09, 2016
anonymous4
Dec 12, 2017
Mike Franklin
Dec 17, 2022
Iain Buclaw
October 03, 2016
https://issues.dlang.org/show_bug.cgi?id=16265

--- Comment #1 from anonymous4 <dfj1esp02@sneakemail.com> ---
But you will still have a cycle when compiling unittests? Then unittest dependencies can't be possibly ignored.

--
October 04, 2016
https://issues.dlang.org/show_bug.cgi?id=16265

Martin Nowak <code@dawg.eu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |code@dawg.eu
            Summary|unittest imports should not |batter detection of real
                   |be counted as dependencies  |module cycles
                   |for static ctors            |

--- Comment #2 from Martin Nowak <code@dawg.eu> ---
> unittest {
>    import other; // other imports this module, and contains static ctors
>    other.foo();
> }
> 
> Should not be considered a cycle. The shared ctor cannot possibly call the unit test code, so there is no leaking of the import.

Well, unfortunately it's technically possible using `__traits(getUnitTests,
__MODULE__)`,
and it wouldn't be too far-fetched to call the tests from a static ctor.
The example is pretty close to do that
http://dlang.org/spec/traits.html#getUnitTests.

--
October 05, 2016
https://issues.dlang.org/show_bug.cgi?id=16265

Steven Schveighoffer <schveiguy@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|batter detection of real    |unittest imports should not
                   |module cycles               |be counted as dependencies
                   |                            |for static ctors

--- Comment #3 from Steven Schveighoffer <schveiguy@yahoo.com> ---
unittest dependencies cannot be called directly by static constructors (except by Martin's corner case method), so their imports don't count when doing construction. By the time unittests run, static ctors are already done, so no worries there.

(In reply to Martin Nowak from comment #2
> Well, unfortunately it's technically possible using `__traits(getUnitTests,
> __MODULE__)`,
> and it wouldn't be too far-fetched to call the tests from a static ctor.

I disagree this is not far-fetched, do we need to screw up everyone's cycle detection code due to this rare case? Isn't it enough to just say "WARNING unit test imports are not considered during static construction, calling unit tests during static construction can result in undetected cycles"?

Consider that documented unit tests are meant to show how one can use a library call, and this might involve importing many other modules that are totally unrelated. Including unittest imports when doing cycle detection is harmful in many ways, it is very advantageous to get rid of this.

Please, open a new bug report for other ideas of cycle detection improvement, don't override the purpose of this one.

--
November 09, 2016
https://issues.dlang.org/show_bug.cgi?id=16265

anonymous4 <dfj1esp02@sneakemail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://issues.dlang.org/sh
                   |                            |ow_bug.cgi?id=16673

--
May 07, 2017
https://issues.dlang.org/show_bug.cgi?id=16265

--- Comment #4 from Steven Schveighoffer <schveiguy@yahoo.com> ---
Trial PR: https://github.com/dlang/dmd/pull/6753

--
December 12, 2017
https://issues.dlang.org/show_bug.cgi?id=16265

Mike Franklin <slavo5150@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |slavo5150@yahoo.com

--- Comment #5 from Mike Franklin <slavo5150@yahoo.com> ---
I think it would help to have an example that someone could quickly cut and paste into their development environment to reproduce and illustrate the problem.

--
December 12, 2017
https://issues.dlang.org/show_bug.cgi?id=16265

--- Comment #6 from Steven Schveighoffer <schveiguy@yahoo.com> ---
(In reply to Mike Franklin from comment #5)
> I think it would help to have an example that someone could quickly cut and paste into their development environment to reproduce and illustrate the problem.


Of course. It's going to be a toy example, but things like documented unit tests cause these kinds of problems, especially when you have so many modules that you need stuff from in order to run a complete program.

mod1.d:
module mod1;

immutable int val;

shared static this()
{
   val = 2;
}

size_t bar(size_t x) { return x + 1; }

unittest
{
   import mod2;
   assert("abc".foo.bar == 7);
}

mod2.d:
module mod2;

import mod1;

immutable int multiplier;

shared static this()
{
   multiplier = val;
}

size_t foo(string s) { return s.length * multiplier; }

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=16265

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P4

--