comp.lang.ada
 help / color / mirror / Atom feed
* Pure, Storage_Size and Unchecked_Conversion
@ 2007-07-08  0:24 Y.Tomino
  2007-07-08  9:49 ` Georg Bauhaus
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Y.Tomino @ 2007-07-08  0:24 UTC (permalink / raw)


Hi.
I compiled the package like this with gcc 4.2.

with Ada.Unchecked_Conversion;
package Pure_SS_Unc is
   pragma Pure;
   type T is access Integer;
   for T'Storage_Size use 0;
   function F1 (X : Integer) return T;
   function F2 is new Ada.Unchecked_Conversion (Integer, T);
end Pure_SS_Unc;

Ada.Unchecked_Conversion is pure generic function.
I think the condition of F1 and F2 is the same.
but, I saw this message:

pure_ss_unc.ads:7:58: named access types not allowed in pure unit

   function F1 (X : Integer) return T; -- OK
   function F2 is new Ada.Unchecked_Conversion (Integer, T); -- NG

Why does compiler make an error at F2?

--
YT http://panathenaia.halfmoon.jp/alang/ada.html




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Pure, Storage_Size and Unchecked_Conversion
  2007-07-08  0:24 Pure, Storage_Size and Unchecked_Conversion Y.Tomino
@ 2007-07-08  9:49 ` Georg Bauhaus
  2007-07-08 10:41   ` Y.Tomino
  2007-07-08 16:08 ` Martin Krischik
  2007-07-10  1:35 ` Randy Brukardt
  2 siblings, 1 reply; 9+ messages in thread
From: Georg Bauhaus @ 2007-07-08  9:49 UTC (permalink / raw)


On Sat, 2007-07-07 at 17:24 -0700, Y.Tomino wrote:

> with Ada.Unchecked_Conversion;
> package Pure_SS_Unc is
>    pragma Pure;
>    type T is access Integer;
>    for T'Storage_Size use 0;
>    function F1 (X : Integer) return T;
>    function F2 is new Ada.Unchecked_Conversion (Integer, T);
> end Pure_SS_Unc;
> 
> [...]
> pure_ss_unc.ads:7:58: named access types not allowed in pure unit

The message should really apply to the declaration of T.
T is a named access type. If you remove all lines referring
to U_C, the compiler might say something like


GNAT 4.1.2 (Ubuntu 4.1.2-0ubuntu4)
Copyright 1992-2005 Free Software Foundation, Inc.

Compiling: pure_ss_unc.ads (source file time stamp: 2007-07-08 09:44:14)

     4.    type T is access Integer;
                |
        >>> named access type not allowed in pure unit

 8 lines: 1 error


Just guessing what your package is supposed to achieve,
have you considered using System.Address_To_Access_Conversions?






^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Pure, Storage_Size and Unchecked_Conversion
  2007-07-08  9:49 ` Georg Bauhaus
@ 2007-07-08 10:41   ` Y.Tomino
  0 siblings, 0 replies; 9+ messages in thread
From: Y.Tomino @ 2007-07-08 10:41 UTC (permalink / raw)


gcc 4.1.2 and gcc 4.2.0 are different. The default mode of gcc 4.2.0
is Ada 2005.
And, Ada 2005 accepts access types with "for T'Storage_Size use 0" in
pure package.
"for T'Storage_Size use 0" means to disallow "new". T will be plain
address value, and has no side effect.
Please, see http://www.adaic.com/standards/05rm/html/RM-10-2-1.html

> Just guessing what your package is supposed to achieve,
> have you considered using System.Address_To_Access_Conversions?

System.Address_To_Access_Conversions fixes pointer type as access all.
Actually, I want to use the access constant, and expect inlining.

--
YT http://panathenaia.halfmoon.jp/alang/ada.html




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Pure, Storage_Size and Unchecked_Conversion
  2007-07-08  0:24 Pure, Storage_Size and Unchecked_Conversion Y.Tomino
  2007-07-08  9:49 ` Georg Bauhaus
