[Issue 8185] Pure functions and pointers

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Jun 3 06:26:17 PDT 2012


http://d.puremagic.com/issues/show_bug.cgi?id=8185



--- Comment #10 from art.08.09 at gmail.com 2012-06-03 06:28:09 PDT ---
(In reply to comment #7)

> argument value is all the data reachable via the parameters.  Argument result
> is all the data reachable via the result.
[...]
> the optimizer.  My gut feeling is the compiler/optimizer should trust the code
> "knows what it's doing." and so should expect that the code implicitly knows
> how much data it can access after the pointer.

Having "pure" as an user provided attribute, the compiler completely trusting
the programmer and only checking/enforcing certain assumptions when it is easy
to do, is a reasonable solution. Anybody that understands the purity concept
will have no problem determining if some function is "pure" or not, this is how
it is in C, in dialects supporting pure.

Unfortunately, D has purity inference.

   uint f()(immutable ubyte* p) {
      uint r;
      foreach (i; 0..size_t.max)
         r += p[i];
      return r;
   }

Can this still be considered pure?
What about "uint f2()(Struct* p) {/*same body*/}"?
Or

   uint f3()(ubyte* p) {
      uint r;
      foreach (i; 0..size_t.max)
         r += p[i]++;
      return r;
   }

?

All three functions are tagged as pure by the compiler...

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list