comp.lang.ada
 help / color / mirror / Atom feed
* Ada Pure or Preelaborate or ? in Adare_net
@ 2021-12-31 16:13 Daniel Norte Moraes
  2022-01-04  1:11 ` Simon Belmont
  2022-01-04 13:52 ` Fabien Chouteau
  0 siblings, 2 replies; 7+ messages in thread
From: Daniel Norte Moraes @ 2021-12-31 16:13 UTC (permalink / raw)


Hi! 

I and a friend created an Ada network lib where,
from the begining, we tried very hard to make It a Ada Pure.

From the examples dir, the lib worked as expected (in gcc-10.2 gcc-11.2 and gcc-12).
To our surprise, what most caught the attention of the group's friends was the fact that the lib was Ada Pure and if that was correct.

For this reason, if really 'is' pure, not pure, preelaborate or what (?), pleeeeeeaaase, we ask the group's Ada Language Lawyers to help analyze and suggest modifications  if necessary. 

link: https://gitlab.com/daresoft/network/adare_net/-/tree/202x
for Ada version use 2012 and or 202x.

Best Wishes and Happy New Year,
Dani.



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

* Re: Ada Pure or Preelaborate or ? in Adare_net
  2021-12-31 16:13 Ada Pure or Preelaborate or ? in Adare_net Daniel Norte Moraes
@ 2022-01-04  1:11 ` Simon Belmont
  2022-01-05 16:11   ` Daniel Norte Moraes
  2022-01-04 13:52 ` Fabien Chouteau
  1 sibling, 1 reply; 7+ messages in thread
From: Simon Belmont @ 2022-01-04  1:11 UTC (permalink / raw)


On Friday, December 31, 2021 at 11:13:33 AM UTC-5, daniel...@gmail.com wrote:
> Hi! 
> 
> I and a friend created an Ada network lib where, 
> from the begining, we tried very hard to make It a Ada Pure. 
> 
> From the examples dir, the lib worked as expected (in gcc-10.2 gcc-11.2 and gcc-12). 
> To our surprise, what most caught the attention of the group's friends was the fact that the lib was Ada Pure and if that was correct. 
> 
> For this reason, if really 'is' pure, not pure, preelaborate or what (?), pleeeeeeaaase, we ask the group's Ada Language Lawyers to help analyze and suggest modifications if necessary. 
> 
> link: https://gitlab.com/daresoft/network/adare_net/-/tree/202x 
> for Ada version use 2012 and or 202x. 
> 
> Best Wishes and Happy New Year, 
> Dani.

It seems to be mostly just a thin binding to a bunch of C functions, so the applicability of any Ada feature is mostly a moot point. The Ada compiler has no control or visibility into the C domain, so while on the one hand your packages are technically Pure, on the other hand the C functions can violate those "purity rules" all they want, which might be misleading to users expecting otherwise.  You don't use 'Unchecked_Access either, but obviously that doesn't mean the C functions are somehow prevented from creating dangling pointers.  Personally, I would have the interfaces reflect the reality of the actual behavior (which in the case of C code you don't control, is usually assume-the-worst).

-sb


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

* Re: Ada Pure or Preelaborate or ? in Adare_net
  2021-12-31 16:13 Ada Pure or Preelaborate or ? in Adare_net Daniel Norte Moraes
  2022-01-04  1:11 ` Simon Belmont
@ 2022-01-04 13:52 ` Fabien Chouteau
  2022-01-05 16:33   ` Daniel Norte Moraes
  1 sibling, 1 reply; 7+ messages in thread
From: Fabien Chouteau @ 2022-01-04 13:52 UTC (permalink / raw)


On Friday, December 31, 2021 at 5:13:33 PM UTC+1, daniel...@gmail.com wrote:
> For this reason, if really 'is' pure, not pure, preelaborate or what (?), pleeeeeeaaase, we ask the group's Ada Language Lawyers to help analyze and suggest modifications if necessary. 

I recommend reading this: https://stackoverflow.com/questions/19353228/when-to-use-pragma-pure-preelaborate

If your units are declared as Pure, the compiler considers that they have no side effect and can decided to call the sub-programs only once and cache the result, or not even call the sub-program if the result is not used after.

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

* Re: Ada Pure or Preelaborate or ? in Adare_net
  2022-01-04  1:11 ` Simon Belmont
@ 2022-01-05 16:11   ` Daniel Norte Moraes
  0 siblings, 0 replies; 7+ messages in thread
