2 * Written in the D programming language.
3 * Module initialization routines.
5 * Copyright: Copyright Digital Mars 2000 - 2013.
6 * License: Distributed under the
7 * $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0).
8 * (See accompanying file LICENSE)
9 * Authors: Walter Bright, Sean Kelly
10 * Source: $(DRUNTIMESRC src/rt/_minfo.d)
15 import core.stdc.stdlib; // alloca
16 import core.stdc.string; // memcpy
21 MIctorstart = 0x1, // we've started constructing it
22 MIctordone = 0x2, // finished construction
23 MIstandalone = 0x4, // module ctor does not depend on other module
24 // ctors being done first
32 MIimportedModules = 0x400,
33 MIlocalClasses = 0x800,
38 * A ModuleGroup is an unordered collection of modules.
39 * There is exactly one for:
40 * 1. all statically linked in D modules, either directely or as shared libraries
41 * 2. each call to rt_loadLibrary()
46 this(immutable(ModuleInfo*)[] modules) nothrow @nogc
51 @property immutable(ModuleInfo*)[] modules() const nothrow @nogc
56 // this function initializes the bookeeping necessary to create the
57 // cycle path, and then creates it. It is a precondition that src and
58 // target modules are involved in a cycle.
60 // The return value is malloc'd using C, so it must be freed after use.
61 private size_t[] genCyclePath(size_t srcidx, size_t targetidx, int[][] edges)
63 import core.bitop : bt, btc, bts;
65 // set up all the arrays.
66 size_t[] cyclePath = (cast(size_t*)malloc(size_t.sizeof * _modules.length * 2))[0 .. _modules.length * 2];
68 int[] distance = (cast(int*)malloc(int.sizeof * _modules.length))[0 .. _modules.length];
72 // determine the shortest path between two modules. Uses dijkstra
73 // without a priority queue. (we can be a bit slow here, in order to
74 // get a better printout).
75 void shortest(size_t start, size_t target)
84 foreach (i, x; distance)
95 if (distance[n] == int.max)
97 distance[n] = curdist + 1;
107 // it should be impossible to not get to target, this is just a
108 // sanity check. Not an assert, because druntime is compiled in
110 if (distance[target] != curdist)
112 throw new Error("internal error printing module cycle");
115 // determine the path. This is tricky, because we have to
116 // follow the edges in reverse to get back to the original. We
117 // don't have a reverse mapping, so it takes a bit of looping.
118 totalMods += curdist;
119 auto subpath = cyclePath[totalMods - curdist .. totalMods];
123 subpath[curdist] = target;
127 // search for next (previous) module in cycle.
128 foreach (int m, d; distance)
132 // determine if m can reach target
133 foreach (e; edges[m])
147 // first get to the target
148 shortest(srcidx, targetidx);
150 shortest(targetidx, srcidx);
152 return cyclePath[0 .. totalMods];
155 /******************************
156 * Allocate and fill in _ctors[] and _tlsctors[].
157 * Modules are inserted into the arrays in the order in which the constructors
161 * cycleHandling - string indicating option for cycle handling
163 * Exception if it fails.
165 void sortCtors(string cycleHandling)
167 import core.bitop : bts, btr, bt, BitRange;
168 import rt.util.container.hashtab;
178 auto onCycle = OnCycle.abort;
180 switch (cycleHandling) with(OnCycle)
198 // invalid cycle handling option.
199 throw new Error("DRT invalid cycle handling option: " ~ cycleHandling);
202 debug (printModuleDependencies)
204 import core.stdc.stdio : printf;
206 foreach (_m; _modules)
208 printf("%s%s%s:", _m.name.ptr, (_m.flags & MIstandalone)
209 ? "+".ptr : "".ptr, (_m.flags & (MIctor | MIdtor)) ? "*".ptr : "".ptr);
210 foreach (_i; _m.importedModules)
211 printf(" %s", _i.name.ptr);
216 immutable uint len = cast(uint) _modules.length;
218 return; // nothing to do.
220 // allocate some stack arrays that will be used throughout the process.
221 immutable nwords = (len + 8 * size_t.sizeof - 1) / (8 * size_t.sizeof);
222 immutable flagbytes = nwords * size_t.sizeof;
223 auto ctorstart = cast(size_t*) malloc(flagbytes); // ctor/dtor seen
224 auto ctordone = cast(size_t*) malloc(flagbytes); // ctor/dtor processed
225 auto relevant = cast(size_t*) malloc(flagbytes); // has ctors/dtors
233 void clearFlags(size_t* flags)
235 memset(flags, 0, flagbytes);
239 // build the edges between each module. We may need this for printing,
240 // and also allows avoiding keeping a hash around for module lookups.
241 int[][] edges = (cast(int[]*)malloc((int[]).sizeof * _modules.length))[0 .. _modules.length];
243 HashTab!(immutable(ModuleInfo)*, int) modIndexes;
244 foreach (i, m; _modules)
245 modIndexes[m] = cast(int) i;
247 auto reachable = cast(size_t*) malloc(flagbytes);
251 foreach (i, m; _modules)
253 // use bit array to prevent duplicates
254 // https://issues.dlang.org/show_bug.cgi?id=16208
255 clearFlags(reachable);
256 // preallocate enough space to store all the indexes
257 int *edge = cast(int*)malloc(int.sizeof * _modules.length);
259 foreach (imp; m.importedModules)
261 if (imp is m) // self-import
263 if (auto impidx = imp in modIndexes)
265 if (!bts(reachable, *impidx))
266 edge[nEdges++] = *impidx;
269 // trim space to what is needed.
270 edges[i] = (cast(int*)realloc(edge, int.sizeof * nEdges))[0 .. nEdges];
274 // free all the edges after we are done
283 void buildCycleMessage(size_t sourceIdx, size_t cycleIdx, scope void delegate(string) sink)
290 sink("Cyclic dependency between module ");
291 sink(_modules[sourceIdx].name);
293 sink(_modules[cycleIdx].name);
295 auto cyclePath = genCyclePath(sourceIdx, cycleIdx, edges);
296 scope(exit) .free(cyclePath.ptr);
298 sink(_modules[sourceIdx].name);
300 foreach (x; cyclePath[0 .. $ - 1])
302 sink(_modules[x].name);
303 sink(bt(relevant, x) ? "* ->" ~ EOL : " ->" ~ EOL);
305 sink(_modules[sourceIdx].name);
309 // find all the non-trivial dependencies (that is, dependencies that have a
310 // ctor or dtor) of a given module. Doing this, we can 'skip over' the
311 // trivial modules to get at the non-trivial ones.
313 // If a cycle is detected, returns the index of the module that completes the cycle.
314 // Returns: true for success, false for a deprecated cycle error
315 bool findDeps(size_t idx, size_t* reachable)
317 static struct stackFrame
323 // initialize "stack"
324 auto stack = cast(stackFrame*) malloc(stackFrame.sizeof * len);
327 auto stacktop = stack + len;
329 sp.curMod = cast(int) idx;
332 // initialize reachable by flagging source module
333 clearFlags(reachable);
338 auto m = _modules[sp.curMod];
339 if (sp.curDep >= edges[sp.curMod].length)
342 if (sp == stack) // finished the algorithm
348 auto midx = edges[sp.curMod][sp.curDep];
349 if (!bts(reachable, midx))
351 if (bt(relevant, midx))
353 // need to process this node, don't recurse.
354 if (bt(ctorstart, midx))
356 // was already started, this is a cycle.
357 final switch (onCycle) with(OnCycle)
360 // check with old algorithm
361 if (sortCtorsOld(edges))
363 // unwind to print deprecation message.
364 return false; // deprecated cycle error
366 goto case abort; // fall through
370 buildCycleMessage(idx, midx, (string x) {errmsg ~= x;});
371 throw new Error(errmsg, __FILE__, __LINE__);
376 buildCycleMessage(idx, midx, (string x) {
377 import core.stdc.stdio : fprintf, stderr;
378 fprintf(stderr, "%.*s", cast(int) x.length, x.ptr);
380 // continue on as if this is correct.
385 else if (!bt(ctordone, midx))
387 // non-relevant, and hasn't been exhaustively processed, recurse.
388 if (++sp >= stacktop)
390 // stack overflow, this shouldn't happen.
391 import core.internal.abort : abort;
393 abort("stack overflow on dependency search");
405 return true; // success
408 // The list of constructors that will be returned by the sorting.
409 immutable(ModuleInfo)** ctors;
410 // current element being inserted into ctors list.
413 // This function will determine the order of construction/destruction and
414 // check for cycles. If a cycle is found, the cycle path is transformed
415 // into a string and thrown as an error.
417 // Each call into this function is given a module that has static
418 // ctor/dtors that must be dealt with. It recurses only when it finds
419 // dependencies that also have static ctor/dtors.
420 // Returns: true for success, false for a deprecated cycle error
421 bool processMod(size_t curidx)
423 immutable ModuleInfo* current = _modules[curidx];
425 // First, determine what modules are reachable.
426 auto reachable = cast(size_t*) malloc(flagbytes);
429 if (!findDeps(curidx, reachable))
430 return false; // deprecated cycle error
432 // process the dependencies. First, we process all relevant ones
433 bts(ctorstart, curidx);
434 auto brange = BitRange(reachable, len);
437 // note, don't check for cycles here, because the config could have been set to ignore cycles.
438 // however, don't recurse if there is one, so still check for started ctor.
439 if (i != curidx && bt(relevant, i) && !bt(ctordone, i) && !bt(ctorstart, i))
442 return false; // deprecated cycle error
446 // now mark this node, and all nodes reachable from this module as done.
447 bts(ctordone, curidx);
448 btr(ctorstart, curidx);
451 // Since relevant dependencies are already marked as done
452 // from recursion above (or are going to be handled up the call
453 // stack), no reason to check for relevance, that is a wasted
458 // add this module to the construction order list
459 ctors[ctoridx++] = current;
463 // returns `false` if deprecated cycle error otherwise set `result`.
464 bool doSort(size_t relevantFlags, ref immutable(ModuleInfo)*[] result)
466 clearFlags(relevant);
467 clearFlags(ctorstart);
468 clearFlags(ctordone);
470 // pre-allocate enough space to hold all modules.
471 ctors = (cast(immutable(ModuleInfo)**).malloc(len * (void*).sizeof));
473 foreach (int idx, m; _modules)
475 if (m.flags & relevantFlags)
477 if (m.flags & MIstandalone)
479 // can run at any time. Just run it first.
480 ctors[ctoridx++] = m;
489 // now run the algorithm in the relevant ones
490 foreach (idx; BitRange(relevant, len))
492 if (!bt(ctordone, idx))
494 if (!processMod(idx))
501 // no ctors in the list.
506 ctors = cast(immutable(ModuleInfo)**).realloc(ctors, ctoridx * (void*).sizeof);
509 result = ctors[0 .. ctoridx];
514 // finally, do the sorting for both shared and tls ctors. If either returns false,
515 // print the deprecation warning.
516 if (!doSort(MIctor | MIdtor, _ctors) ||
517 !doSort(MItlsctor | MItlsdtor, _tlsctors))
520 import core.stdc.stdio : fprintf, stderr;
521 fprintf(stderr, "Deprecation 16211 warning:\n"
522 ~ "A cycle has been detected in your program that was undetected prior to DMD\n"
523 ~ "2.072. This program will continue, but will not operate when using DMD 2.074\n"
524 ~ "to compile. Use runtime option --DRT-oncycle=print to see the cycle details.\n");
532 import rt.config : rt_configOption;
533 sortCtors(rt_configOption("oncycle"));
536 /******************************
537 * This is the old ctor sorting algorithm that does not find all cycles.
539 * It is here to allow the deprecated behavior from the original algorithm
540 * until people have fixed their code.
542 * If no cycles are found, the _ctors and _tlsctors are replaced with the
543 * ones generated by this algorithm to preserve the old incorrect ordering
547 * edges - The module edges as found in the `importedModules` member of
548 * each ModuleInfo. Generated in sortCtors.
550 * true if no cycle is found, false if one was.
552 bool sortCtorsOld(int[][] edges)
554 immutable len = edges.length;
555 assert(len == _modules.length);
557 static struct StackRec
568 auto stack = (cast(StackRec*).calloc(len, StackRec.sizeof))[0 .. len];
569 // TODO: reuse GCBits by moving it to rt.util.container or core.internal
570 immutable nwords = (len + 8 * size_t.sizeof - 1) / (8 * size_t.sizeof);
571 auto ctorstart = cast(size_t*).malloc(nwords * size_t.sizeof);
572 auto ctordone = cast(size_t*).malloc(nwords * size_t.sizeof);
573 int[] initialEdges = (cast(int *)malloc(int.sizeof * len))[0 .. len];
574 if (!stack.ptr || ctorstart is null || ctordone is null || !initialEdges.ptr)
581 .free(initialEdges.ptr);
584 // initialize the initial edges
585 foreach (int i, ref v; initialEdges)
588 bool sort(ref immutable(ModuleInfo)*[] ctors, uint mask)
592 ctors = (cast(immutable(ModuleInfo)**).malloc(len * size_t.sizeof))[0 .. len];
597 memset(ctorstart, 0, nwords * size_t.sizeof);
598 memset(ctordone, 0, nwords * size_t.sizeof);
602 int[] mods = initialEdges;
607 while (idx < mods.length)
613 // this module has already been processed, skip
617 else if (bt(ctorstart, m))
619 /* Trace back to the begin of the cycle.
622 size_t start = stackidx;
625 auto sm = stack[start].mod;
629 if (bt(ctorstart, sm))
632 assert(stack[start].mod == m);
639 /* This is also a cycle, but the import chain does not constrain
640 * the order of initialization, either because the imported
641 * modules have no ctors or the ctors are standalone.
648 auto curmod = _modules[m];
649 if (curmod.flags & mask)
651 if (curmod.flags & MIstandalone || !edges[m].length)
652 { // trivial ctor => sort in
653 ctors[cidx++] = curmod;
657 { // non-trivial ctor => defer
661 else // no ctor => mark as visited
668 /* Internal runtime error, recursion exceeds number of modules.
670 (stackidx < len) || assert(0);
673 stack[stackidx++] = StackRec(mods, idx);
681 { // pop old value from stack
683 mods = stack[stackidx]._mods;
684 idx = stack[stackidx]._idx;
685 auto m = mods[idx++];
686 if (bt(ctorstart, m) && !bts(ctordone, m))
687 ctors[cidx++] = _modules[m];
692 // store final number and shrink array
693 ctors = (cast(immutable(ModuleInfo)**).realloc(ctors.ptr, cidx * size_t.sizeof))[0 .. cidx];
697 /* Do two passes: ctor/dtor, tlsctor/tlsdtor
699 immutable(ModuleInfo)*[] _ctors2;
700 immutable(ModuleInfo)*[] _tlsctors2;
701 auto result = sort(_ctors2, MIctor | MIdtor) && sort(_tlsctors2, MItlsctor | MItlsdtor);
702 if (result) // no cycle
704 // fall back to original ordering as part of the deprecation.
709 .free(_tlsctors.ptr);
710 _tlsctors = _tlsctors2;
714 // free any allocated memory that will be forgotten
718 .free(_tlsctors2.ptr);
725 // run independent ctors
726 runModuleFuncs!(m => m.ictor)(_modules);
727 // sorted module ctors
728 runModuleFuncs!(m => m.ctor)(_ctors);
733 runModuleFuncs!(m => m.tlsctor)(_tlsctors);
738 runModuleFuncsRev!(m => m.tlsdtor)(_tlsctors);
743 runModuleFuncsRev!(m => m.dtor)(_ctors);
752 .free(_tlsctors.ptr);
754 // _modules = null; // let the owner free it
758 immutable(ModuleInfo*)[] _modules;
759 immutable(ModuleInfo)*[] _ctors;
760 immutable(ModuleInfo)*[] _tlsctors;
764 /********************************************
765 * Iterate over all module infos.
768 int moduleinfos_apply(scope int delegate(immutable(ModuleInfo*)) dg)
770 foreach (ref sg; SectionGroup)
772 foreach (m; sg.modules)
774 // TODO: Should null ModuleInfo be allowed?
777 if (auto res = dg(m))
785 /********************************************
786 * Module constructor and destructor routines.
793 foreach (ref sg; SectionGroup)
795 sg.moduleGroup.sortCtors();
796 sg.moduleGroup.runCtors();
800 void rt_moduleTlsCtor()
802 foreach (ref sg; SectionGroup)
804 sg.moduleGroup.runTlsCtors();
808 void rt_moduleTlsDtor()
810 foreach_reverse (ref sg; SectionGroup)
812 sg.moduleGroup.runTlsDtors();
818 foreach_reverse (ref sg; SectionGroup)
820 sg.moduleGroup.runDtors();
821 sg.moduleGroup.free();
827 // Alternate names for backwards compatibility with older DLL code
838 void _moduleTlsCtor()
843 void _moduleTlsDtor()
850 /********************************************
853 void runModuleFuncs(alias getfp)(const(immutable(ModuleInfo)*)[] modules)
857 if (auto fp = getfp(m))
862 void runModuleFuncsRev(alias getfp)(const(immutable(ModuleInfo)*)[] modules)
864 foreach_reverse (m; modules)
866 if (auto fp = getfp(m))
873 static void assertThrown(T : Throwable, E)(lazy E expr, string msg)
886 static struct UTModuleInfo
893 void setImports(immutable(ModuleInfo)*[] imports...)
896 assert(flags & MIimportedModules);
898 immutable nfuncs = popcnt(flags & (MItlsctor|MItlsdtor|MIctor|MIdtor|MIictor));
899 immutable size = nfuncs * (void function()).sizeof +
900 size_t.sizeof + imports.length * (ModuleInfo*).sizeof;
901 assert(size <= pad.sizeof);
903 pad[nfuncs] = imports.length;
904 .memcpy(&pad[nfuncs+1], imports.ptr, imports.length * imports[0].sizeof);
907 immutable ModuleInfo mi;
912 static UTModuleInfo mockMI(uint flags)
914 auto mi = UTModuleInfo(flags | MIimportedModules);
915 auto p = cast(void function()*)&mi.pad;
916 if (flags & MItlsctor) *p++ = &stub;
917 if (flags & MItlsdtor) *p++ = &stub;
918 if (flags & MIctor) *p++ = &stub;
919 if (flags & MIdtor) *p++ = &stub;
920 if (flags & MIictor) *p++ = &stub;
921 *cast(size_t*)p++ = 0; // number of imported modules
922 assert(cast(void*)p <= &mi + 1);
926 static void checkExp2(string testname, bool shouldThrow, string oncycle,
927 immutable(ModuleInfo*)[] modules,
928 immutable(ModuleInfo*)[] dtors=null,
929 immutable(ModuleInfo*)[] tlsdtors=null)
931 auto mgroup = ModuleGroup(modules);
932 mgroup.sortCtors(oncycle);
934 // if we are expecting sort to throw, don't throw because of unexpected
938 foreach (m; mgroup._modules)
939 assert(!(m.flags & (MIctorstart | MIctordone)), testname);
940 assert(mgroup._ctors == dtors, testname);
941 assert(mgroup._tlsctors == tlsdtors, testname);
945 static void checkExp(string testname, bool shouldThrow,
946 immutable(ModuleInfo*)[] modules,
947 immutable(ModuleInfo*)[] dtors=null,
948 immutable(ModuleInfo*)[] tlsdtors=null)
950 checkExp2(testname, shouldThrow, "abort", modules, dtors, tlsdtors);
958 checkExp("no ctors", false, [&m0.mi, &m1.mi, &m2.mi]);
962 auto m0 = mockMI(MIictor);
964 auto m2 = mockMI(MIictor);
965 auto mgroup = ModuleGroup([&m0.mi, &m1.mi, &m2.mi]);
966 checkExp("independent ctors", false, [&m0.mi, &m1.mi, &m2.mi]);
970 auto m0 = mockMI(MIstandalone | MIctor);
973 auto mgroup = ModuleGroup([&m0.mi, &m1.mi, &m2.mi]);
974 checkExp("standalone ctor", false, [&m0.mi, &m1.mi, &m2.mi], [&m0.mi]);
978 auto m0 = mockMI(MIstandalone | MIctor);
979 auto m1 = mockMI(MIstandalone | MIctor);
981 m1.setImports(&m0.mi);
982 checkExp("imported standalone => no dependency", false,
983 [&m0.mi, &m1.mi, &m2.mi], [&m0.mi, &m1.mi]);
987 auto m0 = mockMI(MIstandalone | MIctor);
988 auto m1 = mockMI(MIstandalone | MIctor);
990 m0.setImports(&m1.mi);
991 checkExp("imported standalone => no dependency (2)", false,
992 [&m0.mi, &m1.mi, &m2.mi], [&m0.mi, &m1.mi]);
996 auto m0 = mockMI(MIstandalone | MIctor);
997 auto m1 = mockMI(MIstandalone | MIctor);
999 m0.setImports(&m1.mi);
1000 m1.setImports(&m0.mi);
1001 checkExp("standalone may have cycle", false,
1002 [&m0.mi, &m1.mi, &m2.mi], [&m0.mi, &m1.mi]);
1006 auto m0 = mockMI(MIctor);
1007 auto m1 = mockMI(MIctor);
1008 auto m2 = mockMI(0);
1009 m1.setImports(&m0.mi);
1010 checkExp("imported ctor => ordered ctors", false,
1011 [&m0.mi, &m1.mi, &m2.mi], [&m0.mi, &m1.mi], []);
1015 auto m0 = mockMI(MIctor);
1016 auto m1 = mockMI(MIctor);
1017 auto m2 = mockMI(0);
1018 m0.setImports(&m1.mi);
1019 checkExp("imported ctor => ordered ctors (2)", false,
1020 [&m0.mi, &m1.mi, &m2.mi], [&m1.mi, &m0.mi], []);
1024 auto m0 = mockMI(MIctor);
1025 auto m1 = mockMI(MIctor);
1026 auto m2 = mockMI(0);
1027 m0.setImports(&m1.mi);
1028 m1.setImports(&m0.mi);
1029 assertThrown!Throwable(checkExp("", true, [&m0.mi, &m1.mi, &m2.mi]),
1030 "detects ctors cycles");
1031 assertThrown!Throwable(checkExp2("", true, "deprecate",
1032 [&m0.mi, &m1.mi, &m2.mi]),
1033 "detects ctors cycles (dep)");
1037 auto m0 = mockMI(MIctor);
1038 auto m1 = mockMI(MIctor);
1039 auto m2 = mockMI(0);
1040 m0.setImports(&m2.mi);
1041 m1.setImports(&m2.mi);
1042 m2.setImports(&m0.mi, &m1.mi);
1043 assertThrown!Throwable(checkExp("", true, [&m0.mi, &m1.mi, &m2.mi]),
1044 "detects cycle with repeats");
1048 auto m0 = mockMI(MIctor);
1049 auto m1 = mockMI(MIctor);
1050 auto m2 = mockMI(MItlsctor);
1051 m0.setImports(&m1.mi, &m2.mi);
1052 checkExp("imported ctor/tlsctor => ordered ctors/tlsctors", false,
1053 [&m0.mi, &m1.mi, &m2.mi], [&m1.mi, &m0.mi], [&m2.mi]);
1057 auto m0 = mockMI(MIctor | MItlsctor);
1058 auto m1 = mockMI(MIctor);
1059 auto m2 = mockMI(MItlsctor);
1060 m0.setImports(&m1.mi, &m2.mi);
1061 checkExp("imported ctor/tlsctor => ordered ctors/tlsctors (2)", false,
1062 [&m0.mi, &m1.mi, &m2.mi], [&m1.mi, &m0.mi], [&m2.mi, &m0.mi]);
1066 auto m0 = mockMI(MIctor);
1067 auto m1 = mockMI(MIctor);
1068 auto m2 = mockMI(MItlsctor);
1069 m0.setImports(&m1.mi, &m2.mi);
1070 m2.setImports(&m0.mi);
1071 checkExp("no cycle between ctors/tlsctors", false,
1072 [&m0.mi, &m1.mi, &m2.mi], [&m1.mi, &m0.mi], [&m2.mi]);
1076 auto m0 = mockMI(MItlsctor);
1077 auto m1 = mockMI(MIctor);
1078 auto m2 = mockMI(MItlsctor);
1079 m0.setImports(&m2.mi);
1080 m2.setImports(&m0.mi);
1081 assertThrown!Throwable(checkExp("", true, [&m0.mi, &m1.mi, &m2.mi]),
1082 "detects tlsctors cycle");
1083 assertThrown!Throwable(checkExp2("", true, "deprecate",
1084 [&m0.mi, &m1.mi, &m2.mi]),
1085 "detects tlsctors cycle (dep)");
1089 auto m0 = mockMI(MItlsctor);
1090 auto m1 = mockMI(MIctor);
1091 auto m2 = mockMI(MItlsctor);
1092 m0.setImports(&m1.mi);
1093 m1.setImports(&m0.mi, &m2.mi);
1094 m2.setImports(&m1.mi);
1095 assertThrown!Throwable(checkExp("", true, [&m0.mi, &m1.mi, &m2.mi]),
1096 "detects tlsctors cycle with repeats");
1100 auto m0 = mockMI(MIctor);
1101 auto m1 = mockMI(MIstandalone | MIctor);
1102 auto m2 = mockMI(MIstandalone | MIctor);
1103 m0.setImports(&m1.mi);
1104 m1.setImports(&m2.mi);
1105 m2.setImports(&m0.mi);
1106 // NOTE: this is implementation dependent, sorted order shouldn't be tested.
1107 checkExp("closed ctors cycle", false, [&m0.mi, &m1.mi, &m2.mi],
1108 [&m1.mi, &m2.mi, &m0.mi]);
1109 //checkExp("closed ctors cycle", false, [&m0.mi, &m1.mi, &m2.mi], [&m0.mi, &m1.mi, &m2.mi]);
1113 version (CRuntime_Microsoft)
1115 // Dummy so Win32 code can still call it
1116 extern(C) void _minit() { }