Temporarily disable all purity for debug prints

Steven Schveighoffer schveiguy at yahoo.com
Tue Apr 12 13:23:50 PDT 2011


On Tue, 12 Apr 2011 16:11:41 -0400, bearophile <bearophileHUGS at lycos.com>  
wrote:

> Steven Schveighoffer:
>
>> Well, yes.  So?  How does the compiler establish rules to separate "safe
>> debug printing" from "all code that isn't pure"?  If you did that, how
>> does the compiler know it's safe?  The only way I can think of is to  
>> treat
>> writeln specially, which doesn't sound like the right thing to do.
>
> In the first post in this thread I have suggested a possible solution  
> that avoids that unsafety, a compilation switch to disable all pure  
> annotations in the program/compilation unit. Then you are able to add  
> printing statements in a version{} relative to this compilation switch.

I think the -debug switch should disable certain pure optimizations (like  
running multiple calls in parallel on different cores) so issues with  
unpure code being inside pure functions wouldn't affect them.  If you are  
in debug mode, you shouldn't worry about performance as much.

Of course, you'd still see some oddities in other cases of pure  
optimizations (like refactoring), but I think you'd *want* to see those.   
In fact, I'd think you want to have most of the pure optimizations apply  
to see how it actually refactors.

-Steve


More information about the Digitalmars-d mailing list