@ 2007-07-08 16:08 ` Martin Krischik
  2007-07-09 13:31   ` Y.Tomino
  2007-07-10  1:35 ` Randy Brukardt
  2 siblings, 1 reply; 9+ messages in thread
From: Martin Krischik @ 2007-07-08 16:08 UTC (permalink / raw)


Y.Tomino wrote:

> Hi.
> I compiled the package like this with gcc 4.2.
> 
> with Ada.Unchecked_Conversion;
> package Pure_SS_Unc is
>    pragma Pure;
>    type T is access Integer;
>    for T'Storage_Size use 0;
>    function F1 (X : Integer) return T;
>    function F2 is new Ada.Unchecked_Conversion (Integer, T);
> end Pure_SS_Unc;

You are aware that this will only work on 32 bit system while 64 bit is the
future. It does - of course - not mean that you can't do it. You just have
to do it right.

Read:

http://en.wikibooks.org/wiki/Ada_Programming/Types/access#Where_is_void.2A.3F

In short: don't use the predefined integer - use your own:

type void is mod System.Memory_Size;
for void'Size use System.Word_Size;

> pure_ss_unc.ads:7:58: named access types not allowed in pure unit

It's one of the definitions of a pure unit: no named access types. It you
read the Distributed System Annex then you will see why it has to be that
way.

Martin
-- 
mailto://krischik@users.sourceforge.net
Ada programming at: http://ada.krischik.com



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Pure, Storage_Size and Unchecked_Conversion
  2007-07-08 16:08 ` Martin Krischik
@ 2007-07-09 13:31   ` Y.Tomino
  2007-07-09 21:31     ` Georg Bauhaus
  0 siblings, 1 reply; 9+ messages in thread
From: Y.Tomino @ 2007-07-09 13:31 UTC (permalink / raw)


On Jul 9, 1:08 am, Martin Krischik <krisc...@users.sourceforge.net>
wrote:
> You are aware that this will only work on 32 bit system while 64 bit is the
> future. It does - of course - not mean that you can't do it. You just have
> to do it right.

Don't mind. :-)

> It's one of the definitions of a pure unit: no named access types. It you
> read the Distributed System Annex then you will see why it has to be that
> way.

Thank you. I read it.
I understood access to class wide types is prohibited in remote
packages,
but I could not find description that normal access types were
prohibited (in pure packages).

Actually, Usual functions having access types like F1 are OK.
Generic functions like Ada.Unchecked_Conversion
(or my generic function I tested *1) are disallowed.

What is different ?

*1
generic type T is private; type A is access T;
function G (X : A) return A;
pragma Pure (G); --OK

function G (X : A) return A is begin return X; end G;

with G;
package P is
pragma Pure (P);
type A is access Integer; for A'Storage_Size use 0; --OK
function F1 (X : A) return A; --OK
function F2 is new G (A); --NG
end P;

--
YT http://panathenaia.halfmoon.jp/alang/ada.html




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Pure, Storage_Size and Unchecked_Conversion
  2007-07-09 13:31   ` Y.Tomino
@ 2007-07-09 21:31     ` Georg Bauhaus
  0 siblings, 0 replies; 9+ messages in thread
From: Georg Bauhaus @ 2007-07-09 21:31 UTC (permalink / raw)


On Mon, 2007-07-09 at 06:31 -0700, Y.Tomino wrote:

> Generic functions like Ada.Unchecked_Conversion
> (or my generic function I tested *1) are disallowed.
> 
> What is different ?

