comp.lang.ada
 help / color / mirror / Atom feed
From: Niklas Holsti <niklas.holsti@tidorum.invalid>
Subject: Re: Ada.Locales pseudo-string types
Date: Wed, 08 Aug 2012 11:17:46 +0300
Date: 2012-08-08T11:17:46+03:00	[thread overview]
Message-ID: <a8ellaFjajU1@mid.individual.net> (raw)
In-Reply-To: <jvt4lo$cpq$1@dont-email.me>

On 12-08-08 10:32 , J-P. Rosen wrote:
> Le 08/08/2012 09:04, Niklas Holsti a �crit :
>> The rule does seem surprisingly rigid, for a value conversion. (The
>> Annotated RM does not explain or motivate it.) For a value conversion,
>> the default could be to convert element by element, and the compiler
>> could then optimize this conversion based on what it can deduce
>> statically about the matching of the source and target subtypes.
> One of the founding principles of Ada was "no hidden inefficiencies"
> (whether this has been achieved is another story). Since an array can
> have many elements, this could be quite costly.

This is understood. Whether this inefficiency is "hidden" is debatable,
of course.

> And of course, it would force pass-by-copy

I don't think so. If the source and target element subtypes statically
match, or match well enough that no element conversions are necessary
(as in the original Ada.Locales example), the compiled code could be the
same as compilers use now. In other cases, the compiler could create a
temporary array to hold the result of the conversion, and pass this
array by reference.

I admit that this could lead to cases where a small change in the types
makes the compiler switch from the fast, no-copy, pass-by-reference code
to the slower element-by-element copying code, which could cause a
surprising drop in performance. Users might want compilers to warn them
about such cases.

>> In the example, the compiler should be able to deduce that
>> element-by-element conversion is unnecessary since the source element
>> subtype is a subrange of the target element subtype.
> But if the conversion is used for an in-out parameter, it implies the
> opposite conversion - where nothing can be deduced.
> 
> And you don't want a special rule that works only for in parameters,

"In" parameters already have special rules, since conversions for "in"
parameters are considered value conversions rather than view conversions.

> and only with compilers that pass arrays by copy, would you?

So the movation for the present static-match rule is that it makes it
simple for compilers always to pass arrays by reference, even when the
array is the result of a type conversion. (I suppose it is a quibble to
point out that a compiler is nevertheless not forced to pass by
reference.) But the rule is still stronger than necessary.

For value conversions, including "in" parameters, the exact match could
be replaced by a static check that the constraints on the source
elements are the same as or stronger than those on the target elements.
This would allow Ada.Text_IO.Put (String (Some_Country_Code)).

For "out" parameters, there could be a static check that the constraints
on the actual (source) array elements are the same as or weaker than
those on the formal (target) array elements.

For "in out" parameters, the present static-match rule would be kept, as
the logical conjunction of the "in" and "out" rules.

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
      .      @       .



  reply	other threads:[~2012-08-13  8:50 UTC|newest]

Thread overview: 69+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-06 16:45 Ada.Locales pseudo-string types Marius Amado-Alves
2012-08-06 17:10 ` Marius Amado-Alves
2012-08-06 19:15   ` J-P. Rosen
2012-08-06 19:34     ` Simon Wright
2012-08-06 20:07       ` Marius Amado-Alves
2012-08-06 20:57         ` Simon Wright
2012-08-06 21:09           ` Vasiliy Molostov
2012-08-06 23:07             ` Adam Beneschan
2012-08-06 23:23               ` Vasiliy Molostov
2012-08-06 23:46                 ` Adam Beneschan
2012-08-07  1:17                   ` Vasiliy Molostov
2012-08-07  7:20               ` Dmitry A. Kazakov
2012-08-07  7:43               ` Jacob Sparre Andersen
2012-08-09 20:47                 ` Randy Brukardt
2012-08-07  8:44               ` Marius Amado-Alves
2012-08-07 13:14                 ` Marius Amado-Alves
2012-08-07 15:42                   ` Adam Beneschan
2012-08-07 18:22                     ` Marius Amado-Alves
2012-08-07 20:10                       ` Adam Beneschan
2012-08-07 20:42                         ` Marius Amado-Alves
2012-08-07 21:38                           ` Adam Beneschan
2012-08-08  7:04                           ` Niklas Holsti
2012-08-08  7:18                             ` Dmitry A. Kazakov
2012-08-08  7:37                               ` Niklas Holsti
2012-08-08  8:09                                 ` Dmitry A. Kazakov
2012-08-08 11:14                                   ` Niklas Holsti
2012-08-08 11:59                                     ` Dmitry A. Kazakov
2012-08-08 14:01                                       ` Niklas Holsti
2012-08-09  7:48                                         ` Dmitry A. Kazakov
2012-08-09  8:31                                           ` Niklas Holsti
2012-08-09 12:17                                             ` Dmitry A. Kazakov
2012-08-09 15:25                                               ` Niklas Holsti
2012-08-09 16:43                                                 ` Dmitry A. Kazakov
2012-08-08  8:28                                 ` J-P. Rosen
2012-08-08 11:35                                   ` Niklas Holsti
2012-08-08 14:05                                     ` Georg Bauhaus
2012-08-08  7:32                             ` J-P. Rosen
2012-08-08  8:17                               ` Niklas Holsti [this message]
2012-08-08  8:33                                 ` J-P. Rosen
2012-08-08 11:44                                   ` Niklas Holsti
2012-08-09 21:00                                   ` Randy Brukardt
2012-08-08  8:35                                 ` Dmitry A. Kazakov
2012-08-08  9:32                                   ` Marius Amado-Alves
2012-08-08 10:11                                     ` Dmitry A. Kazakov
2012-08-08 11:28                                       ` Marius Amado-Alves
2012-08-08 11:30                                         ` Marius Amado-Alves
2012-08-08 11:35                                       ` Marius Amado-Alves
2012-08-08 12:24                                         ` Dmitry A. Kazakov
2012-08-08 11:52                                   ` Niklas Holsti
2012-08-08 13:21                                     ` Dmitry A. Kazakov
2012-08-08  9:07                             ` Marius Amado-Alves
2012-08-07 20:43                         ` Marius Amado-Alves
2012-08-07 21:59                   ` Robert A Duff
2012-08-07 22:19                     ` Adam Beneschan
2012-08-08  0:37                       ` Robert A Duff
2012-08-07 15:26                 ` Adam Beneschan
2012-08-07 18:07                   ` Marius Amado-Alves
2012-08-07 17:51       ` Simon Wright
2012-08-06 20:00     ` Marius Amado-Alves
2012-08-06 19:49   ` Jacob Sparre Andersen
2012-08-06 20:11     ` Marius Amado-Alves
2012-08-06 17:37 ` Michael Rohan
2012-08-06 18:23   ` Marius Amado-Alves
2012-08-06 19:36     ` Michael Rohan
2012-08-09 21:15   ` Randy Brukardt
2012-08-07  5:57 ` Jeffrey R. Carter
2012-08-07 15:46   ` Adam Beneschan
2012-08-07 17:51     ` Jeffrey R. Carter
2012-08-09 21:17       ` Randy Brukardt
replies disabled

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