comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Controlled types and exception safety
Date: Wed, 7 Dec 2005 18:50:14 -0600
Date: 2005-12-07T18:50:14-06:00	[thread overview]
Message-ID: <Av2dnWucM4bfHwreRVn-gQ@megapath.net> (raw)
In-Reply-To: ekrlf.267$Tg2.247@newsread1.news.pas.earthlink.net

"Jeffrey R. Carter" <spam@spam.com> wrote in message
news:ekrlf.267$Tg2.247@newsread1.news.pas.earthlink.net...
> Randy Brukardt wrote:
> >
> > For an another explanation of this, see ARM 7.6(17.a-17.h).
> > http://www.adaic.com/standards/95aarm/html/AA-A-5-3.html
>
> Is it meaningful that you reference 7.6 and provide the URL of 5.3?

No, cut-and-paste error.

> > The other issues are solveable, but this one is not.
>
> This still doesn't seem like a problem to me. Suppose R is a discriminated
> record with default:
>
> type R (D : D_Type := D_Type'First) is record
>     ...
> end record;
>
> and we want to write Assign:
>
> procedure Assign (To : in out R; From : in R);

That's not the problem. The problem is with the components of R, if they
also have user-defined assignment.

These user-defined assignments have to compose (otherwise, you'd be breaking
the invariants of the component types - remember, these components are
likely private types, and you might not have any idea how they're
implemented). So, you have to be able to *automatically* do the right thing
for each component. (This, BTW, is why Ada insists that an exception in one
Adjust routine be delayed until all other Adjusts have completed -- we don't
want a failure in one abstraction to destroy another, unrelated one.)

Say you have an assignment for type R as described above, and a function F
returning an object of type R. And you have type S defined as:

type S (D : Boolean := False) is record
    case D is
        when False => null;
        when True => C : R;
    end case;
end record;

O : S; -- D = False here.

O := (D => True, C => F);

Now, how is this assignment performed if we're using the default assignment
here? Since we need to component, we need to call the Assign procedure on
the component C, but what left-hand side to pass as To? There isn't a
component O.C in the left-hand side!

Now, you could try to (a) require this also have a user-defined Assign [but
that's very unfriendly and error-prone] or (b) ban components that have
user-defined assignment from being discriminant dependent [but this would be
a big contract model problem - or, a lot of things that are currently done
in generic bodies could no longer be. For instance, if R was a generic
private type, the above type S would have to be illegal in a generic body -
not matter what the actual type of R is.]

So there is no solution in the framework of Ada. To solve the problem, you'd
have to get rid of discriminants and discriminant-dependent components --
and that's not an option for Ada.

...
> Maybe I'm still missing something. Anyway, I never thought user-defined
> assignment was a real need. Limited types and Assign procedures seem
adequate to
> me. What Ada 83 really lacked was finalization. While I'm glad Ada 95 has
it, I
> think I'd prefer
>
> for R'Finalize use ...;

Maybe Ada 200Y limited types and Assign procedures would be adequate, but
certainly not the Ada 95 variety. Ada 95 limited types don't allow (1)
aggregates; (2) constants; (3) useful functions; or (4) any sort of complex
initialization. Which means that you can't use many of the techniques that
help reduce bugs in Ada (such as letting the compiler check that all
components have been given in an aggregate). And limited types also block
most optimizations by their very nature. That's useful in some cases, but in
others you'd rather let the compiler eliminate extra temporaries and
Finalizes. (That's allowed for non-limited types, but never for limited
types.)

                           Randy.







  reply	other threads:[~2005-12-08  0:50 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-30 13:57 Controlled types and exception safety Maciej Sobczak
2005-11-30 15:06 ` Dmitry A. Kazakov
2005-11-30 16:19   ` Maciej Sobczak
2005-12-01  0:05     ` Stephen Leake
2005-12-01  9:21     ` Dmitry A. Kazakov
2005-12-01 10:46       ` Maciej Sobczak
2005-12-01 15:08         ` Dmitry A. Kazakov
2005-12-02  4:17           ` Randy Brukardt
2005-12-02  9:29             ` Maciej Sobczak
2005-12-02 18:12               ` tmoran
2005-12-02 19:15                 ` Robert A Duff
2005-12-02 21:42                   ` tmoran
2005-12-06  9:00                     ` Maciej Sobczak
2005-12-06  9:50                       ` Dmitry A. Kazakov
2005-12-06 18:34                         ` Jeffrey R. Carter
2005-12-06 19:34                           ` Randy Brukardt
2005-12-06 21:20                             ` Dmitry A. Kazakov
2005-12-07  1:57                             ` Jeffrey R. Carter
2005-12-08  0:50                               ` Randy Brukardt [this message]
2005-12-08 19:37                                 ` Jeffrey R. Carter
2005-12-09  2:36                                   ` Randy Brukardt
2005-12-09  6:33                                     ` Jeffrey R. Carter
2005-12-09 20:35                                       ` Randy Brukardt
2005-12-10  7:53                                         ` Jeffrey R. Carter
2005-12-06 20:43                           ` Dmitry A. Kazakov
2005-12-07  2:00                             ` Jeffrey R. Carter
2005-12-07 10:01                               ` Dmitry A. Kazakov
2005-12-02 23:21             ` Robert A Duff
2005-11-30 17:46 ` Jean-Pierre Rosen
2005-11-30 21:02 ` Jeffrey R. Carter
2005-11-30 22:06   ` Björn Persson
2005-11-30 23:52     ` Randy Brukardt
2005-12-01  5:26     ` Jeffrey R. Carter
2005-12-02 23:51       ` Robert A Duff
2005-12-06 11:41   ` Peter C. Chapin
2005-12-06 12:50     ` Jean-Pierre Rosen
2005-12-06 13:06     ` Dmitry A. Kazakov
replies disabled

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