[Dlang-study] [lifetime] Few root decisions to take on RC classes

Jakob Bornecrantz wallbraker at gmail.com
Mon Nov 2 12:43:50 PST 2015


On Saturday, 31 October 2015 at 10:19:12 UTC, Jonathan M Davis 
wrote:
> On Saturday, October 31, 2015 03:10:41 Jakob Bornecrantz wrote:
>> On Friday, 30 October 2015 at 21:31:56 UTC, Andrei 
>> Alexandrescu wrote:
>> > A few matters Walter and I just discussed and wanted to 
>> > submit for scrutiny:
>> >
>> > * @rc classes shall not be single-rooted. Rationale: there 
>> > is no strong advantage in it and it would force all @rc 
>> > classes to embed a vptr. This has been already discussed and 
>> > largely agreed upon in this group.
>>
>> Have you done any investigation how this effects exception
>> handling and
>> dynamic upcasts?
>
> Why would the existence (or lack thereof) of a root object 
> affect either exceptions or casting?
>
> Unless Throwable becomes an @rc class (which might be a good 
> idea), exceptions won't be affected by @rc. And if Throwable 
> does become an @rc class, then Throwable would be the root of 
> all exception classes, and the lack of a general @rc class root 
> would be irrelevant. As it is, exceptions aren't treated as 
> Objects under normal circumstances. The closest that they get 
> to to that would be when they're treated as an Exception or 
> Throwable.
>
> The same goes with casting. Having a root object is irrelevant 
> to casting. As long as the class reference that you're casting 
> refers to an object whose type is either the target type or a 
> type derived from the target type, then the cast will succeed. 
> And if it doesn't, the result will be null. I don't see how the 
> existence of a root object would affect that.
>
> Remember that C++ doesn't have a root object, and exceptions 
> and casting work just fine there.

Correct, but vtable will effect it. Casts on classes in D
are dynamic by default unless they are downcasts.

In C++ dynamic_cast wont work on classes that doesn't
have a vtables, see example http://vp.dav1d.de/5ZOm?cpp I had
to check for myself since it was a long time I programmed
in C++ thanks to D. :)

I think just slapping @rc on Throwable will probably break code
that is out there in the wild.

Cheers, Jakob.



More information about the Dlang-study mailing list