From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: Victor Porton Newsgroups: comp.lang.ada Subject: Re: Rough proposal to make some generic types static Date: Tue, 22 Jul 2014 00:44:35 +0300 Organization: Aioe.org NNTP Server Message-ID: References: <45b2d813-f991-4c1c-b280-a1037bae8a66@googlegroups.com> NNTP-Posting-Host: rFX7cZOSaeuGGZI2vwQTaQ.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Complaints-To: abuse@aioe.org User-Agent: KNode/4.12.4 X-Notice: Filtered by postfilter v. 0.8.2 Xref: news.eternal-september.org comp.lang.ada:21104 Date: 2014-07-22T00:44:35+03:00 List-Id: 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