Maybe that is it, the generic formal pointer types (to
which the 'Storage_Size does not apply, then?)
The code below compile using GNAT GPL 2007.
The issue might be a question for your friendly Ada support
team...

package PP is

   pragma pure(PP);

   type Ptr is access Integer;
   for Ptr'Storage_Size use 0;

   generic
      type T is private;
   function G(X : Ptr) return Ptr;
      -- (Note: Ptr is not a generic formal here)

end PP;

with PP;
function F2 is new PP.G(Integer);
pragma pure(F2);

package body PP is
   function G(X : Ptr) return Ptr is
   begin
      return X;
   end G;
end PP;

> *1
> generic type T is private; type A is access T;
> function G (X : A) return A;
> pragma Pure (G); --OK
> 
> function G (X : A) return A is begin return X; end G;
> 
> with G;
> package P is
> pragma Pure (P);
> type A is access Integer; for A'Storage_Size use 0; --OK
> function F1 (X : A) return A; --OK
> function F2 is new G (A); --NG
> end P;





^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Pure, Storage_Size and Unchecked_Conversion
  2007-07-08  0:24 Pure, Storage_Size and Unchecked_Conversion Y.Tomino
  2007-07-08  9:49 ` Georg Bauhaus
  2007-07-08 16:08 ` Martin Krischik
@ 2007-07-10  1:35 ` Randy Brukardt
  2007-07-10  8:30   ` Georg Bauhaus
  2007-07-15 17:30   ` Y.Tomino
  2 siblings, 2 replies; 9+ messages in thread
From: Randy Brukardt @ 2007-07-10  1:35 UTC (permalink / raw)


"Y.Tomino" <demoonlit@panathenaia.halfmoon.jp> wrote in message
news:1183854255.792142.110150@i38g2000prf.googlegroups.com...
...
> Ada.Unchecked_Conversion is pure generic function.
> I think the condition of F1 and F2 is the same.
> but, I saw this message:
>
> pure_ss_unc.ads:7:58: named access types not allowed in pure unit
>
>    function F1 (X : Integer) return T; -- OK
>    function F2 is new Ada.Unchecked_Conversion (Integer, T); -- NG
>
> Why does compiler make an error at F2?

You've gotten a whole bunch of answers, but I think the correct one has not
be provided:
it is a compiler bug and there should not be an error at F2.

I'd suggest that you (and others as well) should ask the people at AdaCore
about what appear to be compiler bugs (especially in things changed by the
Amendment, which are highly likely to be buggy as they are new) rather than
confusing many with examples that seem to show non-existent limitations of
Ada (as opposed to a particular compiler). OTOH, if you don't have an
AdaCore contract, you won't get a timely answer from them, but I'd have to
say that you get what you pay for in that case...

                                        Randy.






^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Pure, Storage_Size and Unchecked_Conversion
  2007-07-10  1:35 ` Randy Brukardt
@ 2007-07-10  8:30   ` Georg Bauhaus
  2007-07-15 17:30   ` Y.Tomino
  1 sibling, 0 replies; 9+ messages in thread
From: Georg Bauhaus @ 2007-07-10  8:30 UTC (permalink / raw)


Randy Brukardt wrote:
> "Y.Tomino" <demoonlit@panathenaia.halfmoon.jp> wrote in message

>>    function F2 is new Ada.Unchecked_Conversion (Integer, T); -- NG
>>
>> Why does compiler make an error at F2?
> 
> You've gotten a whole bunch of answers, but I think the correct one has not
> be provided:
> it is a compiler bug and there should not be an error at F2.
> 
> I'd suggest that you (and others as well) should ask the people at AdaCore
> about what appear to be compiler bugs (especially in things changed by the
> Amendment, which are highly likely to be buggy as they are new) rather than
> confusing many with examples that seem to show non-existent limitations of
> Ada (as opposed to a particular compiler).

Thanks for pointing this out. I'm sure that the suspicion
of a bug has now turned into much more certainty and somewhat
better understanding of the language. A paradigmatic demonstration
of the value of support if that is within reach for an Ada 2005 compiler.




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Pure, Storage_Size and Unchecked_Conversion
  2007-07-10  1:35 ` Randy Brukardt
  2007-07-10  8:30   ` Georg Bauhaus
@ 2007-07-15 17:30   ` Y.Tomino
  1 sibling, 0 replies; 9+ messages in thread
From: Y.Tomino @ 2007-07-15 17:30 UTC (permalink / raw)


On Jul 10, 10:35 am, "Randy Brukardt" <ra...@rrsoftware.com> wrote:
> You've gotten a whole bunch of answers, but I think the correct one has not
> be provided:
> it is a compiler bug and there should not be an error at F2.

Thank you, the situation became clear for me.
I was looking for the cause and found the correction point of gcc.

sem_ch3.adb
--------------
                if Comes_From_Source (Id)
                  and then In_Pure_Unit
                  and then not In_Subprogram_Task_Protected_Unit
+                 and then not No_Pool_Assigned (T)
                then
                   Error_Msg_N
                     ("named access types not allowed in pure unit",
N);
----------------

The compiler after changing passes the above-mentioned code
though I do not understand whether my correction is correct.

> I'd suggest that you (and others as well) should ask the people at AdaCore
> about what appear to be compiler bugs (especially in things changed by the
> Amendment, which are highly likely to be buggy as they are new) rather than
> confusing many with examples that seem to show non-existent limitations of
> Ada (as opposed to a particular compiler). OTOH, if you don't have an
> AdaCore contract, you won't get a timely answer from them, but I'd have to
> say that you get what you pay for in that case...

Oh....I cannot pay the cost so much.




^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2007-07-15 17:30 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-07-08  0:24 Pure, Storage_Size and Unchecked_Conversion Y.Tomino
2007-07-08  9:49 ` Georg Bauhaus
2007-07-08 10:41   ` Y.Tomino
2007-07-08 16:08 ` Martin Krischik
2007-07-09 13:31   ` Y.Tomino
2007-07-09 21:31     ` Georg Bauhaus
2007-07-10  1:35 ` Randy Brukardt
2007-07-10  8:30   ` Georg Bauhaus
2007-07-15 17:30   ` Y.Tomino

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