• Ada Pure or Preelaborate or ? in Adare_net

    From Daniel Norte Moraes@21:1/5 to All on Fri Dec 31 08:13:31 2021
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Simon Belmont@21:1/5 to daniel...@gmail.com on Mon Jan 3 17:11:36 2022
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Fabien Chouteau@21:1/5 to daniel...@gmail.com on Tue Jan 4 05:52:41 2022
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Daniel Norte Moraes@21:1/5 to All on Wed Jan 5 08:11:52 2022
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Daniel Norte Moraes@21:1/5 to All on Wed Jan 5 08:33:57 2022
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Randy Brukardt@21:1/5 to All on Wed Jan 5 17:40:04 2022
    "Daniel Norte Moraes" <danielcheagle@gmail.com> wrote in message news:378bc69a-8388-4daf-b13f-523fd1defa12n@googlegroups.com...
    Em tera-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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Daniel Norte Moraes@21:1/5 to All on Thu Jan 6 12:39:21 2022
    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!! :-)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)