digitalmars.D.learn - can we detect at compile time module ctor/dtor cycles ?
- Timothee Cour (26/26) Jun 07 2013 Why can't we detect at compile time module ctor/dtor cycles (instead of
- Andrej Mitrovic (3/6) Jun 17 2013 No idea, but I've wondered this myself too. After all "imports"
- bearophile (8/10) Jun 17 2013 rdmd is used often in a situation where it knows all the modules
- Timothee Cour (7/18) Jun 17 2013 why do the email threads keep splitting up again?
- Andrej Mitrovic (7/8) Jun 17 2013 I answered through DForum, but the email thread was already split-up
Why can't we detect at compile time module ctor/dtor cycles (instead of runtime) ? See example below. It should be easy to detect the chain at CT: algo: build graph from import dependencies a=>b if module a imports module b. mark as red the modules that have a ctor collapse each non-red node into its parent (and update parent's edges) detect cycles (eg BFS) (same with dtor) ---- a1: import a2; void main(){} static this(){} a2: import a3; static this(){} a3: import a1; ---- rdmd --force --build-only -oftest a1 #works ./test #error: object.Exception src/rt/minfo.d(243): Aborting: Cycle detected between modules with ctors/dtors: a1 -> a2 -> a3 -> a1
Jun 07 2013
On Saturday, 8 June 2013 at 06:31:14 UTC, Timothee Cour wrote:Why can't we detect at compile time module ctor/dtor cycles (instead of runtime) ?No idea, but I've wondered this myself too. After all "imports" are a static feature and all are known at compile-time.
Jun 17 2013
Andrej Mitrovic:No idea, but I've wondered this myself too. After all "imports" are a static feature and all are known at compile-time.rdmd is used often in a situation where it knows all the modules of a program. So it must be able to detect those cycles. It seems an enhancement request for rdmd. Maybe a similar enhancement is possible for dmd, because there are plans to make the D compiler able to find all the modules it needs to compile a program. Bye, bearophile
Jun 17 2013
On Mon, Jun 17, 2013 at 5:11 PM, bearophile <bearophileHUGS lycos.com>wrote:Andrej Mitrovic: No idea, but I've wondered this myself too. After all "imports" are awhy do the email threads keep splitting up again? Anyways, on the original thread 'can we detect at compile time module ctor/dtor cycles ?', Steven Schveighoffer raised the concern that di files may have certain private imports not written in the di file, to which I answered we can at least attempt cycle detection at compile time (which won't catch all cases) followed by cycle detection at runtime.static feature and all are known at compile-time.rdmd is used often in a situation where it knows all the modules of a program. So it must be able to detect those cycles. It seems an enhancement request for rdmd. Maybe a similar enhancement is possible for dmd, because there are plans to make the D compiler able to find all the modules it needs to compile a program. Bye, bearophile
Jun 17 2013
On 6/18/13, Timothee Cour <thelastmammoth gmail.com> wrote:why do the email threads keep splitting up again?I answered through DForum, but the email thread was already split-up (it had 0 replies). See here: http://forum.dlang.org/thread/mailman.961.1370673073.13711.digitalmars-d-learn puremagic.com Interestingly now the other thread showed up: http://forum.dlang.org/thread/CANri+Ex8ZwYxtp5h+1FT-cve3SNbUze6CdUF10zHoC2=Rc4mPw mail.gmail.com Oh well.
Jun 17 2013