digitalmars.D.bugs - [Issue 8637] New: Enforcement and purity
- d-bugmail puremagic.com (46/46) Sep 10 2012 http://d.puremagic.com/issues/show_bug.cgi?id=8637
- d-bugmail puremagic.com (18/41) Sep 10 2012 http://d.puremagic.com/issues/show_bug.cgi?id=8637
- d-bugmail puremagic.com (7/7) Sep 10 2012 http://d.puremagic.com/issues/show_bug.cgi?id=8637
- d-bugmail puremagic.com (7/9) Sep 10 2012 http://d.puremagic.com/issues/show_bug.cgi?id=8637
- d-bugmail puremagic.com (11/11) Sep 10 2012 http://d.puremagic.com/issues/show_bug.cgi?id=8637
- d-bugmail puremagic.com (13/13) Sep 10 2012 http://d.puremagic.com/issues/show_bug.cgi?id=8637
- d-bugmail puremagic.com (8/12) Sep 10 2012 http://d.puremagic.com/issues/show_bug.cgi?id=8637
- d-bugmail puremagic.com (11/11) Sep 10 2012 http://d.puremagic.com/issues/show_bug.cgi?id=8637
- d-bugmail puremagic.com (9/9) Sep 10 2012 http://d.puremagic.com/issues/show_bug.cgi?id=8637
- d-bugmail puremagic.com (12/12) Sep 11 2012 http://d.puremagic.com/issues/show_bug.cgi?id=8637
http://d.puremagic.com/issues/show_bug.cgi?id=8637
           Summary: Enforcement and purity
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: monarchdodra gmail.com
The argument taken by enforce must be "castable to bool", so the the
implementation can do the cast. However, enforce is declared pure, so if the
cast operator is not pure, the compilation fails:
--------
import std.regex;
import std.exception;
void main()
{
    auto m = match("hello world", regex("world"));
    assert(m); //<- Fine
    enforce(m); //Here
}
--------
Error: pure function 'enforce' cannot call impure function '~this'
Error: pure function 'enforce' cannot call impure function 'opCast'
--------
The messages come from:
--------
T enforce(T)(T value, lazy const(char)[] msg = null, string file = __FILE__,
size_t line = __LINE__)  safe pure
{
    if (!value) bailOut(file, line, msg);
    return value;
}
--------
"if(!value)": This makes an impure call to opCast.
"enforce(T)(T value..." This uses pass by value, and makes an impure call to
the destructor
I have no idea what a good fix would be. Regarding pass by value, wouldn't this
be a textbook example of using "auto ref" with "auto return"? I have no idea...
-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
 Sep 10 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8637
Kenji Hara <k.hara.pg gmail.com> changed:
           What    |Removed                     |Added
----------------------------------------------------------------------------
            Version|unspecified                 |D2
 The argument taken by enforce must be "castable to bool", so the the
 implementation can do the cast. However, enforce is declared pure, so if the
 cast operator is not pure, the compilation fails:
[snip]
 --------
 Error: pure function 'enforce' cannot call impure function '~this'
 Error: pure function 'enforce' cannot call impure function 'opCast'
 --------
The cause might be the explicit annotation with pure.
 The messages come from:
 
 --------
 T enforce(T)(T value, lazy const(char)[] msg = null, string file = __FILE__,
 size_t line = __LINE__)  safe pure
 {
     if (!value) bailOut(file, line, msg);
     return value;
 }
 --------
 "if(!value)": This makes an impure call to opCast.
 
 "enforce(T)(T value..." This uses pass by value, and makes an impure call to
 the destructor
 I have no idea what a good fix would be. Regarding pass by value, wouldn't this
 be a textbook example of using "auto ref" with "auto return"? I have no idea...
https://github.com/D-Programming-Language/phobos/pull/263
As you can see, the pure annotations were just for the documentation. At this
point, impure destructor had not been considered at all in the discussion.
Then, now, the pure annotation causes this problem, so I think we should remove
it and rely on the pure attribute inference.
-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
 Sep 10 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8637 If that is the fix, I can make the pull request. Do you want me to do it, or are you on it? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
 Sep 10 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8637If that is the fix, I can make the pull request. Do you want me to do it, or are you on it?Of course I would welcome your contribution. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
 Sep 10 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8637
monarchdodra gmail.com changed:
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
         AssignedTo|nobody puremagic.com        |monarchdodra gmail.com
Will commit fix myself then.
-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
 Sep 10 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8637
Jonathan M Davis <jmdavisProg gmx.com> changed:
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jmdavisProg gmx.com
PDT ---
Both the annotation for pure and  safe need to go, because T's destructor and
opCast could be impure or non- safe. When the explicit annotations were added,
clearly the destructor and opCast were not taken into account, since they're
not called directly and are easily forgotten.
-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
 Sep 10 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8637Both the annotation for pure and safe need to go, because T's destructor and opCast could be impure or non- safe. When the explicit annotations were added, clearly the destructor and opCast were not taken into account, since they're not called directly and are easily forgotten.Oh, that's right. We should remove both 'pure' and ' safe', and need to depends on fully attribute inference. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
 Sep 10 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8637
Dmitry Olshansky <dmitry.olsh gmail.com> changed:
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dmitry.olsh gmail.com
12:44:17 PDT ---
Sorry, it had regex somewhere in description so I jumped in ;)
https://github.com/D-Programming-Language/phobos/pull/783
-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
 Sep 10 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8637 Darn! Kidding asside, thanks. BTW, I just made touch on std.regex itself. Seems like you may have wanted to know: https://github.com/D-Programming-Language/phobos/pull/784 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
 Sep 10 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8637
monarchdodra gmail.com changed:
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED
Fixed by Dmitry in
https://github.com/D-Programming-Language/phobos/pull/783
-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
 Sep 11 2012








 
  
  
 
 d-bugmail puremagic.com
 d-bugmail puremagic.com 