comp.lang.ada
 help / color / mirror / Atom feed
From: dewar@gnat.com (Robert Dewar)
Subject: Re: System.Address'Size - not a static integer expression?
Date: 9 Apr 2002 18:54:55 -0700
Date: 2002-04-10T01:54:55+00:00	[thread overview]
Message-ID: <5ee5b646.0204091754.5dcfd16d@posting.google.com> (raw)
In-Reply-To: 3CB1B473.CF6E93AD@despammed.com

Wes Groleau <wesgroleau@despammed.com> wrote in message news:<3CB1B473.CF6E93AD@despammed.com>...

> > > There's the justification:  'Size is sometimes
> > > non-static, and requiring a compiler to distinguish 
> > > when imposes too much complexity.

I assumed you meant by non-static here: not known at compile time
(otherwise the statement is nonsense, of COURSE an Ada compiler must
distinguish between static and
non-static expressions in the formal sense.

Also, you were replying to a message that said that 
Size was always non-static, and giving an (incorrect)
justification for this (incorrect) claim.

> I'll take your word for that, but the last time both Apex
> and GNAT rejected a 'Size that I knew was static (in the
> sense that it traced to a constant at compile time)

Please please do not misuse static in this way. An expression in Ada
is static if it meets the rules of
section 4.9. This is NOT the same as being able to
"trace to a constant at compile time". For example

    type r is record a : integer; end record;
    for r'size use 4;

Now of course we know at compile time that R'Size has
the value of 4, but please do NOT call it static, since
R'Size here is a non-static expression. Why? Because the
rules in 4.9 say that an attribute reference of this type
is static if an only if it applies to a static scalar
subtype (I quoted the rule in my previous post). 
    
> I found something in the RM that basically insisted that 
> 'Size is non-static.

Well since you are confused over what static means, I doubt
this memory is relevant. Once again, while it is true that
all static expressions have known-at-compile time values,
the converse is obviously false (known at compile time values are not
always static).

Why? Because it is obviously recursively undecidable whether a given
expression has a known at compile time
value (finding all such expressions requires being able
to prove all possible theorems which of course is not
possible). So the language had two choices:

 o Try to pin down a subset of known at compile time
   expressions and require all compilers to agree on
   this subset in cases where staticness of expressions
   has semantic significance (e.g. case tags).

 o Allow this set to be implementation defined, meaning
   that the legality (e.g. of case statements) would also
   be implementation defined.

Not hard to make a choice! Ada 83 and Ada 95 both chose the first
path, and that is what the rules in 4.9 are about (Ada 95 increased
the set of static expressions slightly).

So most certainly GNAT and Apex (and any other correct Ada compiler)
agree on what Size references are static and what
are not. If the prefix is a static scalar subtype, the size
reference is static, otherwise it is non-static. End of
story, and the fact that Wes can figure out that some particular
non-static case is in fact known at compile time
is not interesting or relevant.

In fact any decent Ada compiler will have internally a class of
expressions larger than static expressions which are recognized as
known at compile time.

Indeed I just did a significant enhancement to GNAT that
increases the number of such cases by doing value tracking.
Consider the following output from the latest development
version of GNAT Pro:

 1. procedure z is
 2.    x : integer;
 3.    y : integer range 3 .. 6;
 4. begin
 5.    x := 3;
 6.    x := x + 4;
 7.    y := x;
            |
 >>> warning: value not in range of subtype of         
     "Standard.Integer" defined at line 3
 >>> warning: "Constraint_Error" will be raised at run time
 8. end;


The warning comes from the fact that the expression x in
line 7, while most *certainly* not static, is in fact a
compile time known value (the value is 7), and the compiler can issue
a warning.


> 
> Perhaps I'll have time to hunt that down again this week.
> (Don't hold your breath)



  reply	other threads:[~2002-04-10  1:54 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-03-06 17:57 System.Address'Size - not a static integer expression? Vadim Godunko
2002-03-07  1:21 ` Robert Dewar
2002-03-07 13:56   ` Wes Groleau
2002-03-08 18:34     ` FGD
2002-03-08 19:07       ` Larry Kilgallen
2002-03-08 19:43       ` Wes Groleau
2002-04-08  4:57         ` Robert Dewar
2002-04-08 15:17           ` Wes Groleau
2002-04-10  1:54             ` Robert Dewar [this message]
2002-04-10 17:41               ` Wes Groleau
2002-04-10 18:29                 ` Darren New
2002-04-12 20:20                 ` Robert Dewar
2002-04-12 21:10                   ` Wes Groleau
2002-04-14 19:59                     ` Robert Dewar
2002-04-14 20:01                     ` Robert Dewar
2002-04-15 15:13                       ` Wes Groleau
2002-04-15 19:57                         ` Randy Brukardt
2002-04-17  3:22                           ` Robert Dewar
2002-04-17  3:11                         ` Robert Dewar
2002-04-17 18:27                           ` Wes Groleau
2002-04-19 14:06                             ` Robert Dewar
2002-04-19 15:05                               ` Wes Groleau
2002-04-20  2:26                                 ` Robert Dewar
2002-04-20  5:11                                 ` Robert Dewar
2002-04-20 16:50                                   ` Darren New
2002-04-22  9:20                                   ` Ole-Hjalmar Kristensen
2002-04-22 13:24                                     ` Robert Dewar
2002-04-22 13:59                                       ` Ole-Hjalmar Kristensen
2002-04-22 13:34                                     ` Robert Dewar
2002-04-22 14:02                                       ` Ole-Hjalmar Kristensen
2002-04-22 16:11                                         ` Jean-Pierre Rosen
2002-04-22 23:57                                         ` Robert Dewar
2002-04-08  0:43 ` Nick Roberts
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox