There are times you may want to do something differently in a final release version, just as the built-in D array types do.
It appears this could be added fairly simply.
In src/dmd/mars.c there's this code:
if (global.params.release)
{ global.params.useInvariants = 0;
global.params.useIn = 0;
global.params.useOut = 0;
global.params.useAssert = 0;
global.params.useArrayBounds = 0;
global.params.useSwitchError = 0;
}
I think just adding this line inside the 'if' would do the trick:
VersionCondition::addPredefinedGlobalIdent("release");
If not, it can't be much more complicated than that.
Comment #1 by andrej.mitrovich — 2012-12-25T18:30:32Z
Use-cases that I can think of:
- Enable certain code-path only when maximum performance is required (it might be expensive at compile-time too so it's wrapped in a `version(release)`)
I can't think of anything else. In fact I'm against this. Since the user ultimately controls the switches passed to the compiler there's nothing stopping the user from passing `-version=release`.
Also it could easily break linking with libraries. Suppose a library has this code:
version(release)
{
void foo(int x, int y = 1) { }
}
else
{
void foo(int x) { }
}
And the user creates a static library without using -release. Then, the user decides to compile his app with -release and use the existing precompiled static library. He will get linker errors because the right `foo` might not have been compiled in. (Please note that *this* example might not give you linking errors because DMD can inline the call)
I know the same issue can appear with other version statements, however '-release' is used often enough that this could become a common problem. And it would be extremely confusing for novice users to get linking errors because they've decided to use -release.
Other than that, yes it's simple to implement in the compiler.
Comment #2 by issues.dlang — 2012-12-25T19:12:52Z
There is no a version(assert) that will be enabled when assertions are enabled, which takes care of many of the use cases where version(release) would be useful (though clearly version(assert) is the opposite of version(release)).
Comment #3 by razvan.nitu1305 — 2019-10-10T14:14:49Z
Any other thoughts on this? I am tempted to close as WONTFIX.