Bug 9482 – Option to compile in release mode, but keep in contracts on non-private functions
Status
RESOLVED
Resolution
WORKSFORME
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-02-08T04:50:21Z
Last change time
2020-06-13T22:40:27Z
Keywords
contracts
Assigned to
No Owner
Creator
Stewart Gordon
Comments
Comment #0 by smjg — 2013-02-08T04:50:21Z
At the moment, development vs. release mode is a binary switch.
Development build (no -release):
- asserts are compiled in
- in/out contracts are compiled in
- invariants are compiled in
- array bounds checking
Release build (-release):
- asserts are ignored
- in/out contracts are ignored
- invariants are ignored
- no array bounds checking
This all-or-nothing choice is unideal. In particular, for compiling libraries, it would be useful to still have the in contracts and the asserts therein, but otherwise have a release build. This means that the tested and released library code will perform at (almost) full speed and have minimal code bloat, but users of the library still get the checks that they are passing valid input to the library's functions.
Of course, there's no point having the in contracts on private functions, since these will be called only from within the library. The same applies to package. But for public and protected functions, the in contract would be generated in this mode.
This would become a non-issue if we:
- move in contract checking to the caller side, as has been suggested on a number of occasions
- in some way make sure the in contract can be compiled with code that uses the library, if it isn't present in the .lib
- allow contracts to be specified without an implementation (issue 6549)
But since these changes don't seem to be forthcoming, the improvement I am suggesting here might be worth implementing at this time.
At first I thought this was a Linux-specific feature - but I see now it's in the Windows, OSX (which is called macOS now) and FreeBSD versions alike. Any idea when this feature was added? Furthermore, does this switch on in contracts for all functions, or does it exclude private functions?
Comment #3 by b2.temp — 2020-06-13T22:40:27Z
(In reply to Stewart Gordon from comment #2)
> At first I thought this was a Linux-specific feature - but I see now it's in
> the Windows, OSX (which is called macOS now) and FreeBSD versions alike.
> Any idea when this feature was added? Furthermore, does this switch on in
> contracts for all functions, or does it exclude private functions?
it was added in version 2.084:
https://dlang.org/changelog/2.084.0.html#check-switch
Sorry I missed the "private" criterion... maybe reopen if the check feature is not sufficient.