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!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!maths.tcd.ie!newsswitch.lcs.mit.edu!nntp.TheWorld.com!.POSTED!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Ada Annoyances Date: Thu, 29 Jun 2017 17:12:20 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <1ac5a44b-4423-443a-a7bb-2864d9abe78f@googlegroups.com> <4921bd4e-3827-a7ac-7f2d-d60edbc514a3@tidorum.invalid> NNTP-Posting-Host: shell02.theworld.com Mime-Version: 1.0 Content-Type: text/plain X-Trace: pcls7.std.com 1498770740 12791 192.74.137.72 (29 Jun 2017 21:12:20 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Thu, 29 Jun 2017 21:12:20 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:hwgM9YPsvMq8qeImar62MnK2R2c= Xref: news.eternal-september.org comp.lang.ada:47192 Date: 2017-06-29T17:12:20-04:00 List-Id: Niklas Holsti writes: > There are two reasons why tagged types hamper such analysis: As Randy pointed out, it is more correct to say that class-wide types do that. Tagged types by themselves do not cause these problems. Tagged types without class-wide types are not super useful, but they are somewhat useful. > a) dispatching calls (as you said), where the actual callee is > determined by run-time values (tags) which are hard to predict by static > analysis > > b) the non-static size of class-wide objects (of type T'Class), which > means that the compiler and/or the programmer must use dynamic > allocation (usually heap or secondary stack) for such objects. ... > For some time, I have had in mind a possible Ada extension to solve > point (b): an attribute/aspect that would let the programmer set a > static upper bound on the size of any object in T'Class. If we call this > aspect Maximum_Size (or perhaps Maximum_Size'Class), the programmer > could use it like this: > > type Root is tagged record ... end record > with Maximum_Size => 128; Something like that was considered and rejected for Ada 9X. Part of the problem is that it seems so low level to be talking about sizes. It's not even portable. And not maintainable -- if you delete a big type, or make it smaller, you're now wasting space. It would be better to have the compiler compute the maximum size needed. That would require the compiler to do a fairly global analysis, which is something Ada compilers are not set up to do. > type Object_List is array (List_Index) of Root'Class; > > type Object_Pair is record > A, B : Root'Class; > end record; Would you allow: X : Object_List (1..10); Y : Object_Pair; ? If so, what is the 'Tag of the various components? "Undefined" is not a very satisfying answer. These things are analogous to records with defaulted discriminants. The language makes some (unsuccessful!) attempt to prevent uninitialized discriminants. - Bob