www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Can getHash be made pure?

reply "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
Still chugging away at implementing AA's in druntime proper, I reviewed
the code for methods that can be marked pure but ran into a major road
block: getHash() is not marked pure. That makes a lot of AA methods
impure, that could, and probably should, be marked pure.

Is it possible to make TypeInfo.getHash() pure? AFAICT there's no good
reason why it shouldn't be pure. Am I missing something?


T

-- 
The most powerful one-line C program: #include "/dev/tty" -- IOCCC
Mar 09 2012
parent reply Walter Bright <newshound2 digitalmars.com> writes:
On 3/9/2012 1:54 PM, H. S. Teoh wrote:
 Still chugging away at implementing AA's in druntime proper, I reviewed
 the code for methods that can be marked pure but ran into a major road
 block: getHash() is not marked pure. That makes a lot of AA methods
 impure, that could, and probably should, be marked pure.

 Is it possible to make TypeInfo.getHash() pure? AFAICT there's no good
 reason why it shouldn't be pure. Am I missing something?

It should be const, pure, nothrow, safe.
Mar 09 2012
parent reply "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Fri, Mar 09, 2012 at 02:01:01PM -0800, Walter Bright wrote:
 On 3/9/2012 1:54 PM, H. S. Teoh wrote:
Still chugging away at implementing AA's in druntime proper, I reviewed
the code for methods that can be marked pure but ran into a major road
block: getHash() is not marked pure. That makes a lot of AA methods
impure, that could, and probably should, be marked pure.

Is it possible to make TypeInfo.getHash() pure? AFAICT there's no good
reason why it shouldn't be pure. Am I missing something?

It should be const, pure, nothrow, safe.

Hmph. I tried to make getHash() const pure nothrow safe, but found that in some places it calls toHash() which isn't marked const pure nothrow safe. So I fixed that as well, then found that toHash() calls toString() which isn't pure, nothrow, nor safe... and before I knew it, I was deep into marking a *lot* of druntime functions (as perhaps they *should* be), and then I ran into this: src/object_.d(648): Error: function object.TypeInfo_AssociativeArray.next () is not callable using argument types () src/object_.d(648): Error: function object.TypeInfo_AssociativeArray.next () is not callable using argument types () src/object_.d(759): Error: function object.TypeInfo_Class.info () is not callable using argument types () src/object_.d(1334): Error: cannot uniquely infer foreach argument types src/core/runtime.d(483): Error: cannot uniquely infer foreach argument types make: *** [lib/libdruntime-linux32.a] Error 1 I'm not sure how to proceed from here. A related question though: have we implemented automatic propagation of attributes like pure/nothrow/etc., yet? Just wondering if I can just modify the base class and have the attributes propagate, or I have to search for every override of every affected function in order to mark them (as I have been doing -- just wanted to make sure it isn't for nothing). T -- It won't be covered in the book. The source code has to be useful for something, after all. -- Larry Wall
Mar 09 2012
parent reply Walter Bright <newshound2 digitalmars.com> writes:
On 3/9/2012 5:15 PM, H. S. Teoh wrote:
 I tried to make getHash() const pure nothrow  safe, but found that in
 some places it calls toHash() which isn't marked const pure nothrow
  safe.  So I fixed that as well, then found that toHash() calls
 toString() which isn't pure, nothrow, nor  safe... and before I knew it,
 I was deep into marking a *lot* of druntime functions (as perhaps they
 *should* be), and then I ran into this:

 src/object_.d(648): Error: function object.TypeInfo_AssociativeArray.next ()
is not callable using argument types ()
 src/object_.d(648): Error: function object.TypeInfo_AssociativeArray.next ()
is not callable using argument types ()
 src/object_.d(759): Error: function object.TypeInfo_Class.info () is not
callable using argument types ()
 src/object_.d(1334): Error: cannot uniquely infer foreach argument types
 src/core/runtime.d(483): Error: cannot uniquely infer foreach argument types
 make: *** [lib/libdruntime-linux32.a] Error 1

Yeah, I know, it's viral. Can't do it piecemeal.
 A related question though: have we implemented automatic propagation of
 attributes like pure/nothrow/etc., yet? Just wondering if I can just
 modify the base class and have the attributes propagate, or I have to
 search for every override of every affected function in order to mark
 them (as I have been doing -- just wanted to make sure it isn't for
 nothing).

