CVS difference for ai12s/ai12-0075-1.txt

Differences between 1.12 and version 1.13
Log of other versions for file ai12s/ai12-0075-1.txt

--- ai12s/ai12-0075-1.txt	2018/04/07 06:17:22	1.12
+++ ai12s/ai12-0075-1.txt	2018/04/27 04:35:48	1.13
@@ -1,4 +1,4 @@
-!standard 4.9(21)                                  18-04-06    AI12-0075-1/09
+!standard 4.9(21)                                  18-04-26    AI12-0075-1/10
 !standard 6.8(3/4)
 !standard 6.8(5/4)
 !standard 6.8(6/4)
@@ -28,7 +28,8 @@
 
 !proposal
 
-(See summary.)
+The aspect Static is introduced. It can only be applied to expression functions
+and ensures that the expression function can be evaluated statically.
 
 !wording
 
@@ -40,11 +41,11 @@
 
   AARM Discussion:
   The preceding "statically unevaluated" rule allows
-       X : constant := (if True then 37 else (1 / 0))
+       X : constant := (if True then 37 else (1 / 0)); -- OK.
   but does not allow
        function If_Then_Else (Flag : Boolean; X, Y : Integer) return Integer is
           (if Flag then X else Y) with Static; -- see 6.8
-       X : constant := If_Then_Else (True, 37, 1 / 0);
+       X : constant := If_Then_Else (True, 37, 1 / 0); -- Error.
   because evaluation of a function call includes evaluation of
   all of its actual parameters.
 
@@ -162,6 +163,36 @@
 
    c) an expression function which is subject to a type invariant is
       never a static function.
+
+We use aspect Static to declare static expression functions, as it is unsafe for
+a function to change from being non-static to static (or the reverse). Such a
+change can cause code to change results or even be illegal - especially a
+problem for existing Ada 2012 code where automatically determining staticness
+can cause compatibility problems.
+
+Specifically: 
+
+   * whether or not an expression is static potentially changes legality of
+     the expression. There are three known ways for an expression function
+     call to change the legality of an expression depending on whether or
+     not the function is considered static. Explicitly declaring static
+     functions means that the legality of uses far way don't change due to
+     simple maintenance changes, and the legality of existing code doesn't
+     change simply by compiling in Ada 2020 mode rather than Ada 2012 mode.
+
+   * the value of a real static expression is likely to be different than
+     the value of the equivalent non-static expression (exact evaluation can
+     give a different answer than runtime evaluation, even after rounding).
+     Changing from one to the other can break careful numerical analysis;
+     doing so implicitly could cause significant problems. Making staticness
+     part of the function declaration avoids this problem.
+
+   * if staticness was determined automatically, it could depend on the view
+     of the function as to whether it is known to be static and thus whether
+     the expression it is used in is static. Deferred constants, for instance
+     can be nonstatic in the visible part and static in the private part/body.
+     That would be horribly confusing, thus determining it when the function
+     is declared with aspect Static is preferable.
 
 !example
 

Questions? Ask the ACAA Technical Agent