Re: toHash => pure, nothrow, const, @safe

2012-03-14 Thread Steven Schveighoffer
On Wed, 14 Mar 2012 09:27:08 -0400, Martin Nowak wrote: In essence, when @type is encountered the compiler looks at TypeInfo_Struct (in object.di) for the equivalent xfuncname. Then uses the attributes of that function pointer (and also the parameter types/count) to compile the given meth

Re: toHash => pure, nothrow, const, @safe

2012-03-14 Thread Martin Nowak
In essence, when @type is encountered the compiler looks at TypeInfo_Struct (in object.di) for the equivalent xfuncname. Then uses the attributes of that function pointer (and also the parameter types/count) to compile the given method. Why would you want to add explicit annotation for imp

Re: toHash => pure, nothrow, const, @safe

2012-03-14 Thread Dmitry Olshansky
On 14.03.2012 16:11, Steven Schveighoffer wrote: On Mon, 12 Mar 2012 22:06:51 -0400, Walter Bright wrote: On 3/12/2012 6:40 PM, H. S. Teoh wrote: And I'm not talking about doing just toHash, or just toString either. Any of these functions have complex interdependencies with each other, so it'

Re: toHash => pure, nothrow, const, @safe

2012-03-14 Thread Steven Schveighoffer
On Tue, 13 Mar 2012 19:23:25 -0400, Walter Bright wrote: On 3/13/2012 4:15 AM, Don Clugston wrote: On 13/03/12 03:05, Walter Bright wrote: On 3/12/2012 6:15 PM, Stewart Gordon wrote: And what about toString? Good question. What do you suggest? Why can't we just kill that abomination?

Re: toHash => pure, nothrow, const, @safe

2012-03-14 Thread Steven Schveighoffer
On Mon, 12 Mar 2012 22:06:51 -0400, Walter Bright wrote: On 3/12/2012 6:40 PM, H. S. Teoh wrote: And I'm not talking about doing just toHash, or just toString either. Any of these functions have complex interdependencies with each other, so it's either fix them ALL, or not at all. Yup. It

Re: toHash => pure, nothrow, const, @safe

2012-03-14 Thread Steven Schveighoffer
On Tue, 13 Mar 2012 12:03:22 -0400, Alex Rønne Petersen wrote: Yes, and in some cases, it doesn't even work right; i.e. you can declare certain opCmp and opEquals signatures that work fine for ==, >, <, etc but don't get emitted to the TypeInfo metadata, and vice versa. It's a mess. Se

Re: toHash => pure, nothrow, const, @safe

2012-03-14 Thread Martin Nowak
In general, for modules a and b, all of these should work: dmd a b dmd b a dmd -c a dmd -c b For '-c' CTFE will already run semantic3 on the other module's functions. But it would be very inefficient to do that for attributes.

Re: toHash => pure, nothrow, const, @safe

2012-03-14 Thread Dmitry Olshansky
On 14.03.2012 3:23, Walter Bright wrote: On 3/13/2012 4:15 AM, Don Clugston wrote: On 13/03/12 03:05, Walter Bright wrote: On 3/12/2012 6:15 PM, Stewart Gordon wrote: And what about toString? Good question. What do you suggest? Why can't we just kill that abomination? Break a lot of exis

Re: toHash => pure, nothrow, const, @safe

2012-03-14 Thread Manu
On 13 March 2012 04:15, H. S. Teoh wrote: > On Mon, Mar 12, 2012 at 07:06:51PM -0700, Walter Bright wrote: > > On 3/12/2012 6:40 PM, H. S. Teoh wrote: > > >And I'm not talking about doing just toHash, or just toString either. > > >Any of these functions have complex interdependencies with each >

Re: toHash => pure, nothrow, const, @safe

2012-03-13 Thread Walter Bright
On 3/13/2012 4:50 AM, Martin Nowak wrote: Yeah, you're right. It would easily create confusing behavior. In general, for modules a and b, all of these should work: dmd a b dmd b a dmd -c a dmd -c b

Re: toHash => pure, nothrow, const, @safe

