digitalmars.D - How to make invariant switchable
- Qian Xu (7/7) Jun 18 2009 Hi All,
- Jason House (2/13) Jun 18 2009 "dmd -release" will ignore invariants. You can also wrap your invariants...
- Qian Xu (5/22) Jun 18 2009 Thanks for the hint.
- Denis Koroskin (3/26) Jun 18 2009 No, they wont.
- Qian Xu (2/4) Jun 18 2009 Is there any reason for that?
- Denis Koroskin (4/9) Jun 18 2009 I dont know. I'd prefer to write
- Max Samukha (6/16) Jun 18 2009 'debug' is not necessary in most cases because asserts are removed
- Denis Koroskin (9/30) Jun 18 2009 You must have misunderstood my post.
- Max Samukha (5/37) Jun 18 2009 Sorry, I understand now.
- bearophile (5/7) Jun 18 2009 If you look around on internet you will find lot of people that like to ...
- Lars T. Kyllingstad (5/14) Jun 18 2009 For assertions that are meant only for debugging, use assert (...). For
- Max Samukha (9/16) Jun 19 2009 You have a point. With current dmd, you can include unittests in the
- Christian Kamm (2/9) Jun 19 2009 LDC has the -enable-* and -disable-* command line options for asserts, a...
- Christian Kamm (7/10) Jun 19 2009 Ah, Jarrett had already pointed that out. Anyway, what I meant to say wa...
- Max Samukha (3/12) Jun 19 2009 Nice! No support for D2, sadly
- Jarrett Billingsley (6/28) Jun 18 2009 All the debugging features are optional. Using -release turns of not
- Qian Xu (16/16) Jun 18 2009 Release and Debug are two configuration sets.
- Jason House (10/29) Jun 18 2009 No.
Hi All, "invariant" is a great language feature of D. But nice thing costs. Is it possible to make it compiler switchable? Like "dmd --ignore-invariant" or "dmd --version=ignore-invariant" It think it will be quite helpful to generate test version and release version of software. Best regards Qian Xu
Jun 18 2009
Qian Xu Wrote:Hi All, "invariant" is a great language feature of D. But nice thing costs. Is it possible to make it compiler switchable? Like "dmd --ignore-invariant" or "dmd --version=ignore-invariant" It think it will be quite helpful to generate test version and release version of software. Best regards Qian Xu"dmd -release" will ignore invariants. You can also wrap your invariants inside of debug{} or similar.
Jun 18 2009
Jason House wrote:Qian Xu Wrote:Thanks for the hint. BTW: is assertion switchable as well? I put some assertions outside of invariant-block, it will be executed, when my program is compiled in release mode.Hi All, "invariant" is a great language feature of D. But nice thing costs. Is it possible to make it compiler switchable? Like "dmd --ignore-invariant" or "dmd --version=ignore-invariant" It think it will be quite helpful to generate test version and release version of software. Best regards Qian Xu"dmd -release" will ignore invariants. You can also wrap your invariants inside of debug{} or similar.
Jun 18 2009
On Thu, 18 Jun 2009 16:57:47 +0400, Qian Xu <quian.xu stud.tu-ilmenau.de> wrote:Jason House wrote:No, they wont.Qian Xu Wrote:Thanks for the hint. BTW: is assertion switchable as well? I put some assertions outside of invariant-block, it will be executed, when my program is compiled in release mode.Hi All, "invariant" is a great language feature of D. But nice thing costs. Is it possible to make it compiler switchable? Like "dmd --ignore-invariant" or "dmd --version=ignore-invariant" It think it will be quite helpful to generate test version and release version of software. Best regards Qian Xu"dmd -release" will ignore invariants. You can also wrap your invariants inside of debug{} or similar.
Jun 18 2009
Denis Koroskin wrote:No, they wont.Is there any reason for that?
Jun 18 2009
On Thu, 18 Jun 2009 17:09:12 +0400, Qian Xu <quian.xu stud.tu-ilmenau.de> wrote:Denis Koroskin wrote:I dont know. I'd prefer to writeNo, they wont.Is there any reason for that?debug assert(foo == bar, "foo must be equal to bar");if I'd like to turn them off in release mode.
Jun 18 2009
On Thu, 18 Jun 2009 17:12:25 +0400, "Denis Koroskin" <2korden gmail.com> wrote:On Thu, 18 Jun 2009 17:09:12 +0400, Qian Xu <quian.xu stud.tu-ilmenau.de> wrote:'debug' is not necessary in most cases because asserts are removed from release builds unless the assert condition is known to be false at compile time, in which case a hlt instruction is generated for the assert in release mode.Denis Koroskin wrote:I dont know. I'd prefer to writeNo, they wont.Is there any reason for that?debug assert(foo == bar, "foo must be equal to bar");if I'd like to turn them off in release mode.
Jun 18 2009
On Thu, 18 Jun 2009 17:46:37 +0400, Max Samukha <outer space.com> wrote:On Thu, 18 Jun 2009 17:12:25 +0400, "Denis Koroskin" <2korden gmail.com> wrote:You must have misunderstood my post. I know that asserts are removed in release mode. Why question was, why they are removed? I responded that I personally see no reason in removing them in release mode. I wrote that if I were to remove my asserts in release, I would prepend them with "debug": debug assert(condition, errorMessage);On Thu, 18 Jun 2009 17:09:12 +0400, Qian Xu <quian.xu stud.tu-ilmenau.de> wrote:'debug' is not necessary in most cases because asserts are removed from release builds unless the assert condition is known to be false at compile time, in which case a hlt instruction is generated for the assert in release mode.Denis Koroskin wrote:I dont know. I'd prefer to writeNo, they wont.Is there any reason for that?debug assert(foo == bar, "foo must be equal to bar");if I'd like to turn them off in release mode.
Jun 18 2009
On Thu, 18 Jun 2009 19:28:41 +0400, "Denis Koroskin" <2korden gmail.com> wrote:On Thu, 18 Jun 2009 17:46:37 +0400, Max Samukha <outer space.com> wrote:Sorry, I understand now.On Thu, 18 Jun 2009 17:12:25 +0400, "Denis Koroskin" <2korden gmail.com> wrote:You must have misunderstood my post.On Thu, 18 Jun 2009 17:09:12 +0400, Qian Xu <quian.xu stud.tu-ilmenau.de> wrote:'debug' is not necessary in most cases because asserts are removed from release builds unless the assert condition is known to be false at compile time, in which case a hlt instruction is generated for the assert in release mode.Denis Koroskin wrote:I dont know. I'd prefer to writeNo, they wont.Is there any reason for that?debug assert(foo == bar, "foo must be equal to bar");if I'd like to turn them off in release mode.I know that asserts are removed in release mode. Why question was, why they are removed? I responded that I personally see no reason in removing them in release mode. I wrote that if I were to remove my asserts in release, I would prepend them with "debug": debug assert(condition, errorMessage);Why would you want to leave asserts in a release build while they are supposed to be used for debugging?
Jun 18 2009
Max Samukha:Why would you want to leave asserts in a release build while they are supposed to be used for debugging?If you look around on internet you will find lot of people that like to keep assertions in the final programs too. Is DMD itself compiled with asserts left inside? When DMD doesn't work if often spits out a file + line number that I think come from an assert. Bye, bearophile
Jun 18 2009
bearophile wrote:Max Samukha:For assertions that are meant only for debugging, use assert (...). For assertions that should also be included in a release build, use enforce(...) from the std.contracts module. -LarsWhy would you want to leave asserts in a release build while they are supposed to be used for debugging?If you look around on internet you will find lot of people that like to keep assertions in the final programs too. Is DMD itself compiled with asserts left inside? When DMD doesn't work if often spits out a file + line number that I think come from an assert. Bye, bearophile
Jun 18 2009
On Thu, 18 Jun 2009 13:43:22 -0400, bearophile <bearophileHUGS lycos.com> wrote:Max Samukha:You have a point. With current dmd, you can include unittests in the release build. So why not asserts? But I don't think it's a good solution to force people who don't want asserts in a final product to prepend each and every assert with 'debug'. For assertions that should stay in production, use 'if' conditions in D1 or std.contracts.enforce in D2. Anyway, it would be nice to have a switch to retain debug assertions in the release build.Why would you want to leave asserts in a release build while they are supposed to be used for debugging?If you look around on internet you will find lot of people that like to keep assertions in the final programs too. Is DMD itself compiled with asserts left inside? When DMD doesn't work if often spits out a file + line number that I think come from an assert. Bye, bearophile
Jun 19 2009
Max Samukha Wrote:You have a point. With current dmd, you can include unittests in the release build. So why not asserts? But I don't think it's a good solution to force people who don't want asserts in a final product to prepend each and every assert with 'debug'. For assertions that should stay in production, use 'if' conditions in D1 or std.contracts.enforce in D2. Anyway, it would be nice to have a switch to retain debug assertions in the release build.LDC has the -enable-* and -disable-* command line options for asserts, array bounds checking, invariants and contracts to allow fine grained control over what is emitted and what isn't.
Jun 19 2009
Christian Kamm Wrote:LDC has the -enable-* and -disable-* command line options for asserts, array bounds checking, invariants and contracts to allow fine grained control over what is emitted and what isn't.Ah, Jarrett had already pointed that out. Anyway, what I meant to say was that adding these switches was pretty easy: as far as I remember the frontend already has individual options for switching the debugging aids on and off individually. So if you want this in DMD, make an enhancement request and append a patch. Unless Walter has fundamental reservations, getting it into the reference compiler (preferably using the same flags LDC uses) would be nice.
Jun 19 2009
On Fri, 19 Jun 2009 05:31:14 -0400, Christian Kamm <see-ldc-commits repository.com> wrote:Max Samukha Wrote:Nice! No support for D2, sadlyYou have a point. With current dmd, you can include unittests in the release build. So why not asserts? But I don't think it's a good solution to force people who don't want asserts in a final product to prepend each and every assert with 'debug'. For assertions that should stay in production, use 'if' conditions in D1 or std.contracts.enforce in D2. Anyway, it would be nice to have a switch to retain debug assertions in the release build.LDC has the -enable-* and -disable-* command line options for asserts, array bounds checking, invariants and contracts to allow fine grained control over what is emitted and what isn't.
Jun 19 2009
On Thu, Jun 18, 2009 at 8:57 AM, Qian Xu<quian.xu stud.tu-ilmenau.de> wrote:Jason House wrote:All the debugging features are optional. Using -release turns of not only invariant{} but also in{} and out{} contracts, assert(), and array bounds checking. DMD doesn't provide any more fine-grained support for these, but LDC allows you to turn each of them on or off individually.Qian Xu Wrote:Thanks for the hint. BTW: is assertion switchable as well? I put some assertions outside of invariant-block, it will be executed, when my program is compiled in release mode.Hi All, "invariant" is a great language feature of D. But nice thing costs. Is it possible to make it compiler switchable? Like "dmd --ignore-invariant" or "dmd --version=ignore-invariant" It think it will be quite helpful to generate test version and release version of software. Best regards Qian Xu"dmd -release" will ignore invariants. You can also wrap your invariants inside of debug{} or similar.
Jun 18 2009
Release and Debug are two configuration sets. FEATURE | DEBUG | RELEASE ---------------+-------+--------- assertion | | ---------------+-------+--------- invariant | | ---------------+-------+--------- debug symbols | | ---------------+-------+--------- optimization | | ---------------+-------+--------- inline | | ---------------+-------+--------- more... | | It is also inconvient to switch "invariant" (or debug features) with a universal "-release" flag.
Jun 18 2009
Qian Xu Wrote:Release and Debug are two configuration sets. FEATURE | DEBUG | RELEASE ---------------+-------+--------- assertion | | ---------------+-------+--------- invariant | | ---------------+-------+--------- debug symbols | | ---------------+-------+--------- optimization | | ---------------+-------+--------- inline | | ---------------+-------+--------- more... | | It is also inconvient to switch "invariant" (or debug features) with a universal "-release" flag.No. They're not as universal as you think. -release disables invariant, array bounds checking, etc... -debug enables debug statements -inline enables inlining -O performs optimizations -g enables debug symbols -unittest enables unit tests These posts should be on d.learn...
Jun 18 2009