Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

"A verbal contract isn't worth the paper it's printed on." -- Samuel Goldwyn


devel / comp.lang.ada / Re: Assignment access type with discriminants

SubjectAuthor
* Assignment access type with discriminantsDmitry A. Kazakov
+- Re: Assignment access type with discriminantsBjörn Lundin
+* Re: Assignment access type with discriminantsG.B.
|`* Re: Assignment access type with discriminantsDmitry A. Kazakov
| `* Re: Assignment access type with discriminantsAdaMagica
|  `- Re: Assignment access type with discriminantsNiklas Holsti
`* Re: Assignment access type with discriminantsJ-P. Rosen
 `* Re: Assignment access type with discriminantsNiklas Holsti
  +- Re: Assignment access type with discriminantsDmitry A. Kazakov
  `* Re: Assignment access type with discriminantsJ-P. Rosen
   `- Re: Assignment access type with discriminantsRandy Brukardt

1
Assignment access type with discriminants

<tveh6u$ihpu$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9412&group=comp.lang.ada#9412

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From: mailbox@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.ada
Subject: Assignment access type with discriminants
Date: Wed, 22 Mar 2023 10:19:28 +0100
Organization: A noiseless patient Spider
Lines: 35
Message-ID: <tveh6u$ihpu$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 22 Mar 2023 09:19:26 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="c7c1c8477de057a13cc37bfa1f0b0dc2";
logging-data="608062"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+jRSPnQIRypuzXFDDTeIcp2M32Yg8CThY="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.9.0
Cancel-Lock: sha1:r7xEKsRHIW5CQPQEnSEVRdreN78=
Content-Language: en-US
 by: Dmitry A. Kazakov - Wed, 22 Mar 2023 09:19 UTC

I stumbled on a curious fact.

The value of an object with a discriminant can be changed to a value
with a different discriminant if the type's discriminants are defaulted.

Right?

Wrong! Not through an access type!

procedure Test is
type F is (F1, F2, F3);
type Foo (K : F := F1) is record
case K is
when F1 =>
X1 : Integer;
when F2 =>
X2 : Float;
when F3 =>
X3 : String (1..2);
end case;
end record;
type Foo_Ptr is access all Foo;
X : aliased Foo;
P : Foo_Ptr := X'Access;
begin
X := (F2, 1.0); -- OK
P.all := (F1, 3); -- Error!
end Test;

Is this a compiler bug or intentional language design? Any language lawyers?

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

Re: Assignment access type with discriminants

<tvehue$ijrf$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9413&group=comp.lang.ada#9413

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From: bnl@nowhere.com (Björn Lundin)
Newsgroups: comp.lang.ada
Subject: Re: Assignment access type with discriminants
Date: Wed, 22 Mar 2023 10:31:58 +0100
Organization: A noiseless patient Spider
Lines: 24
Message-ID: <tvehue$ijrf$1@dont-email.me>
References: <tveh6u$ihpu$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 22 Mar 2023 09:31:58 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="0018d217993fc5ad95359477c1bfdac3";
logging-data="610159"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18GNBD1T0cPkaWy3WO9jgs0"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.8.0
Cancel-Lock: sha1:bX4FC5oudq8UiaIzthrqm+ZT4Yk=
In-Reply-To: <tveh6u$ihpu$1@dont-email.me>
Content-Language: en-US
 by: Björn Lundin - Wed, 22 Mar 2023 09:31 UTC

On 2023-03-22 10:19, Dmitry A. Kazakov wrote:
> I stumbled on a curious fact.
.....
> Is this a compiler bug or intentional language design? Any language
> lawyers?
>

I get
Execution of ./test terminated by unhandled exception
raised CONSTRAINT_ERROR : test.adb:18 discriminant check failed
Call stack traceback locations:
0x402c33 0x402b27 0x7f335b5cfd8e 0x7f335b5cfe3e 0x402b63 0xfffffffffffffffe

bnl@hp-t510:/usr2$ gnatls -v
GNATLS Pro 22.2 (20220605-103)

Linux 64bit - ubuntu 22.04

So it is (also) present on that platform at least

--
/Björn

Re: Assignment access type with discriminants

<tvf294$ldho$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9414&group=comp.lang.ada#9414

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From: bauhaus@notmyhomepage.invalid (G.B.)
Newsgroups: comp.lang.ada
Subject: Re: Assignment access type with discriminants
Date: Wed, 22 Mar 2023 15:10:44 +0100
Organization: A noiseless patient Spider
Lines: 47
Message-ID: <tvf294$ldho$1@dont-email.me>
References: <tveh6u$ihpu$1@dont-email.me>
Reply-To: nonlegitur@notmyhomepage.de
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 22 Mar 2023 14:10:44 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="7465433de0dc0165a3f058124deedfb9";
logging-data="702008"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+QxNbxeavoBl3XsuT1C21Ix2Enk8pEGLk="
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0)
Gecko/20100101 Thunderbird/102.8.0
Cancel-Lock: sha1:d89ZoZiqHJDpM0Bg2CxybsF05sY=
Content-Language: en-US
In-Reply-To: <tveh6u$ihpu$1@dont-email.me>
 by: G.B. - Wed, 22 Mar 2023 14:10 UTC

On 22.03.23 10:19, Dmitry A. Kazakov wrote:
> I stumbled on a curious fact.
>
> The value of an object with a discriminant can be changed to a value with a different discriminant if the type's discriminants are defaulted.
>
> Right?
>
> Wrong! Not through an access type!
>
> procedure Test is
>    type F is (F1, F2, F3);
>    type Foo (K : F := F1) is record
>       case K is
>          when F1 =>
>             X1 : Integer;
>          when F2 =>
>             X2 : Float;
>          when F3 =>
>             X3 : String (1..2);
>       end case;
>    end record;
>    type Foo_Ptr is access all Foo;
>    X : aliased Foo;
>    P : Foo_Ptr := X'Access;
> begin
>    X := (F2, 1.0);   -- OK
>    P.all := (F1, 3); -- Error!
> end Test;

Some experiments point at the general access type.

type Foo_Ptr is access Foo; -- sans `all`
X : Foo;
P : Foo_Ptr := new Foo;
type Foo1 is new Foo_Ptr (K => F1);
begin
X := (F2, 1.0); -- OK
P.all := (F1, 3); -- _no_ Error!
Foo1 (P).all := (F1, 3);
end Test;

(Doesn't rejection for general access types seem reasonable
if assignment would otherwise require adjusting the storage
layout of a variable, including all access paths to components?
Just guessing.)

Re: Assignment access type with discriminants

<tvhef6$1237n$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9415&group=comp.lang.ada#9415

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From: mailbox@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.ada
Subject: Re: Assignment access type with discriminants
Date: Thu, 23 Mar 2023 12:51:03 +0100
Organization: A noiseless patient Spider
Lines: 33
Message-ID: <tvhef6$1237n$1@dont-email.me>
References: <tveh6u$ihpu$1@dont-email.me> <tvf294$ldho$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 23 Mar 2023 11:51:02 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="8f8a6c7e6deaf14d1d63deb97cbf29ad";
logging-data="1117431"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX187ip1k/dfXkcROaur7XqAw/J84N/iJjCg="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.9.0
Cancel-Lock: sha1:GGkVU1J0eZRY2Ueg/+kIbHDaqlY=
In-Reply-To: <tvf294$ldho$1@dont-email.me>
Content-Language: en-US
 by: Dmitry A. Kazakov - Thu, 23 Mar 2023 11:51 UTC

On 2023-03-22 15:10, G.B. wrote:

> Some experiments point at the general access type.
>
>    type Foo_Ptr is access Foo; -- sans `all`
>    X : Foo;
>    P : Foo_Ptr := new Foo;
>    type Foo1 is new Foo_Ptr (K => F1);
> begin
>    X := (F2, 1.0);   -- OK
>    P.all := (F1, 3); -- _no_ Error!
>    Foo1 (P).all := (F1, 3);
> end Test;

You get no error because you do not change the discriminant. Change your
code to:

P.all := (F2, 1.0); -- Error!

> (Doesn't rejection for general access types seem reasonable
> if assignment would otherwise require adjusting the storage
> layout of a variable, including all access paths to components?
> Just guessing.)

I guess that an implementation must allocate memory for any value unless
you constraint the discriminants in a subtype. But I am not a language
lawyer to judge.

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

Re: Assignment access type with discriminants

<1775482e-fd70-4af8-b25d-c2a9c2892b05n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9416&group=comp.lang.ada#9416

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:ae9:eb88:0:b0:72b:25b4:565a with SMTP id b130-20020ae9eb88000000b0072b25b4565amr1665918qkg.0.1679590404379;
Thu, 23 Mar 2023 09:53:24 -0700 (PDT)
X-Received: by 2002:a05:6902:1105:b0:b2f:bdc9:2cdc with SMTP id
o5-20020a056902110500b00b2fbdc92cdcmr2636199ybu.7.1679590404091; Thu, 23 Mar
2023 09:53:24 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Thu, 23 Mar 2023 09:53:23 -0700 (PDT)
In-Reply-To: <tvhef6$1237n$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=18.197.26.138; posting-account=rmHyLAoAAADSQmMWJF0a_815Fdd96RDf
NNTP-Posting-Host: 18.197.26.138
References: <tveh6u$ihpu$1@dont-email.me> <tvf294$ldho$1@dont-email.me> <tvhef6$1237n$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <1775482e-fd70-4af8-b25d-c2a9c2892b05n@googlegroups.com>
Subject: Re: Assignment access type with discriminants
From: christ-usch.grein@t-online.de (AdaMagica)
Injection-Date: Thu, 23 Mar 2023 16:53:24 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 1636
 by: AdaMagica - Thu, 23 Mar 2023 16:53 UTC

I do hope, this answers the question:

3.10(14/3) … The first subtype of a type defined by … an access_to_object_definition is unconstrained if the designated subtype is an .... discriminated subtype; otherwise, it is constrained.
4.8(6/3) If the designated type is composite, then … the created object is constrained by its initial value (even if the designated subtype is unconstrained with defaults).

Re: Assignment access type with discriminants

<tvi0qt$17pev$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9417&group=comp.lang.ada#9417

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From: rosen@adalog.fr (J-P. Rosen)
Newsgroups: comp.lang.ada
Subject: Re: Assignment access type with discriminants
Date: Thu, 23 Mar 2023 18:04:36 +0100
Organization: Adalog
Lines: 51
Message-ID: <tvi0qt$17pev$1@dont-email.me>
References: <tveh6u$ihpu$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 23 Mar 2023 17:04:29 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="3a2cff23be8de86e9fe5e1bc7e53e790";
logging-data="1304031"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18QEz35KcVdo7tZ7fdHNGYs"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.9.0
Cancel-Lock: sha1:4DgjWTN8wgG7VtyoAI8CNRR0jwY=
Content-Language: en-US, fr
In-Reply-To: <tveh6u$ihpu$1@dont-email.me>
 by: J-P. Rosen - Thu, 23 Mar 2023 17:04 UTC

Le 22/03/2023 à 10:19, Dmitry A. Kazakov a écrit :
> I stumbled on a curious fact.
>
> The value of an object with a discriminant can be changed to a value
> with a different discriminant if the type's discriminants are defaulted.
>
> Right?
>
> Wrong! Not through an access type!
>
(...)
> Is this a compiler bug or intentional language design? Any language
> lawyers?
>
An access value is always constrained by its initial value; this is
necessary because of constrained access subtypes. Here is a slightly
modified version of your example:

procedure Test is
type F is (F1, F2, F3);

type Foo (K : F := F1) is record
case K is
when F1 =>
X1 : Integer;
when F2 =>
X2 : Float;
when F3 =>
X3 : String (1..2);
end case;
end record;
type Foo_Ptr is access all Foo;
type Foo_Ptr2 is access Foo;
X : aliased Foo;
P : Foo_Ptr := X'Access;
PF2: Foo_PTR2 (F2);
begin
X := (F2, 1.0); -- OK
PF2 := new Foo (F2);
P := PF2.all'Access;
P.all := (F1, 3); -- Error!
end Test;

Without this rule, PF2.all would now designate a value whose
discriminant is F1!
--
J-P. Rosen
Adalog
2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX
https://www.adalog.fr https://www.adacontrol.fr

Re: Assignment access type with discriminants

<k83iuhF8ubmU1@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9418&group=comp.lang.ada#9418

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: niklas.holsti@tidorum.invalid (Niklas Holsti)
Newsgroups: comp.lang.ada
Subject: Re: Assignment access type with discriminants
Date: Thu, 23 Mar 2023 20:09:21 +0200
Organization: Tidorum Ltd
Lines: 70
Message-ID: <k83iuhF8ubmU1@mid.individual.net>
References: <tveh6u$ihpu$1@dont-email.me> <tvf294$ldho$1@dont-email.me>
<tvhef6$1237n$1@dont-email.me>
<1775482e-fd70-4af8-b25d-c2a9c2892b05n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: individual.net l1jQtT0ilWjm1UQomRtkIgqTowwV9U+IInrTf8usml9D4oPVAn
Cancel-Lock: sha1:BiJDJlnrrPCq1TuhnPouKflxMFA=
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:102.0)
Gecko/20100101 Thunderbird/102.6.1
Content-Language: en-US
In-Reply-To: <1775482e-fd70-4af8-b25d-c2a9c2892b05n@googlegroups.com>
 by: Niklas Holsti - Thu, 23 Mar 2023 18:09 UTC

On 2023-03-23 18:53, AdaMagica wrote:
> I do hope, this answers the question:
>
> 3.10(14/3) … The first subtype of a type defined by … an
> access_to_object_definition is unconstrained if the designated
> subtype is an ... discriminated subtype; otherwise, it is
> constrained.

What do you infer from this, relating to Dmitry's original example code
and the error? The "first subtype .. defined" here is the access
subtype, and I don't see how that affects an assignment /via/ this
access subtype to the accessed object.

(It is not clear to me how an access subtype that is constrained differs
from one that is unconstrained. Can someone clarify?)

> 4.8(6/3) If the designated type is composite, then … the created
> object is constrained by its initial value (even if the designated
> subtype is unconstrained with defaults).

That rule applies to objects created by allocators, but the original
example code has no allocators (some later variants do). The object in
question is created by a declaration (which includes the "aliased"
keyword), not by an allocator.

Also, AARM 3.10 contains the following notes on "Wording Changes from
Ada 1995":

26.d/2 {AI95-00363-01} Most unconstrained aliased objects with defaulted
discriminants are no longer constrained by their initial values. [...]

26.k/2 {AI95-00363-01} The rules about aliased objects being constrained
by their initial values now apply only to allocated objects, and thus
have been moved to 4.8, “Allocators”.

This seems to mean that aliased objects created by declarations are
/not/ constrained by the initial value, so it should be possible to
change the discriminant. This seems to be a change from Ada 95 to Ada
2005. I don't see why that change could not be done via an access to the
object.

I added some output to Dmitry's original code, with this result:

X'Constrained = FALSE
P'Constrained = TRUE
P.all'Constrained = TRUE

The first two values of 'Constrained (for X and P) are as expected by
the RM rules, and the third value (for P.all) is consistent with the
error, and seems valid for Ada 95, but the wording change quoted above
suggests that it is wrong for Ada 2005 and later. This leads me to
suspect that GNAT has not been fully updated for this RM change, so it
would be a GNAT bug. Still, the addition of

subtype Foo2_Ptr is Foo_Ptr (K => F2);

to Dmitry's original example provokes this error message:

fuf.adb:16:24: access subtype of general access type not allowed
fuf.adb:16:24: discriminants have defaults

which suggests that at least this part of AI95-00363 has been
implemented, as noted in AARM 3.10:

14.b/2 Reason: {AI95-00363-01} [...] Constraints are not allowed on
general access-to-unconstrained discriminated types if the type has
defaults for its discriminants [...]

Re: Assignment access type with discriminants

<k83llkF8ubmU2@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9419&group=comp.lang.ada#9419

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: niklas.holsti@tidorum.invalid (Niklas Holsti)
Newsgroups: comp.lang.ada
Subject: Re: Assignment access type with discriminants
Date: Thu, 23 Mar 2023 20:55:48 +0200
Organization: Tidorum Ltd
Lines: 69
Message-ID: <k83llkF8ubmU2@mid.individual.net>
References: <tveh6u$ihpu$1@dont-email.me> <tvi0qt$17pev$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: individual.net hn1q6ZMj8+vJEM7MlR2evAKW6m5Qp8QvnxDoD/jNIbGLwTj9tU
Cancel-Lock: sha1:mAKwXX5gkVEFpPHzt10jBXRuRCA=
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:102.0)
Gecko/20100101 Thunderbird/102.6.1
Content-Language: en-US
In-Reply-To: <tvi0qt$17pev$1@dont-email.me>
 by: Niklas Holsti - Thu, 23 Mar 2023 18:55 UTC

On 2023-03-23 19:04, J-P. Rosen wrote:
> Le 22/03/2023 à 10:19, Dmitry A. Kazakov a écrit :
>> I stumbled on a curious fact.
>>
>> The value of an object with a discriminant can be changed to a value
>> with a different discriminant if the type's discriminants are defaulted.
>>
>> Right?
>>
>> Wrong! Not through an access type!
>>
> (...)
>> Is this a compiler bug or intentional language design? Any language
>> lawyers?
>>
> An access value is always constrained by its initial value; this is
> necessary because of constrained access subtypes.

But constrained access subtypes are not allowed for general access types
like Foo_Ptr in the example.

> Here is a slightly
> modified version of your example:
>
> procedure Test is
>    type F is (F1, F2, F3);
>
>    type Foo (K : F := F1) is record
>       case K is
>          when F1 =>
>             X1 : Integer;
>          when F2 =>
>             X2 : Float;
>          when F3 =>
>             X3 : String (1..2);
>       end case;
>    end record;
>    type Foo_Ptr is access all Foo;
>    type Foo_Ptr2 is access Foo;
>    X : aliased Foo;
>    P : Foo_Ptr := X'Access;
>    PF2: Foo_PTR2 (F2);
> begin
>    X := (F2, 1.0);   -- OK
>    PF2 := new Foo (F2);
>    P := PF2.all'Access;
>    P.all := (F1, 3); -- Error!
> end Test;
>
> Without this rule, PF2.all would now designate a value whose
> discriminant is F1!

This error is understandable and valid, because now P.all is PF2.all
which is an allocated object and therefore constrained by its initial
value with K = F2.

But why should the same apply when P designates X, which is
unconstrained? Is it just an optimization (in the RM) so that a general
access value does not have to carry around a flag showing whether its
designated object is constrained or unconstrained?

Perhaps it would be better to make the assignment P := PF2.all'Access
illegal, because it in effect converts a constrained access value (PF2)
to an unconstrained access subtype (P), and so in some sense violates
the prohibition of constrained subtypes of general access types.

Re: Assignment access type with discriminants

<tviams$19ejf$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9421&group=comp.lang.ada#9421

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From: mailbox@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.ada
Subject: Re: Assignment access type with discriminants
Date: Thu, 23 Mar 2023 20:53:02 +0100
Organization: A noiseless patient Spider
Lines: 27
Message-ID: <tviams$19ejf$1@dont-email.me>
References: <tveh6u$ihpu$1@dont-email.me> <tvi0qt$17pev$1@dont-email.me>
<k83llkF8ubmU2@mid.individual.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 23 Mar 2023 19:53:00 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="8f8a6c7e6deaf14d1d63deb97cbf29ad";
logging-data="1358447"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+v0D0k7d2QIc17RQwuL9LtP+vkPGnzGrA="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.9.0
Cancel-Lock: sha1:cSbicB8arlwY1k7h+GhN88GwMA8=
In-Reply-To: <k83llkF8ubmU2@mid.individual.net>
Content-Language: en-US
 by: Dmitry A. Kazakov - Thu, 23 Mar 2023 19:53 UTC

On 2023-03-23 19:55, Niklas Holsti wrote:

> Perhaps it would be better to make the assignment P := PF2.all'Access
> illegal, because it in effect converts a constrained access value (PF2)
> to an unconstrained access subtype (P), and so in some sense violates
> the prohibition of constrained subtypes of general access types.

Yes this is substitutability violation. Such cases never go without a
punishment. In this case it is an implementation overhead.

Consider:

procedure Set (Destination : in out Foo; Source : Foo) is
begin
Destination := Source;
end Set;

The compiler cannot implement Set in a natural way, because Destination
might be arbitrarily constrained by the caller. E.g. when the actual for
Destination is P.all. So, the constraint must be passed together with
the actual. A quite burden.

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

Re: Assignment access type with discriminants

<tvjr7l$1js79$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9422&group=comp.lang.ada#9422

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From: rosen@adalog.fr (J-P. Rosen)
Newsgroups: comp.lang.ada
Subject: Re: Assignment access type with discriminants
Date: Fri, 24 Mar 2023 10:41:20 +0100
Organization: Adalog
Lines: 52
Message-ID: <tvjr7l$1js79$1@dont-email.me>
References: <tveh6u$ihpu$1@dont-email.me> <tvi0qt$17pev$1@dont-email.me>
<k83llkF8ubmU2@mid.individual.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 24 Mar 2023 09:41:10 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="31b98b1fe80e6ee8ff82eb92b5260268";
logging-data="1700073"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/WXlXkA+utur8cylyywTHI"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.9.0
Cancel-Lock: sha1:QIjGgYLy3lINWcN6/fQ0oxRyD9E=
In-Reply-To: <k83llkF8ubmU2@mid.individual.net>
Content-Language: en-US, fr
 by: J-P. Rosen - Fri, 24 Mar 2023 09:41 UTC

Le 23/03/2023 à 19:55, Niklas Holsti a écrit :
>
>> Here is a slightly modified version of your example:
>>
>> procedure Test is
>> type F is (F1, F2, F3);
>>
>> type Foo (K : F := F1) is record
>> case K is
>> when F1 =>
>> X1 : Integer;
>> when F2 =>
>> X2 : Float;
>> when F3 =>
>> X3 : String (1..2);
>> end case;
>> end record;
>> type Foo_Ptr is access all Foo;
>> type Foo_Ptr2 is access Foo;
>> X : aliased Foo;
>> P : Foo_Ptr := X'Access;
>> PF2: Foo_PTR2 (F2);
>> begin
>> X := (F2, 1.0); -- OK
>> PF2 := new Foo (F2);
>> P := PF2.all'Access;
>> P.all := (F1, 3); -- Error!
>> end Test;
>>
>> Without this rule, PF2.all would now designate a value whose
>> discriminant is F1!
>
>
> This error is understandable and valid, because now P.all is PF2.all
> which is an allocated object and therefore constrained by its initial
> value with K = F2.
>
> But why should the same apply when P designates X, which is
> unconstrained? Is it just an optimization (in the RM) so that a
> general access value does not have to carry around a flag showing
> whether its designated object is constrained or unconstrained?

I didn't dig in the RM in all details, but I think this comes from the
fact that being constrained (always) is a property of the pointer (more
precisely, its subtype), not of the pointed-at object.

--
J-P. Rosen
Adalog
2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX
https://www.adalog.fr https://www.adacontrol.fr

Re: Assignment access type with discriminants

<tvmcls$24506$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9424&group=comp.lang.ada#9424

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From: randy@rrsoftware.com (Randy Brukardt)
Newsgroups: comp.lang.ada
Subject: Re: Assignment access type with discriminants
Date: Sat, 25 Mar 2023 03:51:07 -0500
Organization: A noiseless patient Spider
Lines: 83
Message-ID: <tvmcls$24506$1@dont-email.me>
References: <tveh6u$ihpu$1@dont-email.me> <tvi0qt$17pev$1@dont-email.me> <k83llkF8ubmU2@mid.individual.net> <tvjr7l$1js79$1@dont-email.me>
Injection-Date: Sat, 25 Mar 2023 08:51:09 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="6687f069bfe0f361727be044aacd443a";
logging-data="2233350"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18l8A37ly62fCYJEOobMvJczuXMxwaG8fs="
Cancel-Lock: sha1:aT54wyXK5u5ygGk5ckoaoTmS04o=
X-MSMail-Priority: Normal
X-RFC2646: Format=Flowed; Response
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.7246
X-Priority: 3
X-Newsreader: Microsoft Outlook Express 6.00.2900.5931
 by: Randy Brukardt - Sat, 25 Mar 2023 08:51 UTC

The rule is question is 4.1(9/3):

If the type of the name in a dereference is some access-to-object type T,
then the dereference denotes a view of an object, the nominal subtype of the
view being the designated subtype of T. If the designated subtype has
unconstrained discriminants, the (actual) subtype of the view is constrained
by the values of the discriminants of the designated object, except when
there is a partial view of the type of the designated subtype that does not
have discriminants, in which case the dereference is not constrained by its
discriminant values.

We have to do that so as otherwise the access value would have to carry a
designation as to whether the object was allocated or not.

-------

This rule was inherited from Ada 83.

IMHO, this rule is stupid. It's even more stupid with the hole for types
that have partial views without discriminants. The *proper* solution is to
get rid of the rarely used and mostly useless access constraints, and then
have no extra restrictions on access values. But that's considered too
incompatible.

Randy.

"J-P. Rosen" <rosen@adalog.fr> wrote in message
news:tvjr7l$1js79$1@dont-email.me...
> Le 23/03/2023 � 19:55, Niklas Holsti a �crit :
> >
> >> Here is a slightly modified version of your example:
> >>
> >> procedure Test is
> >> type F is (F1, F2, F3);
> >>
> >> type Foo (K : F := F1) is record
> >> case K is
> >> when F1 =>
> >> X1 : Integer;
> >> when F2 =>
> >> X2 : Float;
> >> when F3 =>
> >> X3 : String (1..2);
> >> end case;
> >> end record;
> >> type Foo_Ptr is access all Foo;
> >> type Foo_Ptr2 is access Foo;
> >> X : aliased Foo;
> >> P : Foo_Ptr := X'Access;
> >> PF2: Foo_PTR2 (F2);
> >> begin
> >> X := (F2, 1.0); -- OK
> >> PF2 := new Foo (F2);
> >> P := PF2.all'Access;
> >> P.all := (F1, 3); -- Error!
> >> end Test;
> >>
> >> Without this rule, PF2.all would now designate a value whose
> >> discriminant is F1!
> >
> >
> > This error is understandable and valid, because now P.all is PF2.all
> > which is an allocated object and therefore constrained by its initial
> > value with K = F2.
> >
> > But why should the same apply when P designates X, which is
> > unconstrained? Is it just an optimization (in the RM) so that a
> > general access value does not have to carry around a flag showing
> > whether its designated object is constrained or unconstrained?
>
> I didn't dig in the RM in all details, but I think this comes from the
> fact that being constrained (always) is a property of the pointer (more
> precisely, its subtype), not of the pointed-at object.
>
> --
> J-P. Rosen
> Adalog
> 2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX
> https://www.adalog.fr https://www.adacontrol.fr
>


devel / comp.lang.ada / Re: Assignment access type with discriminants

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor