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=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,ea5071f634c2ea8b X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.36.6 with SMTP id m6mr5325109pbj.4.1321904466072; Mon, 21 Nov 2011 11:41:06 -0800 (PST) Path: lh20ni2591pbb.0!nntp.google.com!news1.google.com!news2.google.com!newsfeed2.dallas1.level3.net!news.level3.com!bloom-beacon.mit.edu!newsswitch.lcs.mit.edu!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Generic-Package Elaboration Question / Possible GNAT Bug. Date: Mon, 21 Nov 2011 14:41:05 -0500 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <7bf9bc32-850a-40c6-9ae2-5254fe220533@f29g2000yqa.googlegroups.com> <4295dc09-43de-4557-a095-fc108359f27f@y42g2000yqh.googlegroups.com> <3snehoqgs8ia$.1nobjem6g6hx6$.dlg@40tude.net> <128rdz2581345$.c4td19l7qp9z$.dlg@40tude.net> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 X-Trace: pcls6.std.com 1321904465 13861 192.74.137.71 (21 Nov 2011 19:41:05 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Mon, 21 Nov 2011 19:41:05 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:jfBRx7NvnGA9nvSlu9vMyGP3uWM= Xref: news1.google.com comp.lang.ada:18999 Content-Type: text/plain; charset=us-ascii Date: 2011-11-21T14:41:05-05:00 List-Id: "Dmitry A. Kazakov" writes: > On Mon, 21 Nov 2011 08:08:04 -0500, Robert A Duff wrote: > >> "Dmitry A. Kazakov" writes: >> >>>>> I don't know if Ada keeps that promise for generic bodies, ... >> >> I think it does. I'd be interested in any counterexamples. > > GNAT sometimes reports errors in generic bodies upon instantiation, but I > am not sure if these are not compiler bugs. I have seen such compiler bugs in the past. There are also some cases where GNAT allows representation clauses in a generic body that might turn out to be illegal in some instances. But as far as I know, these are optional -- GNAT didn't HAVE to support them in generic bodies, so this violation of the contract model is GNAT's, not Ada's. And it's useful, although nonportable. >>>...Generic contracts are too weak for that. >> >> Well, it's not that the contracts are too weak. You just have to >> consider the entire generic spec (including the private part, >> unfortunately), as part of the "contract". > > That is C++'s approach. If matching formal parameters does not imply > legality, that does not look very contracted. The C++ approach is that the entire template is the "contract" (which means there really is no contract). In Ada, at least the body is excluded. I agree it would be cleaner if the contract were just the generic formals, but in Ada that would require a lot of additional information in the formals. >> Also, the generic contract model applies only to compile-time rules. > > Sure, that is a contract model of the meta language of generics. If it were > properly contracted generics produced only legal "Ada proper" programs. > >> The fact that the instance body is guaranteed to be legal doesn't >> mean that it will work properly! > > Yes, the same applies to non-generic subprograms. Properly typed arguments > do not guaranty it working. Legality does not imply correctness. > >> And there are a few cases where we >> deliberately "cheat" in the RM, by making something raise an exception >> in a generic, when it would normally be a legality rule. > > Conversion of errors into exceptions is an extremely bad idea. The same > fault is represented by dynamic pre-/pos-conditions, assertions, > accessibility checks, tag errors. But it's not feasible to catch all errors statically. If you made a rule that all preconditions (for example) must be statically checked, that would simply mean lots of preconditions are inexpressible. I agree about accessibility checks -- I wish those were always static. - Bob