Re: Temporarily disable all purity for debug prints

2011-04-22 Thread Andrew Wiley
On Fri, Apr 22, 2011 at 12:34 AM, dennis luehring wrote: > On 17.04.2011 22:45, Andrew Wiley wrote: > >> On Sun, Apr 17, 2011 at 3:30 PM, dennis luehring >> wrote: >> >>> On 11.04.2011 23:27, bearophile wrote: >>> From what I am seeing, in a D2 program if I have many (tens or more) >>

Re: Temporarily disable all purity for debug prints

2011-04-21 Thread dennis luehring
On 17.04.2011 22:45, Andrew Wiley wrote: On Sun, Apr 17, 2011 at 3:30 PM, dennis luehring wrote: On 11.04.2011 23:27, bearophile wrote: From what I am seeing, in a D2 program if I have many (tens or more) pure functions that call to each other, and I want to add (or activate) a printf/write

Re: Temporarily disable all purity for debug prints

2011-04-17 Thread Andrew Wiley
On Sun, Apr 17, 2011 at 3:30 PM, dennis luehring wrote: > On 11.04.2011 23:27, bearophile wrote: >> >>  From what I am seeing, in a D2 program if I have many (tens or more) pure >> functions that call to each other, and I want to add (or activate) a >> printf/writeln inside one (or few) of those f

Re: Temporarily disable all purity for debug prints

2011-04-17 Thread dennis luehring
On 11.04.2011 23:27, bearophile wrote: From what I am seeing, in a D2 program if I have many (tens or more) pure functions that call to each other, and I want to add (or activate) a printf/writeln inside one (or few) of those functions to debug it, I may need to temporarily comment out the "p

Re: Temporarily disable all purity for debug prints

2011-04-16 Thread Walter Bright
On 4/16/2011 1:21 PM, bearophile wrote: Walter: No, it is not. You seem to be thinking that purity is just a bug finding or optimization feature. That is not so. Purity is a guarantee that can be relied upon for a program's behavior. Breaking purity breaks that guarantee. (Think multithreaded

Re: Temporarily disable all purity for debug prints

2011-04-16 Thread bearophile
Walter: > No, it is not. You seem to be thinking that purity is just a bug finding or > optimization feature. That is not so. Purity is a guarantee that can be relied > upon for a program's behavior. Breaking purity breaks that guarantee. > > (Think multithreaded programs, for example.) I was no

Re: Temporarily disable all purity for debug prints

2011-04-16 Thread Walter Bright
On 4/16/2011 11:52 AM, bearophile wrote: Walter: Saying it is a safe way to break purity assumes that there was no purpose to the purity. There is no guaranteed safe way to break purity, with or without a compiler switch. The compiler switch I am talking about doesn't break purity. Its purpos

Re: Temporarily disable all purity for debug prints

2011-04-16 Thread bearophile
Walter: > Saying it is a safe way to break purity assumes that there was no purpose to > the purity. > There is no guaranteed safe way to break purity, with or without a compiler > switch. The compiler switch I am talking about doesn't break purity. Its purpose is similar to removing the "pure

Re: Temporarily disable all purity for debug prints

2011-04-16 Thread Walter Bright
On 4/16/2011 6:41 AM, bearophile wrote: Yes, it allows one to break the purity of the function. The alternative is to use casts (which also breaks the purity) or another compiler switch (which also breaks the purity). A compiler switch to disable purity doesn't break purity. It just turns all p

Re: Temporarily disable all purity for debug prints

2011-04-16 Thread bearophile
Walter: > Yes, it allows one to break the purity of the function. The alternative is to > use casts (which also breaks the purity) or another compiler switch (which > also > breaks the purity). A compiler switch to disable purity doesn't break purity. It just turns all pure functions inside t

Re: Temporarily disable all purity for debug prints

2011-04-15 Thread Walter Bright
On 4/15/2011 7:06 PM, bearophile wrote: There is something I don't understand. If your last change allows code like this, isn't it breaking the safety of pure functions in debug mode? Do you think this loss of safety is not important? Yes, it allows one to break the purity of the function. The

Re: Temporarily disable all purity for debug prints

2011-04-15 Thread bearophile
Walter: > On the contrary, I think it is the right solution. After all, the reason > people > want to put impure code in a pure function is for debugging. By putting it > under > the debug conditional, any logging or printing code can be there without > needing > the compiler to be aware of wha

Re: Temporarily disable all purity for debug prints

2011-04-15 Thread Walter Bright
On 4/15/2011 3:00 PM, bearophile wrote: I presume this front end change is not following my suggestion (of adding a switch to disable purity), but adds a dirty hack that allows impure debug code inside pure functions. If this is true, then let's now find the bad side effects of this change. On

Re: Temporarily disable all purity for debug prints

2011-04-15 Thread bearophile
> > Related news: > > https://github.com/D-Programming-Language/dmd/commit/ed8068f5036f88fff1603d98ebe96bb6659bceed I have forgotten to add something: thank you Walter. Sorry for criticizing before actually trying out the change. Bye, bearophile

Re: Temporarily disable all purity for debug prints

2011-04-15 Thread bearophile
David Nadlinger: > Related news: > https://github.com/D-Programming-Language/dmd/commit/ed8068f5036f88fff1603d98ebe96bb6659bceed It's a bit disconcerting to see how important things I'm asking and arguing for for three years or more gets ignored, while this that I have barely noted gets worked

Re: Temporarily disable all purity for debug prints

2011-04-15 Thread David Nadlinger
On 4/11/11 11:27 PM, bearophile wrote: From what I am seeing, in a D2 program if I have many (tens or more) pure functions that call to each other, and I want to add (or activate) a printf/writeln inside one (or few) of those functions to debug it, I may need to temporarily comment out the "p

Re: Temporarily disable all purity for debug prints

2011-04-12 Thread spir
On 04/12/2011 09:54 PM, Steven Schveighoffer wrote: On Tue, 12 Apr 2011 15:48:33 -0400, bearophile wrote: Walter: pure void foo() { debug writeln("in foo()"); } Simple and effective. Very simple designs are sometimes the mark of the genius. But isn't your idea able to lead to debug code t

Re: Temporarily disable all purity for debug prints

2011-04-12 Thread Steven Schveighoffer
On Tue, 12 Apr 2011 16:11:41 -0400, bearophile 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

Re: Temporarily disable all purity for debug prints

2011-04-12 Thread bearophile
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

Re: Temporarily disable all purity for debug prints

2011-04-12 Thread Steven Schveighoffer
On Tue, 12 Apr 2011 15:48:33 -0400, bearophile wrote: Walter: pure void foo() { debug writeln("in foo()"); } Simple and effective. Very simple designs are sometimes the mark of the genius. But isn't your idea able to lead to debug code that's more buggy than the nondebug code, i

Re: Temporarily disable all purity for debug prints

2011-04-12 Thread bearophile
Walter: > pure void foo() > { > debug writeln("in foo()"); > } > > Simple and effective. Very simple designs are sometimes the mark of the genius. But isn't your idea able to lead to debug code that's more buggy than the nondebug code, if some side effect (like modifying a global) is used

Re: Temporarily disable all purity for debug prints

2011-04-12 Thread Steven Schveighoffer
On Tue, 12 Apr 2011 13:18:30 -0400, Walter Bright wrote: On 4/12/2011 8:03 AM, Steven Schveighoffer wrote: use C linkage, you can do whatever you want. It's how druntime accomplishes a lot of stuff. For example: puredebug.d: import std.stdio; extern(C) void pureprint(string[] values...

Re: Temporarily disable all purity for debug prints

2011-04-12 Thread Walter Bright
On 4/12/2011 8:03 AM, Steven Schveighoffer wrote: use C linkage, you can do whatever you want. It's how druntime accomplishes a lot of stuff. For example: puredebug.d: import std.stdio; extern(C) void pureprint(string[] values...) { write("[pure debug] "); foreach(value; values) write(value);

Re: Temporarily disable all purity for debug prints

2011-04-12 Thread bearophile
David Gileadi: > I'm not a day-to-day D programmer but it's seemed to me for a while that > having a print/log function that would work in normal code, in pure code > and in CTFE would be extremely useful. Vote, if you like :-) This asks for something minimal, a way to print strings at compile

Re: Temporarily disable all purity for debug prints

