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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,96f34ca0f504eb8,start X-Google-Attributes: gid103376,public From: dewar@merv.cs.nyu.edu (Robert Dewar) Subject: Little note on shared generics Date: 1997/04/26 Message-ID: #1/1 X-Deja-AN: 237630781 Organization: New York University Newsgroups: comp.lang.ada Date: 1997-04-26T00:00:00+00:00 List-Id: Since we have discussed recently a little bit the advantages and disadvantages of macro-instantiated generics, I thought the following little example from GNAT is entertaining. It shows how the use of macro-instantiation rather cheaply means that the compiler can do a lot for you, because it has all the code conveniently at hand. In this case, we are compiling a case of a triply nested instantiation, and GNAT says: test1.adb:8:04: warning: in instantiation at type_liste_contigue_ordonnee.adb:8 test1.adb:8:04: warning: in instantiation at type_arbre_balance.ads:53 test1.adb:8:04: warning: in instantiation at balance_io.ads:41 test1.adb:8:04: warning: infinite recursion test1.adb:8:04: warning: Storage_Error will be raised at runtime What is going on in this triply nested instantiation is that we have in the template: function "<" (U, V : in ELEMENT) return BOOLEAN is begin return LA_CLE (U) < LA_CLE (V); end "<"; But LA_CLE is a generi formal function, and in the instantiation for which the warning is posted, the instantiation looks like: with BALANCE_IO; procedure TEST1 is function LA_CLE (E : INTEGER) return INTEGER is begin return E; end LA_CLE; package AB is new BALANCE_IO ( 1000, INTEGER, INTEGER); begin null; end TEST1; LA_CLE is passed down to each level of the instantiation, and given that it is a function from INTEGER to INTEGER, and the corresponding formal type ELEMENT is also INTEGER, this is indeed an infinite recursion! The nice thing about this is that the fact that GNAT does macro insertion means we get this kind of processing free on generic instantiations. Robert Dewar Ada Core Technologies