2012-03-13 Thread Andrei Alexandrescu
On 3/13/12 5:39 PM, kennytm wrote: Andrei Alexandrescu wrote: Because in the general case functions call one another so there's no way to figure which to look at first. Andrei That's no difference from template functions calling each others right? int a()(int x) { return x==0?1:b(x-1);

Re: toHash => pure, nothrow, const, @safe

2012-03-13 Thread bearophile
Walter: > Break a lot of existing code? Invent a good deprecation strategy for toString? The idea of modifying toString isn't new, we have discussed it more than on time, and I agree with the general strategy Don appreciates. As far as I know you didn't do much on it mostly because there were

Re: toHash => pure, nothrow, const, @safe

2012-03-13 Thread Timon Gehr
On 03/13/2012 11:39 PM, kennytm wrote: Andrei Alexandrescu wrote: On 3/13/12 6:02 AM, Peter Alexander wrote: On Monday, 12 March 2012 at 09:40:15 UTC, Walter Bright wrote: On 3/12/2012 1:08 AM, Martin Nowak wrote: What's wrong with auto-inference. Inferred attributes are only strengthening g

Re: toHash => pure, nothrow, const, @safe

2012-03-13 Thread Walter Bright
On 3/13/2012 4:15 AM, Don Clugston wrote: On 13/03/12 03:05, Walter Bright wrote: On 3/12/2012 6:15 PM, Stewart Gordon wrote: And what about toString? Good question. What do you suggest? Why can't we just kill that abomination? Break a lot of existing code?

Re: toHash => pure, nothrow, const, @safe

2012-03-13 Thread kennytm
Andrei Alexandrescu wrote: > On 3/13/12 6:02 AM, Peter Alexander wrote: >> On Monday, 12 March 2012 at 09:40:15 UTC, Walter Bright wrote: >>> On 3/12/2012 1:08 AM, Martin Nowak wrote: What's wrong with auto-inference. Inferred attributes are only strengthening guarantees. >>> >>> A

Re: toHash => pure, nothrow, const, @safe

2012-03-13 Thread Martin Nowak
On Tue, 13 Mar 2012 04:40:01 +0100, Andrei Alexandrescu wrote: I think the three others have a special regime because pointers to them must be saved for the sake of associative arrays. toString is used only generically, Andrei Adding a special case for AAs is not a good idea but these

Re: toHash => pure, nothrow, const, @safe

2012-03-13 Thread H. S. Teoh
On Tue, Mar 13, 2012 at 11:06:00AM -0500, Andrei Alexandrescu wrote: > On 3/13/12 10:47 AM, deadalnix wrote: > >This problem is pretty close to garbage collection. Let's use pure as > >example, but it work with other qualifier too. > > > >function are marked pure, impure, or pure given all function

Re: toHash => pure, nothrow, const, @safe

2012-03-13 Thread deadalnix
Le 13/03/2012 17:06, Andrei Alexandrescu a écrit : On 3/13/12 10:47 AM, deadalnix wrote: This problem is pretty close to garbage collection. Let's use pure as example, but it work with other qualifier too. function are marked pure, impure, or pure given all function called are pure (possibly pu

Re: toHash => pure, nothrow, const, @safe

2012-03-13 Thread Andrei Alexandrescu
On 3/13/12 10:47 AM, deadalnix wrote: This problem is pretty close to garbage collection. Let's use pure as example, but it work with other qualifier too. function are marked pure, impure, or pure given all function called are pure (possibly pure). Then you go throw all possibly pure function an

Re: toHash => pure, nothrow, const, @safe

2012-03-13 Thread Alex Rønne Petersen
On 13-03-2012 16:56, deadalnix wrote: Le 13/03/2012 01:50, Walter Bright a écrit : On 3/12/2012 4:11 AM, deadalnix wrote: For struct, we have inference, ? No we don't. Ok my mistake. So why not dig in that direction ? so most of the time attributes will correct. const pure nothrow @safe

Re: toHash => pure, nothrow, const, @safe

2012-03-13 Thread deadalnix
Le 13/03/2012 01:50, Walter Bright a écrit : On 3/12/2012 4:11 AM, deadalnix wrote: For struct, we have inference, ? No we don't. Ok my mistake. So why not dig in that direction ? so most of the time attributes will correct. const pure nothrow @safe are something we want, but is it someth

Re: toHash => pure, nothrow, const, @safe

2012-03-13 Thread deadalnix
Le 13/03/2012 15:46, Andrei Alexandrescu a écrit : On 3/13/12 6:02 AM, Peter Alexander wrote: On Monday, 12 March 2012 at 09:40:15 UTC, Walter Bright wrote: On 3/12/2012 1:08 AM, Martin Nowak wrote: What's wrong with auto-inference. Inferred attributes are only strengthening guarantees. Auto

Re: toHash => pure, nothrow, const, @safe

2012-03-13 Thread Andrei Alexandrescu
On 3/13/12 6:02 AM, Peter Alexander wrote: On Monday, 12 March 2012 at 09:40:15 UTC, Walter Bright wrote: On 3/12/2012 1:08 AM, Martin Nowak wrote: What's wrong with auto-inference. Inferred attributes are only strengthening guarantees. Auto-inference is currently done for lambdas and templat

Re: toHash => pure, nothrow, const, @safe

2012-03-13 Thread Martin Nowak
On Tue, 13 Mar 2012 01:40:08 +0100, Walter Bright wrote: On 3/12/2012 1:56 PM, Martin Nowak wrote: It doesn't require all source code. It just means that without source code nothing can be inferred and the attributes fall back to what has been annotated by hand. Hello endless bug reports o

Re: toHash => pure, nothrow, const, @safe

2012-03-13 Thread Don Clugston
On 13/03/12 03:05, Walter Bright wrote: On 3/12/2012 6:15 PM, Stewart Gordon wrote: And what about toString? Good question. What do you suggest? Why can't we just kill that abomination?

Re: toHash => pure, nothrow, const, @safe

2012-03-13 Thread deadalnix
Le 13/03/2012 12:02, Peter Alexander a écrit : On Monday, 12 March 2012 at 09:40:15 UTC, Walter Bright wrote: On 3/12/2012 1:08 AM, Martin Nowak wrote: What's wrong with auto-inference. Inferred attributes are only strengthening guarantees. Auto-inference is currently done for lambdas and tem

Re: toHash => pure, nothrow, const, @safe

2012-03-13 Thread Peter Alexander
On Monday, 12 March 2012 at 09:40:15 UTC, Walter Bright wrote: On 3/12/2012 1:08 AM, Martin Nowak wrote: What's wrong with auto-inference. Inferred attributes are only strengthening guarantees. Auto-inference is currently done for lambdas and template functions - why? - because the function'

Re: toHash => pure, nothrow, const, @safe

2012-03-13 Thread Jacob Carlborg
On 2012-03-13 01:40, Walter Bright wrote: On 3/12/2012 1:56 PM, Martin Nowak wrote: It doesn't require all source code. It just means that without source code nothing can be inferred and the attributes fall back to what has been annotated by hand. Hello endless bug reports of the form: "It co

Re: toHash => pure, nothrow, const, @safe

2012-03-12 Thread H. S. Teoh
On Mon, Mar 12, 2012 at 10:58:18PM -0400, bearophile wrote: > Walter: > > > Good question. What do you suggest? > > I suggest to follow a slow but reliable path, working bottom-up: turn > to!string()/text()/format() into pure+nothrow functions, and then > later require toString to be pure+nothrow

Re: toHash => pure, nothrow, const, @safe

2012-03-12 Thread Andrei Alexandrescu
On 3/12/12 8:15 PM, Stewart Gordon wrote: On 11/03/2012 23:54, Walter Bright wrote: Consider the toHash() function for struct key types: http://dlang.org/hash-map.html And of course the others: const hash_t toHash(); const bool opEquals(ref const KeyType s); const int opCmp(ref const KeyType

Re: toHash => pure, nothrow, const, @safe

2012-03-12 Thread bearophile
Walter: > Good question. What do you suggest? I suggest to follow a slow but reliable path, working bottom-up: turn to!string()/text()/format() into pure+nothrow functions, and then later require toString to be pure+nothrow and to have such annotations. Bye, bearophile

Re: toHash => pure, nothrow, const, @safe

2012-03-12 Thread Alex Rønne Petersen
On 13-03-2012 03:15, H. S. Teoh wrote: On Mon, Mar 12, 2012 at 07:06:51PM -0700, Walter Bright wrote: On 3/12/2012 6:40 PM, H. S. Teoh wrote: And I'm not talking about doing just toHash, or just toString either. Any of these functions have complex interdependencies with each other, so it's eith

Re: toHash => pure, nothrow, const, @safe

2012-03-12 Thread H. S. Teoh
On Mon, Mar 12, 2012 at 07:06:51PM -0700, Walter Bright wrote: > On 3/12/2012 6:40 PM, H. S. Teoh wrote: > >And I'm not talking about doing just toHash, or just toString either. > >Any of these functions have complex interdependencies with each > >other, so it's either fix them ALL, or not at all.

Re: toHash => pure, nothrow, const, @safe

2012-03-12 Thread Walter Bright
On 3/12/2012 6:15 PM, Stewart Gordon wrote: And what about toString? Good question. What do you suggest?

Re: toHash => pure, nothrow, const, @safe

2012-03-12 Thread Walter Bright
On 3/12/2012 6:40 PM, H. S. Teoh wrote: And I'm not talking about doing just toHash, or just toString either. Any of these functions have complex interdependencies with each other, so it's either fix them ALL, or not at all. Yup. It also seems very hard to figure out a transitional path to it.

Re: toHash => pure, nothrow, const, @safe

2012-03-12 Thread Alex Rønne Petersen
On 13-03-2012 02:28, bearophile wrote: Stewart Gordon: And what about toString? Often in toString I use format() or text(), or to!string(), that currently aren't pure nor nothrow. But in this thread I have seen no answers regarding deprecating the need of opCmp() for hashability. Bye, bea

Re: toHash => pure, nothrow, const, @safe

2012-03-12 Thread H. S. Teoh
On Mon, Mar 12, 2012 at 09:27:41PM -0400, Jonathan M Davis wrote: > On Tuesday, March 13, 2012 01:15:59 Stewart Gordon wrote: > > On 11/03/2012 23:54, Walter Bright wrote: > > > Consider the toHash() function for struct key types: > > > > > > http://dlang.org/hash-map.html > > > > > > And of cour

Re: toHash => pure, nothrow, const, @safe

2012-03-12 Thread bearophile
Stewart Gordon: > And what about toString? Often in toString I use format() or text(), or to!string(), that currently aren't pure nor nothrow. But in this thread I have seen no answers regarding deprecating the need of opCmp() for hashability. Bye, bearophile

Re: toHash => pure, nothrow, const, @safe

2012-03-12 Thread Jonathan M Davis
On Tuesday, March 13, 2012 01:15:59 Stewart Gordon wrote: > On 11/03/2012 23:54, Walter Bright wrote: > > Consider the toHash() function for struct key types: > > > > http://dlang.org/hash-map.html > > > > And of course the others: > > > > const hash_t toHash(); > > const bool opEquals(ref const

Re: toHash => pure, nothrow, const, @safe

2012-03-12 Thread Stewart Gordon
On 11/03/2012 23:54, Walter Bright wrote: Consider the toHash() function for struct key types: http://dlang.org/hash-map.html And of course the others: const hash_t toHash(); const bool opEquals(ref const KeyType s); const int opCmp(ref const KeyType s); And what about toString? Stewart.

Re: toHash => pure, nothrow, const, @safe

2012-03-12 Thread Walter Bright
On 3/12/2012 11:10 AM, Jonathan M Davis wrote: I believe that Walter likes to say that it takes away your excuse _not_ to write them because of how easy it is to write unit tests in D. It can be remarkable how much more use something gets if you just make it a bit more convenient.

Re: toHash => pure, nothrow, const, @safe

2012-03-12 Thread Walter Bright
On 3/12/2012 4:11 AM, deadalnix wrote: For struct, we have inference, ? No we don't. so most of the time attributes will correct. const pure nothrow @safe are something we want, but is it something we want to enforce ? Yes, because they are referred to by TypeInfo, and that's fairly useless

Re: toHash => pure, nothrow, const, @safe

2012-03-12 Thread Walter Bright
On 3/12/2012 1:56 PM, Martin Nowak wrote: It doesn't require all source code. It just means that without source code nothing can be inferred and the attributes fall back to what has been annotated by hand. Hello endless bug reports of the form: "It compiles when I send the arguments to dmd thi

Re: toHash => pure, nothrow, const, @safe

2012-03-12 Thread Timon Gehr
On 03/12/2012 09:46 PM, Jonathan M Davis wrote: On Monday, March 12, 2012 21:36:21 Martin Nowak wrote: That could be solved with a @ctfe attribute or something, no? Like, if the function has @ctfe, go through all possible CTFE paths (excluding !__ctfe paths of course) and make sure they are CTFE

Re: toHash => pure, nothrow, const, @safe

2012-03-12 Thread Martin Nowak
Because that requires having all of the source code. The fact that we have .di files prevents that. It doesn't require all source code. It just means that without source code nothing can be inferred and the attributes fall back to what has been annotated by hand. It could be used to annotated f

Re: toHash => pure, nothrow, const, @safe

2012-03-12 Thread Jonathan M Davis
On Monday, March 12, 2012 11:25:41 H. S. Teoh wrote: > On Mon, Mar 12, 2012 at 02:10:23PM -0400, Jonathan M Davis wrote: > > On Monday, March 12, 2012 11:04:54 H. S. Teoh wrote: > > > Tangential note: writing unit tests may be tedious, but D's inline > > > unittest syntax has alleviated a large par

Re: toHash => pure, nothrow, const, @safe

2012-03-12 Thread Jonathan M Davis
On Monday, March 12, 2012 21:36:21 Martin Nowak wrote: > > That could be solved with a @ctfe attribute or something, no? Like, if > > the function has @ctfe, go through all possible CTFE paths (excluding > > !__ctfe paths of course) and make sure they are CTFEable. > > Everything that's pure shoul

Re: toHash => pure, nothrow, const, @safe

2012-03-12 Thread Martin Nowak
That could be solved with a @ctfe attribute or something, no? Like, if the function has @ctfe, go through all possible CTFE paths (excluding !__ctfe paths of course) and make sure they are CTFEable. Everything that's pure should be CTFEable which doesn't imply that you can turn every CTFEabl

Re: toHash => pure, nothrow, const, @safe

2012-03-12 Thread Jacob Carlborg
On 2012-03-12 19:41, Alex Rønne Petersen wrote: I stopped writing inline unit tests in larger code bases. If I do that, I have to maintain a separate build configuration just for test execution, which is not practical. Furthermore, I want to test my code in debug and release mode, which... goes a

Re: toHash => pure, nothrow, const, @safe

2012-03-12 Thread Alex Rønne Petersen
On 12-03-2012 20:08, H. S. Teoh wrote: On Mon, Mar 12, 2012 at 07:41:39PM +0100, Alex Rønne Petersen wrote: On 12-03-2012 19:04, H. S. Teoh wrote: [...] Tangential note: writing unit tests may be tedious, but D's inline unittest syntax has alleviated a large part of that tedium. So much so tha

Re: toHash => pure, nothrow, const, @safe

2012-03-12 Thread Walter Bright
On 3/12/2012 11:04 AM, H. S. Teoh wrote: Tangential note: writing unit tests may be tedious, but D's inline unittest syntax has alleviated a large part of that tedium. So much so that I find myself writing as much code in unittests as real code. Which is a good thing, because in the past I'd alwa

Re: toHash => pure, nothrow, const, @safe

2012-03-12 Thread H. S. Teoh
On Mon, Mar 12, 2012 at 07:41:39PM +0100, Alex Rønne Petersen wrote: > On 12-03-2012 19:04, H. S. Teoh wrote: [...] > >Tangential note: writing unit tests may be tedious, but D's inline > >unittest syntax has alleviated a large part of that tedium. So much > >so that I find myself writing as much c

Re: toHash => pure, nothrow, const, @safe

2012-03-12 Thread Alex Rønne Petersen
On 12-03-2012 18:55, Jonathan M Davis wrote: On Monday, March 12, 2012 18:44:06 Alex Rønne Petersen wrote: Now, that _does_ introduce the possibility of a template being to be pure and then not being able to be pure thanks to a change that's made to it or something that it uses, and that makes i

Re: toHash => pure, nothrow, const, @safe

2012-03-12 Thread Alex Rønne Petersen
On 12-03-2012 19:04, H. S. Teoh wrote: On Mon, Mar 12, 2012 at 01:55:33PM -0400, Jonathan M Davis wrote: [...] So, no, I don't think that @ctfe would really work. And while I agree that the situation isn't exactly ideal, I don't really see a way around it. Unit tests _do_ catch it for you though

Re: toHash => pure, nothrow, const, @safe

2012-03-12 Thread H. S. Teoh
On Mon, Mar 12, 2012 at 02:10:23PM -0400, Jonathan M Davis wrote: > On Monday, March 12, 2012 11:04:54 H. S. Teoh wrote: > > Tangential note: writing unit tests may be tedious, but D's inline > > unittest syntax has alleviated a large part of that tedium. So much so > > that I find myself writing a

Re: toHash => pure, nothrow, const, @safe

2012-03-12 Thread Jonathan M Davis
On Monday, March 12, 2012 11:04:54 H. S. Teoh wrote: > Tangential note: writing unit tests may be tedious, but D's inline > unittest syntax has alleviated a large part of that tedium. So much so > that I find myself writing as much code in unittests as real code. > Which is a good thing, because in

Re: toHash => pure, nothrow, const, @safe

2012-03-12 Thread H. S. Teoh
On Mon, Mar 12, 2012 at 01:55:33PM -0400, Jonathan M Davis wrote: [...] > So, no, I don't think that @ctfe would really work. And while I agree > that the situation isn't exactly ideal, I don't really see a way > around it. Unit tests _do_ catch it for you though. The only thing > that they can't c

Re: toHash => pure, nothrow, const, @safe

2012-03-12 Thread Jonathan M Davis
On Monday, March 12, 2012 18:44:06 Alex Rønne Petersen wrote: > > Now, that _does_ introduce the possibility of a template being to be pure > > and then not being able to be pure thanks to a change that's made to it > > or something that it uses, and that makes impossible for any code using > > it

Re: toHash => pure, nothrow, const, @safe

2012-03-12 Thread Alex Rønne Petersen
On 12-03-2012 18:38, Jonathan M Davis wrote: On Monday, March 12, 2012 14:23:28 Alex Rønne Petersen wrote: On 12-03-2012 14:16, deadalnix wrote: Le 12/03/2012 13:51, Alex Rønne Petersen a écrit : On 12-03-2012 10:40, Walter Bright wrote: On 3/12/2012 1:08 AM, Martin Nowak wrote: What's wrong

Re: toHash => pure, nothrow, const, @safe

2012-03-12 Thread Jonathan M Davis
On Monday, March 12, 2012 14:23:28 Alex Rønne Petersen wrote: > On 12-03-2012 14:16, deadalnix wrote: > > Le 12/03/2012 13:51, Alex Rønne Petersen a écrit : > >> On 12-03-2012 10:40, Walter Bright wrote: > >>> On 3/12/2012 1:08 AM, Martin Nowak wrote: > What's wrong with auto-inference. Inferr

Re: toHash => pure, nothrow, const, @safe

2012-03-12 Thread Jonathan M Davis
On Monday, March 12, 2012 09:14:17 Martin Nowak wrote: > > So I propose instead a bit of a hack. toHash, opEquals, and opCmp as > > struct members be automatically annotated with pure, nothrow, and @safe > > (if not already marked as @trusted). > > How about complete inference instead of a hack?

Re: toHash => pure, nothrow, const, @safe

2012-03-12 Thread bearophile
Walter: toHash, opEquals, and opCmp as struct members be automatically annotated with pure, nothrow, and @safe (if not already marked as @trusted). I have read the other answers of this thread, and I don't like some of them. In this case I think this programmer convenience doesn't justify

Re: toHash => pure, nothrow, const, @safe

2012-03-12 Thread Martin Nowak
On Mon, 12 Mar 2012 10:40:16 +0100, Walter Bright wrote: On 3/12/2012 1:08 AM, Martin Nowak wrote: What's wrong with auto-inference. Inferred attributes are only strengthening guarantees. Auto-inference is currently done for lambdas and template functions - why? - because the function'

Re: toHash => pure, nothrow, const, @safe

2012-03-12 Thread Alex Rønne Petersen
On 12-03-2012 14:16, deadalnix wrote: Le 12/03/2012 13:51, Alex Rønne Petersen a écrit : On 12-03-2012 10:40, Walter Bright wrote: On 3/12/2012 1:08 AM, Martin Nowak wrote: What's wrong with auto-inference. Inferred attributes are only strengthening guarantees. Auto-inference is currently do

Re: toHash => pure, nothrow, const, @safe

2012-03-12 Thread Steven Schveighoffer
On Sun, 11 Mar 2012 19:54:09 -0400, Walter Bright wrote: Consider the toHash() function for struct key types: http://dlang.org/hash-map.html And of course the others: const hash_t toHash(); const bool opEquals(ref const KeyType s); const int opCmp(ref const KeyType s); They need to be, as

Re: toHash => pure, nothrow, const, @safe

2012-03-12 Thread deadalnix
Le 12/03/2012 13:51, Alex Rønne Petersen a écrit : On 12-03-2012 10:40, Walter Bright wrote: On 3/12/2012 1:08 AM, Martin Nowak wrote: What's wrong with auto-inference. Inferred attributes are only strengthening guarantees. Auto-inference is currently done for lambdas and template functions -

Re: toHash => pure, nothrow, const, @safe

2012-03-12 Thread Alex Rønne Petersen
On 12-03-2012 10:40, Walter Bright wrote: On 3/12/2012 1:08 AM, Martin Nowak wrote: What's wrong with auto-inference. Inferred attributes are only strengthening guarantees. Auto-inference is currently done for lambdas and template functions - why? - because the function's implementation is gua

Re: toHash => pure, nothrow, const, @safe

2012-03-12 Thread Don Clugston
On 12/03/12 00:55, Alex Rønne Petersen wrote: On 12-03-2012 00:54, Walter Bright wrote: Consider the toHash() function for struct key types: http://dlang.org/hash-map.html And of course the others: const hash_t toHash(); const bool opEquals(ref const KeyType s); const int opCmp(ref const KeyT

Re: toHash => pure, nothrow, const, @safe

2012-03-12 Thread deadalnix
Le 12/03/2012 00:54, Walter Bright a écrit : Consider the toHash() function for struct key types: http://dlang.org/hash-map.html And of course the others: const hash_t toHash(); const bool opEquals(ref const KeyType s); const int opCmp(ref const KeyType s); They need to be, as well as const,

Re: toHash => pure, nothrow, const, @safe

2012-03-12 Thread James Miller
> That sounds intentionally. > > Say you have a struct with a getHash method. > > struct Key > { >    hash_t getHash() /* inferred pure */ >    { >    } > } > > Say you have an Set that requires a pure opHash. > > void insert(Key key) pure > { >    immutable hash = key.toHash(); > } > > Now if you

Re: toHash => pure, nothrow, const, @safe

2012-03-12 Thread Martin Nowak
One problem I can think of is relying on the auto-inference can create fragile code. You make a change in one place without concentrating and suddenly a completely different part of your code breaks, because it's expecting pure, or @safe code and you have done something to prevent the inference. I

Re: toHash => pure, nothrow, const, @safe

2012-03-12 Thread Walter Bright
On 3/12/2012 1:08 AM, Martin Nowak wrote: What's wrong with auto-inference. Inferred attributes are only strengthening guarantees. Auto-inference is currently done for lambdas and template functions - why? - because the function's implementation is guaranteed to be visible to the compiler. Fo

Re: toHash => pure, nothrow, const, @safe

2012-03-12 Thread Marco Leise
Am Mon, 12 Mar 2012 07:06:33 +0100 schrieb Alex Rønne Petersen : > I should point out that I *do* think the idea is good (i.e. if you want > the "bad" things, that's what you have to declare), but it's just too > late now. Also, there might be issues with const and the likes - should > the syst

Re: toHash => pure, nothrow, const, @safe

2012-03-12 Thread Martin Nowak
So I propose instead a bit of a hack. toHash, opEquals, and opCmp as struct members be automatically annotated with pure, nothrow, and @safe (if not already marked as @trusted). How about complete inference instead of a hack?

Re: toHash => pure, nothrow, const, @safe

2012-03-12 Thread James Miller
On 12 March 2012 21:08, Martin Nowak wrote: > On Mon, 12 Mar 2012 07:04:52 +0100, Alex Rønne Petersen > wrote: > >> Or, as a compromise, perhaps the compiler can auto-infer most of the >> attributes without any further effort from the user. >>  No, that has API design issues. You can silently bre

Re: toHash => pure, nothrow, const, @safe

2012-03-12 Thread Martin Nowak
On Mon, 12 Mar 2012 07:04:52 +0100, Alex Rønne Petersen wrote: Or, as a compromise, perhaps the compiler can auto-infer most of the attributes without any further effort from the user. No, that has API design issues. You can silently break a guarantee you made previously. What's wrong wi

Re: toHash => pure, nothrow, const, @safe

2012-03-12 Thread so
On Monday, 12 March 2012 at 07:18:06 UTC, so wrote: A pattern is emerging. Why not analyze it a bit and somehow try to find a common ground? Then we can generalize it to a single annotation. @mask(wat) const|pure|nothrow|safe @wat hash_t toHash() @wat bool opEquals(ref const KeyType s) @wat

Re: toHash => pure, nothrow, const, @safe

2012-03-12 Thread so
On Sunday, 11 March 2012 at 23:54:10 UTC, Walter Bright wrote: Consider the toHash() function for struct key types: http://dlang.org/hash-map.html And of course the others: const hash_t toHash(); const bool opEquals(ref const KeyType s); const int opCmp(ref const KeyType s); They need to be,

Re: toHash => pure, nothrow, const, @safe

2012-03-11 Thread Alex Rønne Petersen
On 12-03-2012 07:04, Alex Rønne Petersen wrote: On 12-03-2012 06:43, H. S. Teoh wrote: On Sun, Mar 11, 2012 at 04:54:09PM -0700, Walter Bright wrote: Consider the toHash() function for struct key types: http://dlang.org/hash-map.html And of course the others: const hash_t toHash(); const boo

Re: toHash => pure, nothrow, const, @safe

2012-03-11 Thread Alex Rønne Petersen
On 12-03-2012 06:43, H. S. Teoh wrote: On Sun, Mar 11, 2012 at 04:54:09PM -0700, Walter Bright wrote: Consider the toHash() function for struct key types: http://dlang.org/hash-map.html And of course the others: const hash_t toHash(); const bool opEquals(ref const KeyType s); const int opCmp(

Re: toHash => pure, nothrow, const, @safe

2012-03-11 Thread H. S. Teoh
On Sun, Mar 11, 2012 at 04:54:09PM -0700, Walter Bright wrote: > Consider the toHash() function for struct key types: > > http://dlang.org/hash-map.html > > And of course the others: > > const hash_t toHash(); > const bool opEquals(ref const KeyType s); > const int opCmp(ref const KeyType s); >

Re: toHash => pure, nothrow, const, @safe

2012-03-11 Thread bearophile
Kapps: > Agreed. Those are already special, so I don't think it hurts to > make this change. But I may be missing some implications. At risk of sounding like a troll, I hope from now on Walter will not use this kind of strategy to solve all the MANY breaking changes D/DMD will need to face :-)

Re: toHash => pure, nothrow, const, @safe

2012-03-11 Thread Kapps
On Sunday, 11 March 2012 at 23:55:34 UTC, Alex Rønne Petersen wrote: It may be a hack, but you know, those have special semantics/meanings in the first place, so is it really that bad? Consider also that contract blocks are now implicitly const, etc. Agreed. Those are already special, so I do

Re: toHash => pure, nothrow, const, @safe

2012-03-11 Thread bearophile
Walter: > So I propose instead a bit of a hack. toHash, opEquals, and opCmp as struct > members be automatically annotated with pure, nothrow, and @safe (if not > already > marked as @trusted). Recently I have suggested to deprecate and later remove the need of opCmp for the built-in AAs. Re

Re: toHash => pure, nothrow, const, @safe

2012-03-11 Thread Alex Rønne Petersen
On 12-03-2012 00:54, Walter Bright wrote: Consider the toHash() function for struct key types: http://dlang.org/hash-map.html And of course the others: const hash_t toHash(); const bool opEquals(ref const KeyType s); const int opCmp(ref const KeyType s); They need to be, as well as const, pur

toHash => pure, nothrow, const, @safe

2012-03-11 Thread Walter Bright
Consider the toHash() function for struct key types: http://dlang.org/hash-map.html And of course the others: const hash_t toHash(); const bool opEquals(ref const KeyType s); const int opCmp(ref const KeyType s); They need to be, as well as const, pure nothrow @safe. The problem is: 1. a lot