On Thursday, August 11, 2011 06:58 simendsjo wrote: > On 11.08.2011 14:56, Vladimir Panteleev wrote: > > On Thu, 11 Aug 2011 14:59:03 +0300, Vladimir Panteleev > > > > <[email protected]> wrote: > >> I don't see what the problem is. Is your program buggy? Don't use > >> -release. Are you done fixing bugs? Use -release to remove pointless > >> clutter. Is the program segfaulting on a user's PC? Send him a debug > >> build! > > > > By the way, I'd like to add some thoughts on how wrong I think it is to > > rely on a single debugging feature like this in release builds. Asserts > > (both conditional and unconditional), contracts, invariants and native > > language features such as array bounds checking all work together to > > find bugs as soon as possible. If you get an error message on an > > assert(0) and you attempt to debug it from that, you may be led on a > > wild goose chase, because the program might have actually failed much > > earlier and ran for a while in an undetermined state, corrupting memory > > left and right or spreading internal state inconsistencies uncaught by > > invariants. I know about this all too well from my experience of > > debugging memory corruption - the garbage collector is compiled with no > > invariants as its performance is critical, but recompiling my program > > with a version of Phobos with contracts enabled would have saved me > > tracing a few steps to find the source of corruption. > > Which reminds me.. Why isn't a phobos shipped with a precompiled version > containing contracts?
Because that would be inefficient. As it stands, there's no way to tell the compiler, "use this library in release mode but use this library in debug mode." So, you're stuck with one or the other, and going with the debug version of Phobos would negatively impact all D programs as far as efficiency goes. We _could_ have the debug version in a separate folder with instructions somewhere telling you to adjust your build scripts so that you use one for debug and one for release, but that does complicate things. It also increases the size of the zip file, and I don't think that it makes sense at all with an installer or Linux package. Now, the _templated_ code in Phobos will use contracts just fine (as long you're not compiling your project in release mode), since that's compiled when the programmer uses it rather than compiled into the library itself. So, most of the cases where you actually need contracts based on what the programmer using Phobos is doing (as opposed to Phobos itself) should still work. To actually, reasonably distribute Phobos in a debug and release state would probably necessitate setting it up so that dmd was smart enough to use one set of libraries in release mode and another in debug mode. - Jonathan M Davis