For 2.059, yes.
Mar 09 2012
parent reply "Martin Nowak" <dawg dawgfoto.de> writes:
On Sat, 10 Mar 2012 03:18:59 +0100, Walter Bright  
<newshound2 digitalmars.com> wrote:

 On 3/9/2012 5:15 PM, H. S. Teoh wrote:
 I tried to make getHash() const pure nothrow  safe, but found that in
 some places it calls toHash() which isn't marked const pure nothrow
  safe.  So I fixed that as well, then found that toHash() calls
 toString() which isn't pure, nothrow, nor  safe... and before I knew it,
 I was deep into marking a *lot* of druntime functions (as perhaps they
 *should* be), and then I ran into this:

 src/object_.d(648): Error: function  
 object.TypeInfo_AssociativeArray.next () is not callable using argument  
 types ()
 src/object_.d(648): Error: function  
 object.TypeInfo_AssociativeArray.next () is not callable using argument  
 types ()
 src/object_.d(759): Error: function object.TypeInfo_Class.info () is  
 not callable using argument types ()
 src/object_.d(1334): Error: cannot uniquely infer foreach argument types
 src/core/runtime.d(483): Error: cannot uniquely infer foreach argument  
 types
 make: *** [lib/libdruntime-linux32.a] Error 1

Yeah, I know, it's viral. Can't do it piecemeal.

Bottom-up instead of top-down?
Mar 09 2012
next sibling parent Walter Bright <newshound2 digitalmars.com> writes:
On 3/9/2012 7:21 PM, Martin Nowak wrote:
 Bottom-up instead of top-down?

both.
Mar 09 2012
prev sibling parent reply Jacob Carlborg <doob me.com> writes:
On 2012-03-10 04:21, Martin Nowak wrote:
 On Sat, 10 Mar 2012 03:18:59 +0100, Walter Bright
 Yeah, I know, it's viral. Can't do it piecemeal.

Bottom-up instead of top-down?

Hard to find somewhere to start? -- /Jacob Carlborg
Mar 10 2012
parent reply "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Sat, Mar 10, 2012 at 06:21:08PM +0100, Jacob Carlborg wrote:
 On 2012-03-10 04:21, Martin Nowak wrote:
On Sat, 10 Mar 2012 03:18:59 +0100, Walter Bright
Yeah, I know, it's viral. Can't do it piecemeal.

Bottom-up instead of top-down?

Hard to find somewhere to start?

[...] Not that hard. Just search for toString in Object, and add qualifiers to it, then compile. You'll find a ton of errors caused by propagated qualifiers. Fix those, and you'll find more, ad nauseaum. After a few iterations of this, I found myself labelling almost every method in Object, TypeInfo, and a whole bunch of other places. I'll need to sit down someday to properly and thoroughly do this. Currently my git branch is uncompilable due to a couple o' nasty places, and I'm ready to throw in the towel. :-( Maybe I'll just finish up the actual AA implementation first, then come back to revisit pure/nothrow/const/ safe after the code itself is actually working. T -- There's light at the end of the tunnel. It's the oncoming train.
Mar 10 2012
next sibling parent =?ISO-8859-1?Q?Alex_R=F8nne_Petersen?= <xtzgzorex gmail.com> writes:
On 10-03-2012 18:48, H. S. Teoh wrote:
 On Sat, Mar 10, 2012 at 06:21:08PM +0100, Jacob Carlborg wrote:
 On 2012-03-10 04:21, Martin Nowak wrote:
 On Sat, 10 Mar 2012 03:18:59 +0100, Walter Bright
 Yeah, I know, it's viral. Can't do it piecemeal.

Bottom-up instead of top-down?

Hard to find somewhere to start?

[...] Not that hard. Just search for toString in Object, and add qualifiers to it, then compile. You'll find a ton of errors caused by propagated qualifiers. Fix those, and you'll find more, ad nauseaum. After a few iterations of this, I found myself labelling almost every method in Object, TypeInfo, and a whole bunch of other places. I'll need to sit down someday to properly and thoroughly do this. Currently my git branch is uncompilable due to a couple o' nasty places, and I'm ready to throw in the towel. :-( Maybe I'll just finish up the actual AA implementation first, then come back to revisit pure/nothrow/const/ safe after the code itself is actually working. T

That sounds like the best possible strategy. -- - Alex
Mar 10 2012
prev sibling parent Dmitry Olshansky <dmitry.olsh gmail.com> writes:
On 10.03.2012 21:48, H. S. Teoh wrote:
 On Sat, Mar 10, 2012 at 06:21:08PM +0100, Jacob Carlborg wrote:
 On 2012-03-10 04:21, Martin Nowak wrote:
 On Sat, 10 Mar 2012 03:18:59 +0100, Walter Bright
 Yeah, I know, it's viral. Can't do it piecemeal.

Bottom-up instead of top-down?

Hard to find somewhere to start?

[...] Not that hard. Just search for toString in Object, and add qualifiers to it, then compile. You'll find a ton of errors caused by propagated qualifiers. Fix those, and you'll find more, ad nauseaum. After a few iterations of this, I found myself labelling almost every method in Object, TypeInfo, and a whole bunch of other places. I'll need to sit down someday to properly and thoroughly do this. Currently my git branch is uncompilable due to a couple o' nasty places, and I'm ready to throw in the towel. :-( Maybe I'll just finish up the actual AA implementation first, then come back to revisit pure/nothrow/const/ safe after the code itself is actually working. T

At least safe 'leak' could be temporarily plugged with trusted. -- Dmitry Olshansky
Mar 11 2012