DIP30, delegates more destruction for your pleasure

Maxim Fomin maxim at maxim-fomin.ru
Wed Mar 13 11:54:28 PDT 2013


On Wednesday, 13 March 2013 at 18:00:54 UTC, deadalnix wrote:
> http://wiki.dlang.org/DIP30
>
> As usual, go for simplicity, reduce the number of entity the
> language define.
>
> Feel free to destroy.

 From "Fully typed delegates": "Delegate's context is assumed to 
be of type void*. However, it can be specified as a type after 
the parameter list ".

This does not look like the best idea: 1) context pointer may 
point to function frame with several different objects, 2) there 
are no evidences in th DIP about which problems are solved by 
ability to append explicit type of context pointer.

 From " UFCS as delegates": example with function foo(ref uint a) 
raises concern about ABI implementation. Currently context 
pointer is passed through RDI and arguments are passed 
differently. There would be a problem with functions like foo() 
which do not know from where to take an argument - are they 
called directly or like a closure?

Frankly, I see this simpler: delegate = function pointer + data 
pointer, so they should follow language rules (especially 
regarding qualifiers).

Currently this works:

struct S
{
     immutable int i;
     void bar() {}
     int foo() immutable
     {
         //bar();
         (&bar)();
         return i;
     }
}

I think that delegate call should be treated as a function call 
with extra parameter. If .funcptr is deduced to have qualifier X, 
than delegate call should be permitted only if explicit regular 
function call with X qualifier is permitted in that scope. 
Similar should happen with .ptr.


More information about the Digitalmars-d mailing list