[Issue 5750] New: Allow pure functions to have lazy arguments

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Mar 18 17:37:36 PDT 2011


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

           Summary: Allow pure functions to have lazy arguments
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: clugdbug at yahoo.com.au


--- Comment #0 from Don <clugdbug at yahoo.com.au> 2011-03-18 17:34:21 PDT ---
Any function marked as pure, which has a lazy parameter, should be considered
to be weakly pure. Since a lazy parameter is a delegate, there are no limits on
what it can potentially do, so the purity of the function will depend entirely
on the purity of the lazy parameter.

Secondly, when using a lazy parameter, it should be assumed to be adequately
pure, since it was checked when it was constructed.


PATCH:
mtype.c, line 5042, void TypeFunction::purityLevel()

            size_t dim = Parameter::dim(tf->parameters);
            for (size_t i = 0; i < dim; i++)
            {   Parameter *fparam = Parameter::getNth(tf->parameters, i);
                if (fparam->storageClass & STClazy)
                {
-                    /* We could possibly allow this by doing further analysis
on the
-                     * lazy parameter to see if it's pure.
-                     */
-                    error(0, "cannot have lazy parameters to a pure
function");
+                    tf->purity = PUREweak;
+                    break;
                }
                if (fparam->storageClass & STCout)

expression.c, line 7155, CallExp::semantic()
----
            if (sc->func && sc->func->isPure() && !tf->purity)
            {
+                if (e1->op == TOKvar && ((VarExp *)e1)->var->storage_class &
STClazy)
+                {   // lazy paramaters can be called without violating purity
+                    // since they are checked explicitly
+                }
+                else
                error("pure function '%s' cannot call impure delegate '%s'",
sc->func->toChars(), e1->toChars());
            }
            if (sc->func && sc->func->isSafe() && tf->trust <= TRUSTsystem)
            {
                error("safe function '%s' cannot call system delegate '%s'",
sc->func->toChars(), e1->toChars());
            }

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