October 05, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3356



--- Comment #10 from Don <clugdbug@yahoo.com.au> 2009-10-05 07:11:21 PDT ---
(In reply to comment #7)
> For me this compiles:
> ----
> __gshared char[] str;
> 
> char fun(in char[] s) pure
> {
>     return s[0];
> }
> 
> int main()
> {
>     char a=fun(str);
>     return 0;
> }
> ----
> 
> __gshared is not a type modifier.

Ouch. That definitely shouldn't compile. Obviously 'pure' isn't doing any parameter checking at all. The parameter isn't even const!!

But yes, I agree there's a problem there. It's not going to work if __gshared parameters are passed to pure functions. Note that __gshared isn't allowed in SafeD, but still, this is starting to look ugly.

> Sharing feature is young, it's still not clear how well it suits real code,
> recently its behavior has changed to imply synchronization, we don't know
> whether it will be widely adopted, so I don't think It's a good idea to rely on it so hardly.

Yes. Although the only long as 'shared' remains transitive, it'd be OK.

(In reply to comment #9)
> > Note that you can just look at the parameter list and distinguish levels of purity: if there are any non-immutable reference parameters, it's not cachable. I guess the question is whether that additional complexity is justified.
> 
> Yes, two flavors of pureness can be introduces, it should be documented, what optimizations can be applied to them in relation to threading model. But isn't it a lot of work to specify and implement two flavors of pureness at the same time?
No, because you can get it trivially from the function signature. The big problem is that from the user's point of view, the language is too complicated already. Although, this really only affects optimisation, so users don't really need to know about it.

 At this time optimization for non-immutable arguments should be turned
> off until it's implemented correctly. Does dmd perform any pure optimizations at this time?

Almost none.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 05, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3356



--- Comment #11 from Sobirari Muhomori <dfj1esp02@sneakemail.com> 2009-10-05 07:54:07 PDT ---
> Ouch. That definitely shouldn't compile. Obviously 'pure' isn't doing any parameter checking at all. The parameter isn't even const!!

It's const. I use 'in' instead of const.

> Note that __gshared isn't allowed in
> SafeD, but still, this is starting to look ugly.

__gshared is in fact a hack for those not ready to migrate to shared, but still want to use normal global variables with no effect on their types.

> > Yes, two flavors of pureness can be introduces, it should be documented, what optimizations can be applied to them in relation to threading model. But isn't it a lot of work to specify and implement two flavors of pureness at the same time?
> No, because you can get it trivially from the function signature.

You meant, from the argument list? It doesn't really matter, whether the parameter is const or immutable, matters only actual constness, so if caller passes immutable argument as const to a pure function, it's the same as if parameter was declared immutable, so the level of purity actually depends on what arguments are passed to the function and thus changes from call to call as caller passes arguments with different constness. So it's actually the caller who decides pureness of the call and how to optimize it, the good news is caller knows the constness of perameters it passes. Immutability may be required only when callee wants to do immutable optimizations and call immutable methods.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 09, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3356


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


--- Comment #12 from Don <clugdbug@yahoo.com.au> 2010-11-08 19:10:03 PST ---
With the relaxed purity rules in DMD2.050, the compiler now internally distinguishes const pure functions (which was the old meaning of pure) from immutably pure functions (this issue) and also allows weakly pure.

I don't know whether to mark this as FIXED or WONTFIX.
But since the compiler internally keeps track of immutability pure, I'm marking
as FIXED.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
1 2
Next ›   Last »