comp.lang.ada
 help / color / mirror / Atom feed
From: anon@att.net
Subject: Re: A hole in Ada type safety
Date: Wed, 11 May 2011 20:39:47 +0000 (UTC)
Date: 2011-05-11T20:39:47+00:00	[thread overview]
Message-ID: <iqes6i$18g$1@speranza.aioe.org> (raw)
In-Reply-To: 715a5498-095c-4e61-8a09-8510c19b2553@s16g2000prf.googlegroups.com

The RM 13.9 (3) defines the Unchecked_Conversion function with

    pragma Convention ( Intrinsic, Ada.Unchecked_Conversion ) ;

Intrinsic is built-in" and RM C.1 ( 10 ) implies inlining to reduce 
overhead of this function and RM 13.8 ( 15 ) helps reduces the code 
to that of an inline Machine Code Insertions.


Proof basically come from RM 6.3.1 ( 4 ), RM 13.9 ( 15 ) and 
C.1 ( 10 ).

RM 6.3.1 Conformance Rules 
   
    4  "The Intrinsic calling convention represents subprograms that 
       are ``built in'' to the compiler." ...

RM 13.9 Unchecked Type Conversions

  15   The implementation should not generate unnecessary run-time 
       checks to ensure that the representation of S is a 
       representation of the target type. It should take advantage of 
       the permission to return by reference when possible.  
       Restrictions on unchecked conversions should be avoided unless
       required by the target environment.

RM C.1 Access to Machine Operations

  10   "The implementation should ensure that little or no overhead 
       is associated with calling intrinsic and machine-code 
       subprograms"



Associative RMs  

RM 13.8 Machine Code Insertions

  11   "(17) Intrinsic subprograms (see 6.3.1, ``Conformance Rules'') 
       can also be used to achieve machine code insertions." ...

RM C.1 Access to Machine Operations

   6   "The implementation shall document the overhead associated 
        with calling machine-code or intrinsic subprograms, as 
        compared to a fully-inlined call, and to a regular 
        out-of-line call."



Now in Ada 2005, RM 7.5 (1/2) states that a routine can not just copy
a "limited private" object. RM 6.5 (5.1/2, 5.c/2 ) states that if 
the target is limited the function "must produce a ""new"" object" 
instead of just copying the object.

Aka the "Unchecked_Conversion" which is a generic function is no 
longer just an inlined expression that is just a type conversions 
with all checks being disable. The function must now return a "new" 
object RM 6.5 (5.5/2, 5.c/2 ), by first requesting an new object 
from the Target's storage pool and then copying the Source data to 
that new object. So, in Ada 2005 the "Unchecked_Conversion" must be 
handled as a true generic function with a true return, instead of a 
built-in inline expression.

But GNAT still just performs a simple copy. So, is GNAT or the RM 
or is the generic "Unchecked_Conversion" function in error?


In <715a5498-095c-4e61-8a09-8510c19b2553@s16g2000prf.googlegroups.com>, Adam Beneschan <adam@irvine.com> writes:
>On May 9, 11:27=A0pm, a...@att.net wrote:
>> Better look again!
>>
>> Even though a compiler emulates the "Unchecked_Conversion" with a built-i=
>n
>> "pragma inline" being enforced. =A0The function still must be able to be
>> written in Ada.
>
>No, it doesn't.  Show me a rule in the RM that says it does.  You
>can't.  There isn't one.
>
>                           -- Adam




  reply	other threads:[~2011-05-11 20:39 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-30  8:41 A hole in Ada type safety Florian Weimer
2011-04-30 11:56 ` Robert A Duff
2011-04-30 15:27   ` Gavino
2011-04-30 16:16   ` Florian Weimer
2011-04-30 23:39     ` Randy Brukardt
2011-05-01 10:26       ` Florian Weimer
2011-05-03  1:40         ` Randy Brukardt
2011-05-03 16:57           ` Robert A Duff
2011-05-07  9:09           ` Florian Weimer
2011-05-07  9:28             ` Dmitry A. Kazakov
2011-05-07  9:57               ` Florian Weimer
2011-05-08  8:08                 ` Dmitry A. Kazakov
2011-05-08  8:46                   ` Florian Weimer
2011-05-08  9:32                     ` Dmitry A. Kazakov
2011-05-08 10:30                       ` Florian Weimer
2011-05-08 20:24                         ` anon
2011-05-08 21:11                           ` Simon Wright
2011-05-10  6:27                             ` anon
2011-05-10 14:39                               ` Adam Beneschan
2011-05-11 20:39                                 ` anon [this message]
2011-05-12  0:51                                   ` Randy Brukardt
2011-05-13  0:47                                     ` anon
2011-05-13  0:58                                       ` Adam Beneschan
2011-05-13  5:31                                       ` AdaMagica
2011-05-12  5:51                                   ` AdaMagica
2011-05-12 12:09                                     ` Robert A Duff
2011-05-12 14:40                                     ` Adam Beneschan
2011-05-14  0:30                                       ` Randy Brukardt
2011-05-09  7:48                         ` Dmitry A. Kazakov
2011-05-09 20:41             ` Randy Brukardt
2011-05-14 23:47     ` anon
replies disabled

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