www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3909] New: toDelegate handles only a tiny subset of function pointer types

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3909

           Summary: toDelegate handles only a tiny subset of function
                    pointer types
           Product: D
           Version: 2.041
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: samukha voliacable.com


--- Comment #0 from Max Samukha <samukha voliacable.com> 2010-03-08 23:33:42
PST ---
Current implementation of toDelegate requires parameter and return types of the
argument to be accessible from std.functional, meaning that it won't accept
most of function pointers taking or returning instances of UDTs:

----
import std.functional;

struct S
{
}

void foo(S s)
{
}

void main()
{
    auto dg = &toDelegate(&foo);
}

Error: identifier 'S' is not defined
----

The cause is the mixed-in delegate type generated from the function pointer
type's stringof, which is invalid in the context of the template declaration.
A workaround is to avoid the stringof like this:

alias ParameterTypeTuple!(F) Params;
// mixed-in string:
alias <storage classes> ReturnType!(F) delegate(<storage classes> Params[0],
... <storage classes> Params[$ - 1]) Dg;

where <storage classes> are extracted from F's stringof (isRef, isOut, isLazy
may work too)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 08 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3909



--- Comment #1 from Max Samukha <samukha voliacable.com> 2010-03-09 00:01:42
PST ---
In the test case,

auto dg = &toDelegate(&foo);

should be

auto dg = toDelegate(&foo);

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 09 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3909


David Simcha <dsimcha yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dsimcha yahoo.com
         Depends on|                            |1818


--- Comment #2 from David Simcha <dsimcha yahoo.com> 2010-05-25 06:29:49 PDT ---
I just noticed this report now.  Really, the reason this code is so poorly
designed (I wrote it, and I'll admit in hindsight that it does suck) is bug
1818.  The stupid mixin hack was a last-minute workaround for this bug and
wasn't thought through properly.  This is noted in the comments:

functional.d around line 550:

    // Workaround for DMD Bug 1818.
    mixin("alias " ~ ReturnType!(F).stringof ~
        " delegate" ~ ParameterTypeTuple!(F).stringof ~ " DelType;");

    version(none) {
        // What the code would be if it weren't for bug 1818:
        alias ReturnType!(F) delegate(ParameterTypeTuple!(F)) DelType;
    }

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 25 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3909



--- Comment #3 from Max Samukha <samukha voliacable.com> 2010-05-25 08:12:12
PDT ---
(In reply to comment #2)
 I just noticed this report now.  Really, the reason this code is so poorly
 designed (I wrote it, and I'll admit in hindsight that it does suck) is bug
 1818.  The stupid mixin hack was a last-minute workaround for this bug and
 wasn't thought through properly.  This is noted in the comments:
 
 functional.d around line 550:
 
     // Workaround for DMD Bug 1818.
     mixin("alias " ~ ReturnType!(F).stringof ~
         " delegate" ~ ParameterTypeTuple!(F).stringof ~ " DelType;");
 
     version(none) {
         // What the code would be if it weren't for bug 1818:
         alias ReturnType!(F) delegate(ParameterTypeTuple!(F)) DelType;
     }
Phobos has recently acquired functionality for extracting storage classes from functions and function parameters. I haven't given it a close look but it seems to do that by parsing mangled names. Hacky but should make it possible to correctly generate function types based on other function types. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
May 25 2010
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3909


Shin Fujishiro <rsinfu gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|rsinfu gmail.com            |nobody puremagic.com


--- Comment #4 from Shin Fujishiro <rsinfu gmail.com> 2010-05-27 22:12:09 PDT
---
I commited a hacky workaround in svn r1561.  Now it works with user-defined
types and function attributes (such as pure).  But I leave this bug opened
becuase the bug is not completely fixed.

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