Re: Controlled types and exception safety



"Jeffrey R. Carter" <spam@xxxxxxxx> wrote in message
news:xX%lf.800$n1.254@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> Randy Brukardt wrote:
>
> > 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!
>
> I guess I'm still missing something. Default assignment to a record with
> discriminants, or at least that changes the discriminants, invoking
'Assign for
> a component, would assign to an intermediate with the correct
discriminants,
> which is then copied into the target as is currently done.

You're expecting a bitwise copy to work for that? That seems wrong; since
the advantage to your scheme is that you can do operations on the old
left-hand side before the assignment. But if that "old" object is a
temporary, you have no access to it, and you have degraded to the current
scheme. Except that it is worse, because you can't have position-dependent
items.

What I mean by the latter is something that depends on the actual object,
such as 'Access of it. Claw depends on that heavily; Adjust and Finalize
updates or removes the pointers from the various internal lists. That
doesn't work if the LHS isn't the final one (at least one compiler made that
mistake early on in the Ada 95 process).

> Working out the rules is probably complicated, and hardly worth the effort
since
> Ada uses another mechanism, but I'm still not convinced it couldn't be
done.
>
> Probably because IANALL and I'm missing something.

Probably because what you're suggesting would be less useful than Adjust is,
if it had no guarateed access to the LHS *and* it didn't allow self-pointers
and the like.

> > 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.)
>
> I've always felt that preventing the use of aggregates was an important
part of
> limited types.

That seems odd to me; what's the value of preventing aggregates of types
containing components of the limited type? (Preventing aggregates of limited
private types is a feature of private types, not limited types.)

> Constants don't seem like a problem, since they can be
> implemented as functions. You can pass function results to the From
parameter of
> Assign.

Not in Ada 95; you can't write a useful function without standing on your
head. Such a function can only return a global variable, which is ugly at
best and impossible for anything but literal constants.

> Complex default initialization requires some work, but I was able to do
some
> pretty complex default initialization using functions as default initial
values
> in Ada 83. Preventing user-defined initialization seems like an important
part
> of limited types.

Again, you seem to be confusing features that belong to other things
(private types and the <> discriminant) with limited types. You can prevent
user-defined initialization in other ways, so it's not necessary to make
that a feature of limited types.

The *only* thing limited types are about is preventing copying. Limited
objects are supposed to be always built-in place. That's important, because
in order to get that one feature (no copying), it's nasty to get a passel of
other things that you may or may not want. And if you don't want those other
things, you often have to abandon limited types. (The major reason that most
objects are non-limited in Claw is that limited functions aren't useful in
Ada 95.)

We've tried to eliminate unnecessary restrictions on the categories of
types, so that it is possible to pick categories based on their main
properties - with as few surprises as possible.

Randy.




.



Relevant Pages

  • Re: Controlled types and exception safety
    ... Say you have an assignment for type R as described above, ... user-defined assignment from being discriminant dependent [but this would be ... So there is no solution in the framework of Ada. ... Limited types and Assign procedures seem ...
    (comp.lang.ada)
  • Re: ADA Popularity Discussion Request
    ... 1983 - when Ada was not able to redefine assignment ... Limited types prevented it. ... Ada 95 does have a way to redefine assignment, ...
    (comp.lang.ada)
  • Re: Extended return question
    ... Actually, the situation with limited types isn't totally clear, ... Extended_Return_Function on the right-hand side of an assignment, ... he tried to use the function call as an initializer for some object X, ... copies they wish as long as they get the Ada semantics right. ...
    (comp.lang.ada)
  • Re: Cannot initialize entities of limited type?
    ... In Ada95, initialization is considered an assignment, and assignments are prohibited for limited types. ...
    (comp.lang.ada)
  • Re: Controlled types and exception safety
    ... 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? ... Working out the rules is probably complicated, and hardly worth the effort since Ada uses another mechanism, but I'm still not convinced it couldn't be done. ... And limited types also block most optimizations by their very nature. ... Complex default initialization requires some work, but I was able to do some pretty complex default initialization using functions as default initial values in Ada 83. ...
    (comp.lang.ada)