Use C++ exception model in D

Iain Buclaw ibuclaw at gdcproject.org
Tue Apr 8 15:18:50 PDT 2014


On 8 April 2014 20:56, David Nadlinger <code at klickverbot.at> wrote:
> On Tuesday, 8 April 2014 at 18:55:35 UTC, Brad Roberts wrote:
>>
>> I think, for a mixed language application, that the important part is
>> proper object lifetime management more than being able to catch exceptions
>> from different languages.  When unwinding a c++ exception that has stack
>> frames intermixed with D, destructors need to be executed appropriately, and
>> vice versa.
>
>
> I haven't actually tried to do this, but in theory, this should be the easy
> part with libunwind. You just ignore foreign exceptions during the search
> phase (i.e. not catch them), and during the unwind phase, your own
> personality function is called again for cleanup regardless of the handler
> the stack actually unwinds to.
>
>
>> This is also an important part of having abi compatibility between D
>> compilers, something which we don't have today but really must have
>> eventually.. hopefully not years away.
>
>
> This really depends on somebody familiar with the DMD backend committing to
> going through with it. I think both on the GDC and LDC sides, there is
> agreement that we need to work on a common ABI. However, the whole thing
> would be somewhat of a futile effort without DMD on board as well.
>

Worse, there's even work that is complete for GDC that is critical for
ARM support, but breaks ABI - in a positive way that means all targets
behave as expected.  However DMD is impeding progress of this work.

The work I'm doing on GDB is somewhat similar in this regards in that
what I initially thought would be a walk in the park for GDC turned
out to be an almost re-think/write of the situation.  How you emit
modules (we didn't), how you emit imported modules, selective imports,
renamed imports, enums, methods, vtable layouts in debug, classifying
structs, locations, locations, locations, special cases for _Dmain,
symbol scope lookup hierachy, function overloading...  Most of which
DMD programs may not see all benefits of because they emit debug info
as if is C.


> On x86_64, ABI compatibility is not an unreasonable goal at all (and a very
> important one, in my opinion). There are some areas that will need a lot of
> careful spec'ing and likely entail changes in all three compilers, such as
> the construction of nested scopes. However, in some cases, e.g. exception
> unwinding, or proper variadic arguments, it's definitely the case that GDC
> and LDC would be easy to align, whereas DMD would have to give up its own
> bespoke solution. Does DMD still do things like magically accessing the
> scope of the parent function in in/out contract calls?
>

That magic is still there as I recall that the hacks for GDC custom
static chains are still in place.

Regards
Iain


More information about the Digitalmars-d mailing list