From: Daniel Norte Moraes @ 2022-01-05 16:11 UTC (permalink / raw)


Em segunda-feira, 3 de janeiro de 2022 às 22:11:37 UTC-3, Simon Belmont escreveu:
> On Friday, December 31, 2021 at 11:13:33 AM UTC-5, daniel...@gmail.com wrote: 
> > Hi! 
> > 
> > I and a friend created an Ada network lib where, 
> > from the begining, we tried very hard to make It a Ada Pure. 
> > 
> > From the examples dir, the lib worked as expected (in gcc-10.2 gcc-11.2 and gcc-12). 
> > To our surprise, what most caught the attention of the group's friends was the fact that the lib was Ada Pure and if that was correct. 
> > 
> > For this reason, if really 'is' pure, not pure, preelaborate or what (?), pleeeeeeaaase, we ask the group's Ada Language Lawyers to help analyze and suggest modifications if necessary. 
> > 
> > link: https://gitlab.com/daresoft/network/adare_net/-/tree/202x 
> > for Ada version use 2012 and or 202x. 
> > 
> > Best Wishes and Happy New Year, 
> > Dani.
> It seems to be mostly just a thin binding to a bunch of C functions, so the applicability of any Ada feature is mostly a moot point. The Ada compiler has no control or visibility into the C domain, so while on the one hand your packages are technically Pure, on the other hand the C functions can violate those "purity rules" all they want, which might be misleading to users expecting otherwise. You don't use 'Unchecked_Access either, but obviously that doesn't mean the C functions are somehow prevented from creating dangling pointers. Personally, I would have the interfaces reflect the reality of the actual behavior (which in the case of C code you don't control, is usually assume-the-worst). 
> 
> -sb

Thanks !

The C pointers are only created in   c_initialize_socket.c (c_init_address()  ) and data pointed copied 
to an ada array, and then immediately free by c part.  this is the only time there is a dynamic allocation. 
We managed to make libadare_net very close to 100% static allocation!
Because this, don´t are dangling pointers.

There is still the problem of omitting the execution of subprograms by the compiler by pure packages.
would 'preelaborate' solve this?

Thanks!

Best Wishes,
Dani.

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

* Re: Ada Pure or Preelaborate or ? in Adare_net
  2022-01-04 13:52 ` Fabien Chouteau
@ 2022-01-05 16:33   ` Daniel Norte Moraes
  2022-01-05 23:40     ` Randy Brukardt
  0 siblings, 1 reply; 7+ messages in thread
From: Daniel Norte Moraes @ 2022-01-05 16:33 UTC (permalink / raw)


Em terça-feira, 4 de janeiro de 2022 às 10:52:42 UTC-3, Fabien Chouteau escreveu:
> On Friday, December 31, 2021 at 5:13:33 PM UTC+1, daniel...@gmail.com wrote: 
> > For this reason, if really 'is' pure, not pure, preelaborate or what (?), pleeeeeeaaase, we ask the group's Ada Language Lawyers to help analyze and suggest modifications if necessary.
> I recommend reading this: https://stackoverflow.com/questions/19353228/when-to-use-pragma-pure-preelaborate 
> 
> If your units are declared as Pure, the compiler considers that they have no side effect and can decided to call the sub-programs only once and cache the result, or not even call the sub-program if the result is not used after.

Thanks!
I read the post and believe that because most variables are either streamed or aliased and imported, lib works as it should.
However, there is still the possible problem of omitting the same subprograms with the same parameters (by compiler), although in the tests this did not happen, would replacing aspect 'pure' by 'preelaborate' solve this possible problem?

Thanks!
Best Whishes,
Dani.

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

* Re: Ada Pure or Preelaborate or ? in Adare_net
  2022-01-05 16:33   ` Daniel Norte Moraes
@ 2022-01-05 23:40     ` Randy Brukardt
  2022-01-06 20:39       ` Daniel Norte Moraes
  0 siblings, 1 reply; 7+ messages in thread
From: Randy Brukardt @ 2022-01-05 23:40 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1571 bytes --]

