Regarding compiler switches

Lars T. Kyllingstad public at kyllingen.NOSPAMnet
Thu Nov 5 03:18:42 PST 2009


Michal Minich wrote:
> Hello Lars,
> 
>> DMD has just a few switches that control how code is compiled, such as
>> -safe, -release, -O and so on. In comparison, GCC has (and this is
>> just a rough estimate) a gazillion switches. For the most part, DMD's
>> simpler approach is a good thing, because it makes the compiler easy
>> to use.
>>
>> However, from time to time, discussions appear on this NG that
>> indicate not everyone is happy with the situation. For instance,
>> people have complained that it's not possible to separately turn
>> on/off bounds checking and compilation of contracts.
>>
>> Recently there was a discussion of whether the -safe switch should
>> affect array bounds checking too. I don't think any agreement was
>> reached.
>>
>> Is there any good reason for NOT letting people choose these things
>> for themselves? I suspect it would be very easy to add more detailed
>> options to DMD:
>>
>> --bounds-checking=on|off
>> --mem-safe=on|off
>> --Oxxx=on|off|auto  (There are many possible optimisations, and the
>> compiler doesn't always know best.)
>> --contracts=on|off
>> Note that I think it's important that -release & co. are kept, but
>> they should be defined as common combinations of the more detailed
>> options.
>>
>> -Lars
>>
> 
> Separate switches for bounds checking and contracts would be good (which 
> would turn of bounds checking for mem-safe code too). But there is no 
> reason to have mem-safe=on switch - you cannot force safety on unsafe 
> code by compiler switch, this just would not compile. I think the proper 
> way to specify memory safety is per function, as I wrote in other post 
> around here.

There is already a -safe switch, and whether that is reasonable or not 
is a completely different discussion.  My point was that instead of 
discussing whether -safe should also force array bounds checking, there 
should be separate switches for the two:

   --mem-safe          - Does what -safe was originally intended to do.
   --bounds-checking   - Does what you think it does.
   --safe              - The most commonly used combination of the above,
                         I really don't care which, because now I'm free
                         to choose for myself.


> Also, I think there is only one -O in dmd.

And I'm saying there should be more, for the cases where the programmer 
actually knows best.  (It happens!)  In the case of optimisations, there 
could actually be three levels of detail:

   High-level:
     -O          - Equivalent to setting all other switches to
                   'auto'.  The compiler makes all the decisions
                   (like the current -O).

   Middle level:
     --Ospeed    - Optimise for speed.  The compiler decides how
                   to do this in the best way possible.
     --Omem      - Like above, but optimise for minimal memory usage.

   Low-level:
     --Oxxx=on|off|auto

I'm not even going to start listing the possible low-level optimisation 
options, and I don't necessarily think we should go the down the GCC 
road, but have a look:

   http://gcc.gnu.org/onlinedocs/gcc-4.4.2/gcc/Optimize-Options.html

-Lars



More information about the Digitalmars-d mailing list