comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Proposal: Auto-allocation of Indefinite Objects
Date: Tue, 28 Jul 2020 16:59:09 +0200	[thread overview]
Message-ID: <rfpefq$17fm$1@gioia.aioe.org> (raw)
In-Reply-To: rfpcn4$2n6$1@dont-email.me

On 28/07/2020 16:28, Brian Drummond wrote:
> On Mon, 27 Jul 2020 22:02:57 +0200, Dmitry A. Kazakov wrote:
> 
>> On 27/07/2020 19:48, Brian Drummond wrote:
>>
>>> 2) can be implemented internally using pointers, but externally appears
>>> to be a data object, just like Unbounded_String does, with similar
>>> semantics.
>>
>> No, the point is that Unbounded_String is exactly opposite to what is
>> required. In no case it should appear as an object of a different type!
>>
>> Compare access to string P with unbounded string U:
>>
>>      for I in P'Range loop -- This is OK
>>         P(J) := 'a' -- This is OK
>>
>> Now would you do:
>>
>>      To_String (U) (J) := 'a' -- Garbage!
> 
> That wasn't the aspect of Unbounded I was getting at. I agree ... garbage.
> 
> What I meant was that Unbounded doesn't load New, dereferencing,
> deallocation etc onto the programmer, but hides the access details, and
> our indefinite type should do the same (the compiler can probably to a
> better job than the programmer anyway).
> 
> I'm suggesting something more like the C++ reference, signalling (perhaps
> by adding a reserved word "indefinite") that fixed size allocation won't
> work;

Equivalent of C++ reference in Ada is renaming.

  and implementation is more in line with a controlled type but with
> system-provided Initialise,Adjust,Finalize providing the required
> operations (no need for the programmer to provide them).
> 
> A : String := "hello" -- a definite string
> P : access String := new String'("hello");
> Q : indefinite String := "hello";

I think the keyword is misleading. Maybe this:

    Q : new String := "hello";

And I don't like initialization. It was a mistake to have limited 
return. The syntax must stress that all initialization is strictly 
in-place. No copies involved because the pool is fixed.

> ...
>     begin
>       for I in P'Range loop -- This is OK
>          P(J) := 'a'; -- This is OK
>          Q(J) := 'a'; -- also OK. But index out of range would raise
> Constraint Error
> ...
>       Q := "hello_world"; -- deallocates, allocates with new bounds
> ...
>     end;    -- deallocate Q here.

The rule could be "same pool" as of the container. In the case of a 
block, the pool is the stack. In the case of a record member, the pool 
is the pool of where the record itself is allocated. So that you could 
allocate all object in the same pool.

> It follows that "indefinite" cannot also be "aliased" unless we want to
> implement smart pointers. For simplicity I'd suggest disallowing "aliased
> indefinite" on the grounds that "access" can (should) be used instead.

It makes sense, but there are use cases for having it aliased:

    X : indefinite T;
    Y : indefinite S (X'Access); -- Access discriminant

> Records (including tagged, class wide, discriminated) should work the
> same, but probably with shallow copy on assignment if they contain access
> types.
> 
> If there is no re-allocation (no different size assignment) the compiler
> is free to substitute direct (stack) storage instead of heap allocation
> and implicit access types. So for example instead of
>     
>     A constant String := "done";
>   ...
>     loop
>        declare
>           P : String := Get_Line;
>        begin
>           exit when P = A;
>        end;
>     end loop;
> 
>     A constant String := "done";
>     Q : indefinite String;
>   ...
>     loop
>        Q := Get_Line;
>        exit when Q = A;
>     end loop;

I am not comfortable with the semantics of this and with possible 
implications too. I would keep it simple.

> the implementation can be either an implicit declare block or an implicit
> access type. However, where Q has several reassignments within a block,
> and the compiler can't determine the size, an implicit access type must
> be used. (If it can, it can warn that "indefinite " is unnecessary).
> 
>> What if the original object must be a class-wide object, task, protected
>> object, limited object etc?
>>
>> Ada's access types delegate all operations to the target object, except
>> assignment. This is the key property that the proposal in my view must
>> retain.
> 
> Indefinite can also be applied to records (discriminated, class wide, etc)
> here the size is indeterminate and may vary on reassignment. Assignment
> would always be shallow copy (where the record contained access types).

That would be inconsistent. IMO, it should be a deep copy, provided such 
a component would not make the type limited, of which I am not sure.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

  reply	other threads:[~2020-07-28 14:59 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-03 22:48 Proposal: Auto-allocation of Indefinite Objects Stephen Davies
2020-04-03 23:45 ` Stephen Leake
2020-04-04 10:54   ` Jeffrey R. Carter
2020-04-04 20:55     ` Stephen Davies
2020-04-04  8:31 ` Dmitry A. Kazakov
2020-07-27  7:47 ` Yannick Moy
2020-07-27  9:21   ` J-P. Rosen
2020-07-27  9:49     ` Dmitry A. Kazakov
2020-07-27 17:48   ` Brian Drummond
2020-07-27 20:02     ` Dmitry A. Kazakov
2020-07-28 14:28       ` Brian Drummond
2020-07-28 14:59         ` Dmitry A. Kazakov [this message]
2020-07-29 15:33           ` Brian Drummond
2020-07-29 16:20             ` Dmitry A. Kazakov
2020-07-30 13:37               ` Stephen Davies
2020-07-30 14:23                 ` Dmitry A. Kazakov
2020-07-30 17:04               ` Brian Drummond
2020-07-30 18:28                 ` Dmitry A. Kazakov
2020-08-10  0:39                   ` Randy Brukardt
2020-08-10  8:57                     ` Dmitry A. Kazakov
2020-08-20  0:10                       ` Randy Brukardt
2020-08-20 17:49                         ` Dmitry A. Kazakov
2020-08-20 20:19                           ` Dennis Lee Bieber
2020-08-20 23:33                             ` Randy Brukardt
2020-08-21  6:45                               ` Dmitry A. Kazakov
2020-08-23  4:52                                 ` Randy Brukardt
2020-08-23 12:28                                   ` Dmitry A. Kazakov
2020-08-20 23:30                           ` Randy Brukardt
2020-08-21  6:46                             ` Dmitry A. Kazakov
2020-08-23  4:48                               ` Randy Brukardt
2020-08-23 12:29                                 ` Dmitry A. Kazakov
2020-08-10  0:31               ` Randy Brukardt
2020-08-10  8:58                 ` Dmitry A. Kazakov
2020-08-20  0:13                   ` Randy Brukardt
2020-08-20 17:49                     ` Dmitry A. Kazakov
2020-08-20 23:25                       ` Randy Brukardt
2020-08-21  7:08                         ` Dmitry A. Kazakov
2020-08-23  5:03                           ` Randy Brukardt
2020-08-23 12:28                             ` Dmitry A. Kazakov
2020-07-27 20:31     ` Jeffrey R. Carter
2020-07-31  9:25 ` Stephen Davies
2020-07-31 10:20   ` Dmitry A. Kazakov
2020-08-01 11:22     ` Stephen Davies
2020-08-01 12:58       ` Dmitry A. Kazakov
2020-08-01 20:35         ` Stephen Davies
2020-08-01 20:56           ` Dmitry A. Kazakov
2020-09-03  4:30 ` linda white
replies disabled

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