"Daniel Norte Moraes" <danielcheagle@gmail.com> wrote in message 
news:378bc69a-8388-4daf-b13f-523fd1defa12n@googlegroups.com...
>Em terça-feira, 4 de janeiro de 2022 às 10:52:42 UTC-3, Fabien Chouteau 
>escreveu:
>> On Friday, December 31, 2021 at 5:13:33 PM UTC+1, daniel...@gmail.com 
>> wrote:
>> > For this reason, if really 'is' pure, not pure, preelaborate or what 
>> > (?), pleeeeeeaaase, we ask the group's Ada Language Lawyers to help 
>> > analyze and suggest modifications if necessary.
>> I recommend reading this: 
>> https://stackoverflow.com/questions/19353228/when-to-use-pragma-pure-preelaborate
>>
>> If your units are declared as Pure, the compiler considers that they have 
>> no side effect and can decided to call the sub-programs only once and 
>> cache the result, or not even call the sub-program if the result is not 
>> used after.

>Thanks!
>I read the post and believe that because most variables are either streamed 
>or aliased and imported, lib works as it should.
>However, there is still the possible problem of omitting the same 
>subprograms with the same parameters (by compiler), although in the tests 
>this did not happen, would replacing aspect 'pure' by 'preelaborate' solve 
>this possible problem?

Yes. The permission to omit calls only applies to Pure (see 10.2.1(18/3)). 
http://www.ada-auth.org/standards/2xaarm/html/AA-10-2-1.html#p18. (I gave a 
reference to the Ada 2022 AARM, but this rule hasn't changed in spirit since 
it was introduced in Ada 95.)

                        Randy.


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

* Re: Ada Pure or Preelaborate or ? in Adare_net
  2022-01-05 23:40     ` Randy Brukardt
@ 2022-01-06 20:39       ` Daniel Norte Moraes
  0 siblings, 0 replies; 7+ messages in thread
From: Daniel Norte Moraes @ 2022-01-06 20:39 UTC (permalink / raw)


Em quarta-feira, 5 de janeiro de 2022 às 20:40:08 UTC-3, Randy Brukardt escreveu:
> "Daniel Norte Moraes" <daniel...@gmail.com> wrote in message 
> news:378bc69a-8388-4daf...@googlegroups.com...
> >Em terça-feira, 4 de janeiro de 2022 às 10:52:42 UTC-3, Fabien Chouteau 
> >escreveu: 
> >> On Friday, December 31, 2021 at 5:13:33 PM UTC+1, daniel...@gmail.com 
> >> wrote: 
> >> > For this reason, if really 'is' pure, not pure, preelaborate or what 
> >> > (?), pleeeeeeaaase, we ask the group's Ada Language Lawyers to help 
> >> > analyze and suggest modifications if necessary. 
> >> I recommend reading this: 
> >> https://stackoverflow.com/questions/19353228/when-to-use-pragma-pure-preelaborate 
> >> 
> >> If your units are declared as Pure, the compiler considers that they have 
> >> no side effect and can decided to call the sub-programs only once and 
> >> cache the result, or not even call the sub-program if the result is not 
> >> used after. 
> 
> >Thanks! 
> >I read the post and believe that because most variables are either streamed 
> >or aliased and imported, lib works as it should. 
> >However, there is still the possible problem of omitting the same 
> >subprograms with the same parameters (by compiler), although in the tests 
> >this did not happen, would replacing aspect 'pure' by 'preelaborate' solve 
> >this possible problem?
> Yes. The permission to omit calls only applies to Pure (see 10.2.1(18/3)). 
> http://www.ada-auth.org/standards/2xaarm/html/AA-10-2-1.html#p18. (I gave a 
> reference to the Ada 2022 AARM, but this rule hasn't changed in spirit since 
> it was introduced in Ada 95.) 
> 
> Randy.

Thanks!

We will change the packages in LibAdare_Net to 'preelaborate'. :-)
and continue from here. 

Thanks All,
Best Whishes,
Dani.

Enjoy!! :-)

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

end of thread, other threads:[~2022-01-06 20:39 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-31 16:13 Ada Pure or Preelaborate or ? in Adare_net Daniel Norte Moraes
2022-01-04  1:11 ` Simon Belmont
2022-01-05 16:11   ` Daniel Norte Moraes
2022-01-04 13:52 ` Fabien Chouteau
2022-01-05 16:33   ` Daniel Norte Moraes
2022-01-05 23:40     ` Randy Brukardt
2022-01-06 20:39       ` Daniel Norte Moraes

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