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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,67ca96c42837a9ca X-Google-Attributes: gid103376,public From: Robert Dewar Subject: Re: Getting GNAT to issue ARM error messages Date: 1999/04/20 Message-ID: <7fhvok$j5d$1@nnrp1.dejanews.com> X-Deja-AN: 468696230 References: <79oj1f$e8p$1@nnrp1.dejanews.com> <36c1c82d.1234350@news.pacbell.net> <7fgupd$n7e$1@nnrp1.dejanews.com> X-Http-Proxy: 1.0 x10.dejanews.com:80 (Squid/1.1.22) for client 205.232.38.14 Organization: Deja News - The Leader in Internet Discussion X-Article-Creation-Date: Tue Apr 20 13:34:12 1999 GMT Newsgroups: comp.lang.ada X-Http-User-Agent: Mozilla/4.04 [en] (OS/2; I) Date: 1999-04-20T00:00:00+00:00 List-Id: > A paragraph, AARM ref. and any other info is always good > - if it does NOT > obscure the helpful message whcih the compiler should > give, and which GNAT most often does give. This is the "do no harm" approach, but for me the criterion is "do good". In other words, your idea that extra information is always useful if it does not obscure things is not good enough for me, I would add the criterion that it must be helpful for a significant number of people. Yes, I see some utility in using the compiler to try to teach people to read the RM, but that is certainly not the intention of the error messages from GNAT. The intention is to point out the error in a clear way that allows you to correct it as easily as possible. The example you chose seems a case where the GNAT error message is indeed completely clear from this point of view. Now if you want to ask the question of where this rule is in the RM, I agree that a tool of some kind that would lead to rules can *sometimes* be useful -- I say sometimes because often the source of the rule is not helpful (of course in this case 3.8.1 is a complete red herring as I assume you meant to make clear by your example). The trouble with putting an RM reference where it is not needed is that it tends to waste people's time by sending them off to look at the RM just to check they understand things. Let's take this case. The proper reference is of course 3.8(9), and the trouble with this reference is that it is too course, only the last sentence is interesting: "The identifiers of all components of a record type shall be distinct" Which provides little or no illumination beyond the original error message. Yes, the reference to the last sentence of 3.8(9) is of value if your specific purpose is to know where a particular rule came from, but the number of people who are interested in this is small. Most people just want to fix their program so it works. Most certainly I would NOT encourage beginning students of Ada to spend time reading chapter three of the RM, and most experts would find the 3.8(9) reference gratuitous in any case. I do think it would be nice to have a tool that gave all sorts of references on error messages to text books, the RM, the AARM, relevant AI's (perhaps the most important source of all in practice), etc. And one day maybe there will be such a tool, but meanwhile, I see little point in adding RM references in the case of simple rules, where the error message clearly implies the rule, and the RM does no more than confirm that the rule exists. The time that RM references are useful, and the time that GNAT includes them, is when the rule involved is obscure. For example: 1. with Text_IO; use Text_IO; 2. procedure z is 3. type a is record b : integer := 2; end record; 4. 5. x : integer; 6. 7. v : a; 8. for v'address use x'address; | >>> warning: implicit initialization of "v" may modify "x", use pragma Import for "v" to suppress initialization (RM B(24)) 10. begin 11. Put_Line ("Hello"); 12. end; Now here is a case of a rule which is a surprise to many expert Ada programmers (especially because it is a new rule in Ada 95, the above program is of course erroneous in Ada 83). It seems quite useful to refer to the RM to explain *why* we suggest adding the pragma Import. The RM paragraph says: 24 The declaration of an imported object shall not include an explicit initialization expression. Default initializations are not performed. Hopefully these two examples make the viewpoint clear. It is incidentally often the case that when people have suggested an RM reference, they choose the wrong place in the RM. They try, as in the message to which this is answering, to suggest some helpful general section in the RM that unfortunately has nothing to do with the case. Let's take another example. Suppose we write: for J in 1 .. 10 loop ... J := J - 1; end loop; The GNAT message is: 4. J := J - 1; | >>> assignment to loop parameter not allowed That's pretty clear. Now let's try to give an RM reference. Well we could reference the note in 5.5(10), but notes are not part of the standard, and so this is a bit dubious (by the way, that note is there in the RM because Robert Dewar complained that otherwise the source of this rule is hard to find!) The real rule is from 3.3(13): 13 An object is either a constant object or a variable object. The value of a constant object cannot be changed between its initialization and its finalization, whereas the value of a variable object can be changed. Similarly, a view of an object is either a constant or a variable. All views of a constant object are constant. A constant view of a variable objectcannot be used to modify the value of the variable. The terms constant and variable by themselves refer to constant and variable views of objects. Here again, we have an overkill problem with a simple paragraph reference, since it is really only the second sentence here that is relevant. Note that if we had pointed to the note, the situation would be even worse, since the note leads to the *whole* of 3.3, even more overkill. Of course we also need 3.3(2,6): 2 All of the following are objects: 6 a loop parameter; And of course 3.3(15,19) 15 Whether a view of an object is constant or variable is determined by the definition of the view. The following (and no others) represent constants: 19 a loop parameter, choice parameter, or entry index; So we could perhaps give as the error message: >>> assignment to loop parameter not allowed (RM 3.3 (2,6,15,19) + 3.3 (13, 2nd sentence) Now this message would indeed be helpful to the small minority (probably a larger minority on CLA) of people who specifically want to answer the question of where this rule comes from in the RM, but to 99% of the users of the compiler, the RM references here add nothing at all since the error message states the rule in a complete and much more accessible form. Indeed the mumbling about views in the above references will confuse all but the most experienced Ada programmers. This seems the most common case. Indeed a simple RM reference is almost never sufficient if your question is "why is this illegal, what exactly is the RM argument that makes this illegal". Instead you need an analysis similar to the above. Basically a theorem must be proved, and the axioms and reasoning for proving the theorem will involve several RM references. As I have said before, I see a definite utility in such a tool for the small number of people who like to nose around the RM (*), but for most people using the compiler this tool would not be helpful, and the priority in GNAT is in working on crafting the error messages so that neither students nor experts have to run away to the RM to understand how to fix their programs :-) Robert Dewar Ada Core Technologies (*) if you are an RM explorer, I strongly suggest carefully reading the AI's that are publicly available. First you will learn interesting things, second reading these is very good training in learning how to become a language lawyer certified as a competent RM reader :-) -----------== Posted via Deja News, The Discussion Network ==---------- http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own