CVS difference for ais/ai-00269.txt

Differences between 1.4 and version 1.5
Log of other versions for file ais/ai-00269.txt

--- ais/ai-00269.txt	2001/09/22 01:18:08	1.4
+++ ais/ai-00269.txt	2004/07/31 04:28:12	1.5
@@ -1301,3 +1301,206 @@
 
 ****************************************************************
 
+From: Gary Dismukes
+Sent: Thursday, July 29, 2004  7:31 PM
+
+A question has come up with GNAT's treatment of static expressions.
+I think there may be an RM issue here, but before bothering to write
+up a formal comment I want to see what other ARG members think about
+the legality of some declarations.
+
+First assume types declared as:
+
+    type Some_Range is range 1 .. 30_000;
+
+    type Some_Type is array (1 .. 15_000) of Integer;
+
+and assume that Some_Range has base range -32_768 .. 32_767.
+
+Now consider the following declarations:
+
+    type Some_Int is range 1 .. Some_Range'Last * 2;
+
+    Some_Const : constant := Some_Range'Last * 2;
+
+    for Some_Type'Size use Some_Range'Last * 2;
+
+Preferably without first looking at the RM, decide for each
+of the above three declarations whether the static expression
+it contains is legal or illegal.  This is not really intended
+as a trick question, I just want to find out what people's
+intuitions are here.  It's fine if you then want to check
+the RM and revise any of your answers.  (By the way, my opinion
+is that GNAT currently gives the wrong answer for at least one
+of these declarations.)
+
+****************************************************************
+
+From: Randy Brukardt
+Sent: Thursday, July 29, 2004  8:10 PM
+
+OK, I'll bite. Clearly Some_Range'Last is static, and since static
+expressions are evaluated exactly, and all of these contexts are
+universal_integer contexts, I would expect them all to be legal.
+
+> It's fine if you then want to check
+> the RM and revise any of your answers.  (By the way, my opinion
+> is that GNAT currently gives the wrong answer for at least one
+> of these declarations.)
+
+Of course, that's not quite right. The contexts for the first and last are
+"any integer type". The middle context is universal_integer. But that
+doesn't matter. What does matter (something I realized before responding
+above) is that the multiply has type Some_Range. That is a value of 60,000,
+which is outside of the base range. But wait! There's an exception depending
+on the expected type. So does that apply or not when the expected type is
+"any integer type"? Dunno, but it hardly makes sense to make these cases
+illegal.
+
+Reprise:
+> I think there may be an RM issue here, but before bothering to write
+> up a formal comment I want to see what other ARG members think about
+> the legality of some declarations.
+
+Well, AI-269 needs to rewrite parts of 4.9 anyway, because its seriously
+screwed up for generics. That was the *only* AI that wasn't revised in time
+for the Palma meeting. *Everyone* one else got their homework done on time.
+That AI was assigned to one Gary Dismukes, who ruined an otherwise perfect
+record (children are no excuse! :-) :-). Anyway, given that you're going to
+be rewriting that section anyway, I suggest just adding any other changes to
+the same AI. That will save me work, and avoid future problems trying to
+merge the changes.
+
+Aside: As always, you can check your homework by putting your last name
+after the HTML minutes URL. For Gary's homework, for instance, use the URL
+   http://www.ada-auth.org/ai-files/minutes/min-0406.html#Dismukes.
+
+****************************************************************
+
+From: Robert A Duff
+Sent: Thursday, July 29, 2004  8:34 PM
+
+...
+>     type Some_Range is range 1 .. 30_000;
+>
+>     type Some_Type is array (1 .. 15_000) of Integer;
+
+OK.
+
+> and assume that Some_Range has base range -32_768 .. 32_767.
+
+OK, but I don't see how that's relevant to the questions below.
+
+> Now consider the following declarations:
+>
+>     type Some_Int is range 1 .. Some_Range'Last * 2;
+>
+>     Some_Const : constant := Some_Range'Last * 2;
+
+Above two are legal.
+
+>     for Some_Type'Size use Some_Range'Last * 2;
+
+Well, I see nothing wrong with the static expression
+"Some_Range'Last * 2" itself, but you can't fit 15,000
+Integers in 60,000 bits, so I guess the rep clause is
+illegal.  (Unless Integer'Size is <=4, but I think it's required
+to be at least 16.)
+
+> Preferably without first looking at the RM,...
+
+OK, I haven't looked at the RM in at least a week.
+
+>.. decide for each
+> of the above three declarations whether the static expression
+> it contains is legal or illegal.  This is not really intended
+> as a trick question, I just want to find out what people's
+> intuitions are here.  It's fine if you then want to check
+> the RM and revise any of your answers.
+
+Umm.  I thought I had the doggone thing memorized.  ;-)
+Should I go look now?
+
+>...(By the way, my opinion
+> is that GNAT currently gives the wrong answer for at least one
+> of these declarations.)
+
+Where's the trick?  Seems obvious to me (but I didn't look at
+the RM, so I could be surprised!).
+
+****************************************************************
+
+From: Robert Dewar
+Sent: Thursday, July 29, 2004  8:43 PM
+
+I agree that the clear intention is that all these cases
+be legal. To make some of them legal and some illegal
+would be a real peculiarity. So to me Dewar's special
+RM rule (*) applies here and they *are* all legal, even
+though a more straightforward reading of the RM may
+indicate otherwise :-)
+
+(*) No rule in this RM may be used to deduce an obviously
+incorrect result.
+
+****************************************************************
+
+From: Randy Brukardt
+Sent: Thursday, July 29, 2004  9:04 PM
+
+Bob wrote:
+
+> >...(By the way, my opinion
+> > is that GNAT currently gives the wrong answer for at least one
+> > of these declarations.)
+>
+> Where's the trick?  Seems obvious to me (but I didn't look at
+> the RM, so I could be surprised!).
+
+I think Gary is referring to 4.9(35) "If the expression is not part of a
+larger static expression, then its value shall be within the base range of
+its expected type." Which is why Gary specifically defined the base range.
+
+This begs the question of what the base range of "any numeric type" (for
+named numbers) and "any integer type" (for the integer type declaration) is
+(as those are the expected types). If you say that the expected type is
+Some_Range (which is certainly a reasonable interpretation), then both of
+those are illegal (because 60000 isn't in the base range). If you say it is
+anything (that is, universal_integer), you have to explain why you can use
+that.
+
+Probably the best thing is to apply Dewar's rule here (allowing it to be
+legal), and Gary can fix the wording while he is rewriting that anyway for
+AI-269.
+
+****************************************************************
+
+From: Tucker Taft
+Sent: Thursday, July 29, 2004  9:05 PM
+
+I agree with Randy that when "any integer type" is expected,
+we should treat this as equivalent to having universal_integer
+as the expected type, and that for the purposes of 4.9(35),
+the base range of universal_integer and for "any integer type"
+should be considered unbounded.
+
+It would seem worthwhile to revise 4.9(35) to make this explicit.
+As far as I know, we never define the base range of
+universal_integer, and I recommend we revise 4.9(35) so
+we don't need to.
+
+****************************************************************
+
+From: Robert A Duff
+Sent: Friday, July 30, 2004  9:55 AM
+
+I think the intent was thast "any integer type" means the same thing as
+"universal_integer".  (Also known as root_integer'Class, until a certain
+"scope reduction" meeting!)  I presume universal_integer has the same
+base range as root_integer, and that that base range is infinite.  I
+don't know if the RM says that, but it seems obviously true.
+
+Note that 4.9(35) is referring to the *expected* type.
+
+****************************************************************
+

Questions? Ask the ACAA Technical Agent