comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Controlled types as interfaces
Date: Fri, 29 Aug 2014 18:54:24 -0500
Date: 2014-08-29T18:54:24-05:00	[thread overview]
Message-ID: <ltr3rh$kkc$1@loke.gir.dk> (raw)
In-Reply-To: wcc4mwv731x.fsf@shell01.TheWorld.com

"Robert A Duff" <bobduff@shell01.TheWorld.com> wrote in message 
news:wcc4mwv731x.fsf@shell01.TheWorld.com...
> "Randy Brukardt" <randy@rrsoftware.com> writes:
...
>> Note that in the OP's example, Janus/Ada does NOT treat the enclosing 
>> record
>> as controlled; each individual controlled object (including components) 
>> is
>> managed separately. I did it that way to make unwinding an object in the
>> face of exceptions during construction easier (each object is registered 
>> as
>> it is constructed, so all successfully constructed objects get finalized 
>> and
>> none that failed get finalized). GNAT, OTOH, does treat each object
>                                                   ^ not
>> individibly and has to go through some handstands so that objects that
>> aren't constructed aren't finalized.
>
> I think you're missing a "not" there.

I don't think so, but I don't claim to understand what GNAT does that well.

> Yes, there are some "handstands",
> but it's not so bad.  I think the only reason it was so hard to
> implement is that it was a re-implementation.  Doing it that way from
> the start would not have been so bad (as is often the case).
>
> The compiler generates a "deep_initialize" procedure for each type,
> which either fully initializes everything, or else finalizes the parts
> that got initialized before an exception.

Initialize routines like that are fiendishly complex (we do initializes that 
way), especially because the combination of discriminant dependent 
components and recursion to handle subcomponents. Trying to include 
finalization in there would have caused madness, at a minimum when something 
goes wrong. (They're literally impossible to debug, and I always find 
something else to do rather than work on those routines. Sorry, Tero. :-)

Also, doing that requires that every call and check be effectively wrapped 
with an exception handler since one has to know the exact point of failure. 
For checks, that's not too bad as the check could be replaced by a branch. 
But for calls, that can be expensive depending on the exception handling 
scheme. (It's probably tractable for GNAT because of the zero-cost exception 
handling, although that is clearly an additional source of complexity; for 
Janus which uses a registration scheme, the cost would be way too expensive 
to use regularly.)

As always with compiler construction, YMMV.

                                           Randy.


  reply	other threads:[~2014-08-29 23:54 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-20  1:05 Controlled types as interfaces Victor Porton
2014-08-20  1:09 ` Victor Porton
2014-08-20  7:29   ` Dmitry A. Kazakov
2014-08-20 12:49     ` Victor Porton
2014-08-20 13:47       ` Dmitry A. Kazakov
2014-08-21 23:16         ` Randy Brukardt
2014-08-29 15:01           ` Robert A Duff
2014-08-29 23:54             ` Randy Brukardt [this message]
2014-08-20 12:50     ` Victor Porton
2014-08-20 13:38       ` Dmitry A. Kazakov
2014-08-20 13:56       ` Brad Moore
2014-08-21 22:48         ` Randy Brukardt
2014-08-20  1:41 ` Victor Porton
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox