simple ABI change to enable implicit conversion of functions to delegates?

kinke via Digitalmars-d digitalmars-d at puremagic.com
Mon May 15 11:50:43 PDT 2017


On Monday, 15 May 2017 at 17:03:20 UTC, ag0aep6g wrote:
> On 05/15/2017 02:27 PM, kinke wrote:
>> Some additional context: https://github.com/dlang/dmd/pull/5232
>
> What I take from that is that changing the way arguments are 
> passed (particularly if they're reversed or not) is going to 
> break a ton of stuff.

Well, when I experimentally didn't reverse the args for extern(D) 
back then for LDC (after patching druntime/Phobos inline asm 
accordingly...), that single issue prevented a fully green 
testsuite.
The problem is that druntime there goes the other way and invokes 
a method via a function pointer, so in essence the inverse of 
what you're after.

The problem there is that this/context may be passed differently 
on Win64; I checked, and LDC only does it for `extern(C++)` for 
Visual C++ compatibility, not for extern(D), so OTOH the 
(absolutely unintuitive) resulting arguments order for Win64 
should currently be:

extern(C++) BigStruct freeFunC(Object this, int b, int c)
   => __sret, this, b, c
extern(D)   BigStruct freeFunD(Object this, int b, int c)
   => __sret, c, b, this
extern(C++) BigStruct Object.funC(int b, int c)
   => __this, __sret, b, c
extern(D)   BigStruct Object.funD(int b, int c)
   => __sret, __this, c, b

And yes, for Win32 there's the __thiscall convention, but also 
only for extern(C++).

> `extern(C++)` functions/delegates have to follow it, obviously. 
> But then we can just say that implicit conversion doesn't work 
> with those.

Doesn't sound that bad as long as the front-end enforces it.


More information about the Digitalmars-d mailing list