comp.lang.ada
 help / color / mirror / Atom feed
From: Victor Porton <porton@narod.ru>
Subject: Re: Rough proposal to make some generic types static
Date: Tue, 22 Jul 2014 00:44:35 +0300
Date: 2014-07-22T00:44:35+03:00	[thread overview]
Message-ID: <lqk1k5$3r1$1@speranza.aioe.org> (raw)
In-Reply-To: 45b2d813-f991-4c1c-b280-a1037bae8a66@googlegroups.com

Adam Beneschan wrote:

> On Monday, July 21, 2014 1:44:21 PM UTC-7, Victor Porton wrote:
>> What in the RM signifies that Enum_Type (below) is not a static scalar
>> type?
>> 
>> We should work on an amendment for a future version of Ada to make
>> Enum_Type static?
>> 
>> Is it difficult to implement this?
>> 
>> Rationale is that the below code is useful in practice.
>> 
> 
> Generics in the Ada language are designed so that they can be implemented
> either by "macro expansion" or "code sharing" [1].  In macro expansion,
> every time you instantiate a generic, the compiler treats it as if you had
> written all the code, substituting actual for formal types; the compiler
> thus generates code for each instantiation.  In code sharing, the compiler
> generates the code for the generic *once*, when it sees the generic; when
> you instantiate the generic, the compiler arranges things so that all the
> information it needs to know about the actual types is passed as
> parameters.

I am not an expert in compiler optimization, but it looks anyway impossible 
for me to make efficient shared code for formal scalar types of possibly 
different sizes.

So, if I understand correctly, it cannot work this way anyway, and allowing 
static formal scalar types would not make this optimization worse.

> Using code sharing, it is not feasible for the compiler to generate code
> for a modular type if it doesn't know the type size in advance.  (Or at
> least that was the thinking when the decision was made to require the
> modulus to be static.  It may actually be possible to generate reasonably
> efficient code when the modulus is specifically of the form 2**N, where N
> is non-static.)
> 
> But, anyway, that's the rationale.
> 
>                                 -- Adam
> 
> 
> [1] Note that the language specification doesn't actually refer to those
> [two models.  So if someone came up with a third model that would obey all
> [the Ada rules, that would be legal also.

-- 
Victor Porton - http://portonvictor.org

  reply	other threads:[~2014-07-21 21:44 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-21 20:44 Rough proposal to make some generic types static Victor Porton
2014-07-21 20:54 ` Victor Porton
2014-07-21 21:28   ` Niklas Holsti
2014-07-21 21:32     ` Victor Porton
2014-07-21 21:43       ` Niklas Holsti
2014-07-21 23:10       ` Randy Brukardt
2014-07-21 21:39 ` Adam Beneschan
2014-07-21 21:44   ` Victor Porton [this message]
2014-07-21 21:54     ` Adam Beneschan
2014-07-21 21:58       ` Victor Porton
2014-07-22  0:20         ` Randy Brukardt
2014-07-23 21:36         ` Robert A Duff
2014-07-21 22:06       ` Shark8
2014-07-21 23:12     ` Randy Brukardt
2014-07-22  9:53       ` AdaMagica
2014-07-22 21:10         ` 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