2011-04-12 Thread David Gileadi
On 4/12/11 1:12 AM, spir wrote: On 04/12/2011 04:05 AM, Nick Sabalausky wrote: As more and more D2 functions become pure in my code and in Phobos, > something like a -disablepure compiler switch (and printf/writeln inside > debug{}) may allow more handy debugging with prints (if the purity is we

Re: Temporarily disable all purity for debug prints

2011-04-12 Thread Steven Schveighoffer
On Mon, 11 Apr 2011 17:27:41 -0400, bearophile wrote: From what I am seeing, in a D2 program if I have many (tens or more) pure functions that call to each other, and I want to add (or activate) a printf/writeln inside one (or few) of those functions to debug it, I may need to temporaril

Re: Temporarily disable all purity for debug prints

2011-04-12 Thread spir
On 04/12/2011 04:05 AM, Nick Sabalausky wrote: As more and more D2 functions become pure in my code and in Phobos, > something like a -disablepure compiler switch (and printf/writeln inside > debug{}) may allow more handy debugging with prints (if the purity is well > managed by the compiler t

Re: Temporarily disable all purity for debug prints

2011-04-11 Thread Nick Sabalausky
"bearophile" wrote in message news:invrod$3182$1...@digitalmars.com... > From what I am seeing, in a D2 program if I have many (tens or more) pure > functions that call to each other, and I want to add (or activate) a > printf/writeln inside one (or few) of those functions to debug it, I may >

Re: Temporarily disable all purity for debug prints

2011-04-11 Thread Adam D. Ruppe
bearophile: > To avoid some possible troubles I suggest to keep puts pure only in debug > builds: Definitely. It is a filthy hack, after all!

Re: Temporarily disable all purity for debug prints

2011-04-11 Thread bearophile
dsimcha: > Interesting (and practical) idea. It's one example of a third class of compiler messages that I have named compiler tips (beside warnings and errors). > The only problems I see are templated > functions (for which pure, nothrow, etc. are so broken it's not even > funny) and findin

Re: Temporarily disable all purity for debug prints

2011-04-11 Thread bearophile
Adam D. Ruppe: > Yes. In fact, I view it as better than always seeing it twenty > times because it reflects what's actually going on. To avoid some possible troubles I suggest to keep puts pure only in debug builds: debug extern(C) pure void puts(const char*); else extern(C) void puts(c

Re: Temporarily disable all purity for debug prints

2011-04-11 Thread dsimcha
On 4/11/2011 6:23 PM, bearophile wrote: One extra note: in GCC 4.6 there are compiler switches like -Wsuggest-attribute=const that generate suggestions for functions that are implicitly const (pure) but don't have a const attribute yet. Bye, bearophile Interesting (and practical) idea. The

Re: Temporarily disable all purity for debug prints

2011-04-11 Thread bearophile
One extra note: in GCC 4.6 there are compiler switches like -Wsuggest-attribute=const that generate suggestions for functions that are implicitly const (pure) but don't have a const attribute yet. Bye, bearophile

Re: Temporarily disable all purity for debug prints

2011-04-11 Thread Adam D. Ruppe
bearophile wrote: > Is this an acceptable debug printing for you? Yes. In fact, I view it as better than always seeing it twenty times because it reflects what's actually going on. You already know what it's supposed to do, and if it did what it was supposed to do, you wouldn't be debugging it.

Re: Temporarily disable all purity for debug prints

2011-04-11 Thread spir
On 04/11/2011 11:27 PM, bearophile wrote: From what I am seeing, in a D2 program if I have many (tens or more) pure functions that call to each other, and I want to add (or activate) a printf/writeln inside one (or few) of those functions to debug it, I may need to temporarily comment out the

Re: Temporarily disable all purity for debug prints

2011-04-11 Thread bearophile
Adam D. Ruppe: > I wonder if it would be a good idea to have logging or debug prints > that simply lie about being pure so you can use them there. If the compiler sees a function as pure, the debug prints may or may not appear according to how much pure-related optimizations the compiler is doin

Re: Temporarily disable all purity for debug prints

2011-04-11 Thread Adam D. Ruppe
I wonder if it would be a good idea to have logging or debug prints that simply lie about being pure so you can use them there. Something like this: == extern(C) pure void puts(const char*); pure void hello() { puts("hello world from pure land\n"); // compiles } ==

Temporarily disable all purity for debug prints

2011-04-11 Thread bearophile
>From what I am seeing, in a D2 program if I have many (tens or more) pure >functions that call to each other, and I want to add (or activate) a >printf/writeln inside one (or few) of those functions to debug it, I may need >to temporarily comment out the "pure" attribute of many functions (beca