[Issue 3356] New: Make pure functions require immutable parameters

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Oct 1 07:39:30 PDT 2009


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

           Summary: Make pure functions require immutable parameters
           Product: D
           Version: future
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: dfj1esp02 at sneakemail.com


--- Comment #0 from Sobirari Muhomori <dfj1esp02 at sneakemail.com> 2009-10-01 07:39:29 PDT ---
Illustration:
---
int foo(const int[] bar) pure
{
    return bar[1];
}

void goo()
{
    int[2] a;
    a[1]=1;
    foo(a);
    a[1]=2;
    foo(a);
}
---

1. This doesn't affect functions with value type parameters.
2. When a function takes a reference type parameter, the chanses are slim, that
the return value doesn't depend on the referenced data. So the referenced data
must be immutable.
3. This doesn't require complex flow analysis, only a formal function signature
check.
4. (??) Replace immutability of explicit pointer type with constness, since
even if the referenced data is immutable, the code doesn't know, where the
immutable data ends and can access subsequent possibly mutating data. This will
instantly make any function, taking a pointer, impure. This should not apply to
objects and byref data.

-- 
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