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 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: "Jeffrey R. Carter" Newsgroups: comp.lang.ada Subject: Re: Why forbid local generic instantiations? Date: Sat, 26 Jan 2019 10:56:27 +0100 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: <100ce3ee-71f7-46c7-a24c-dc9c0d280c4f@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sat, 26 Jan 2019 09:56:28 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="804a4597dc6f5d44f793351d739136d0"; logging-data="2160"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/SUoDWS2UHWavR8lsVcQz0G8Ltg1l2Mrk=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 Cancel-Lock: sha1:UPVNUij+tT81TmUUFkObphKUUwI= In-Reply-To: Content-Language: en-US Xref: reader01.eternal-september.org comp.lang.ada:55378 Date: 2019-01-26T10:56:27+01:00 List-Id: On 1/25/19 10:23 PM, Randy Brukardt wrote: > "Jeffrey R. Carter" wrote in message > news:q2fdui$9vn$1@dont-email.me... > ... >> Perhaps such people don't know that instantiation takes place during >> compilation and has no run-time impact. > > I agree with most of what you said, but this statement is false, since the > instance is elaborated at the point of the instantation. Depending on the > generic, that could be a substantial amount of execution time. (Note that is > even more true for a code-shared implementation like Janus/Ada, since the > elaboration of the instance creates the instantiation descriptor.) I can't tell from what you've written if what I said is wrong or if we're saying basically the same thing in different ways. I'm not familiar with the way shared-code generics are instantiated. Macro-expansion instantiation is straightforward. The rule I learned (Ada 83) was: Instantiation happens during compilation; elaboration happens during run time. In more detail: Instantiation is the process whereby a compiler effectively replaces an instantiation with a regular pkg (the instance). The result is no different from having written the resulting regular pkg instead of the instantiation, except for possible code sharing with other instantiations of the same generic [ignoring the case of an instantiation in a pkg spec]. All pkgs, regular or generic instances, are elaborated during run time. That elaboration can be as complex as the developer wants. In the case of a pkg in a subprogram, that elaboration happens every time the subprogram is called. That's what I learned back when dinosaurs ruled the earth. I gather from what you've written that a shared-code compiler may increase the amount of elaboration by some (hopefully small, fixed?) amount, so it's not technically correct unless the increase is small enough to be considered negligible. I think it's correct for compilers that do macro-expansion instantiation, and close enough for the rule to be correct as a 1st-order approximation. If I'm wrong, I'd like to be corrected. -- Jeff Carter "I feel as though somebody stepped on my tongue with muddy feet." Never Give a Sucker an Even Break 112