RFC: reference counted Throwable

via Digitalmars-d digitalmars-d at puremagic.com
Sat Sep 20 02:16:59 PDT 2014


On Saturday, 20 September 2014 at 09:05:24 UTC, Marc Schütz wrote:
> On Saturday, 20 September 2014 at 08:32:55 UTC, Dicebot wrote:
>> On Saturday, 20 September 2014 at 08:20:47 UTC, Marc Schütz 
>> wrote:
>>> I don't think ARC is needed.
>>>
>>> library RC + borrowing + uniqueness/moving = WIN
>>
>> You can't do polymorphic entity RC (like exceptions) without 
>> at least some help from compiler because language currently 
>> does not provide tools for lifetime control of classes. At 
>> least _some_ form of ARC is necessary.
>
> I think we can, using templated alias this. We're not there 
> yet, but it's probably feasable, seeing that Igor Stepanov 
> already implemented multiple alias this [1]. With that and 
> maybe a little opDispatch magic, it should be possible to 
> making wrappers that are implicitly convertible to wrappers of 
> parents of their inner types.
>
> Granted, for exceptions there's more needed: There needs to be 
> support for throwing and catching these wrappers, and for 
> catching wrappers of derived types, too. But note that 
> throw/catch itself doesn't involve copying, it's a moving 
> operation, which might make it easier.
>
> [1] https://github.com/D-Programming-Language/dmd/pull/3998

Thinking further about it, we don't need templated `alias this`, 
because we can just have one `alias this` that returns 
`scope!this(T)` (this needs to be there anyway to be safe). It 
would automatically behave like a normal class with regard to 
polymorphy.

What's still needed then is a little magic to actually be able to 
throw and catch the wrapper.


More information about the Digitalmars-d mailing list