CVS difference for ai05s/ai05-0153-2.txt

Differences between 1.1 and version 1.2
Log of other versions for file ai05s/ai05-0153-2.txt

--- ai05s/ai05-0153-2.txt	2009/10/17 05:53:14	1.1
+++ ai05s/ai05-0153-2.txt	2009/10/18 03:09:36	1.2
@@ -4,12 +4,12 @@
 !status received 09-10-16
 !priority Medium
 !difficulty Medium
-!subject Discontiguous scalar constraints and partial discriminant constraints
+!subject Discontiguous scalar constraints and extended discriminant constraints
 
 !summary
 
-Add list scalar constraints and partial discriminant constraints
-to the language.
+Add list scalar constraints to the language, and extend the available discriminant
+constraints.
 
 !problem
 
@@ -193,16 +193,7 @@
 [Author's note: strictly speaking, we don't need to modify this sentence, as a scalar constraint
 with a list_constraint "has no range_constraint". But that's very tricky!]
 
-Replace 4.9.1(1.1/2):
-
- * both are static and:
-     - if scalar, each value that belongs to one also belongs to the other;
-     - else have equal corresponding bounds or discriminant values;
-
-AARM Ramification:
-   This means that list constraints and range constraints can be statically matching
-   of they define the same set of values. For instance range 1 .. 4 matches
-   when 1 | 2 | 3 | 4 as well as when 4 | 1 .. 2 | 3.
+[For 4.9.1(1.1/2), see below; it's modified by both parts here.]
 
 Add an AARM note after 5.4(7):
 
@@ -236,11 +227,114 @@
 End AARM Ramification.
 
 -------------------------
+
+Extended discriminant constraints:
+
+Modify 3.3.1(12):
+
+* The implicit initial (and only) value for each discriminant of a constrained discriminanted
+  subtype is determined by the subtype. {If the discriminant constraint defines a range or
+  subtype for the value of the discriminant, the lower bound of the range or subtype is used
+  as the initial value.}
+
+AARM Reason: A discriminant constraint that defines a range or list of acceptable discriminant
+values means that any value in the range or list is acceptable for that discriminant. We select
+the lower bound in order that programs are portable (although depending on that is dubious).
+
+Replace 3.7.1(3) by:
+
+   discriminant_association ::=
+      [discriminant_selector_name {|discriminant_selector_name} => discriminant_value
+
+   discriminant_value ::= expression | discrete_range
+
+[Editor's note: discrete_range includes subtype_indication, so it includes list
+constraints (which aren't a range, but changing the name of the non-terminal would
+be rather disruptive).]
+
+Modify 3.7.1(6):
+
+The expected type for the expression {or discrete_range} in a discriminant_association
+is that of the associated discriminant(s).
+
+Modify 3.7.1(8):
+
+...A discriminant_constraint shall provide exactly one value {or subtype} for each
+discriminant of the subtype being considered.
+
+Replace 3.7.1(10) with:
+
+A discriminant_constraint is *compatible* with an unconstrained discriminanted subtype if:
+
+* the value for each discriminant given by an expression belongs to the subtype of the corresponding
+  discriminant; and
+* the constraint of the subtype for each discriminant given by a discrete_range is compatible with
+  the subtype of the corresponding discriminant.
 
-Partial discriminant constraints:
+[Editor's note: Compatibility is only defined for constraints and ranges; we really want
+compatibility of subtypes here. Maybe there is a better way to write this, but there are really
+4 cases to worry about: subtype with range constraint, subtype with list constraint, subtype_mark
+alone, and range alone.]
 
+Replace 3.7.1(11) with
 
+A composite value satisfies a discriminant_constraint if and only if:
+* for each discriminant given by an expression in the discriminant_constraint, the discriminant
+  value has the value imposed by the discriminant constraint; and
+* for each discriminant given by a discrete_range in the discrminant_constraint, the discriminant
+  value belongs to the subtype or range imposed by the discriminant constraint.
 
+Modify 3.7.1(12):
+
+For the elaboration of a discriminant_constraint, the expressions {and discrete_ranges} in the
+discriminant_associations are evaluated in an arbitrary order and converted to the type of the
+associated discriminant (which might raise Constraint_Error  see 4.6); the expression of a
+named association is evaluated (and converted) once for each associated discriminant. The
+result of each evaluation and conversion is the value{, range, or subtype} imposed by the
+constraint for the associated discriminant. 
+
+[Editor's note: Although I find it weird, the "converted to the type of the discriminant" wording
+is used for discrete_choices in aggregates, from which discrete_ranges come. So I used the same
+wording here.]
+
+Modify 4.9(31):
+
+* A discriminant constraint is static if each expression {or discrete_range} of the constraint
+  is static, and the subtype of each discriminant is static.
+
+---
+
+For both changes:
+
+
+Replace 4.9.1(1.1/2):
+
+ * both are static and:
+     - if discrete, each value that belongs to one also belongs to the other;
+     - if real, each have equal lower bounds and equal upper bounds;
+     - if index constraints, have equal corresponding bounds;
+     - if discriminant constraints:
+          * for each discriminant given by an expression in one, the
+            the corresponding discriminant is also given by an expression and
+            the discriminant values are equal; and
+          * for each discriminant given by a discrete_range in one, the
+            the corresponding discriminant is also given by a discrete_range and
+            the constraints, ranges, or subtypes statically match.
+
+AARM Ramification:
+   The first bullet means that list constraints and range constraints can be
+   statically matching of they define the same set of values. For instance
+   range 1 .. 4 matches when 1 | 2 | 3 | 4 as well as when 4 | 1 .. 2 | 3.
+
+AARM Reason:
+   The rules for discriminant constraints are complex so that appropriate matching
+   can be applied to discrete_ranges. The rules imply that a value and range
+   with a single value do not match. For example:
+       Rec(2) does not match Rec(2..2).
+
+[Editor's note: I suppose we could have allowed this case, but it would have made
+the rules even more complicated.]
+
 !discussion
 
 If adopted, this proposal would replace AI05-0158-1, as the subtype_indications proposed
@@ -274,9 +368,28 @@
 
 ---
 
+An alternative semantics considered for extended discriminant constraints was for constraints
+with subtypes to be "partial constraints". A partial constraint would not make the subtype
+definite. However, that leads to additional complications not found in Ada 2005: constrained,
+indefinite subtypes. (Well, at least if you don't believe AI05-0057-1.)
+
+Since the model is that a constraint containing a subtype allows one of a set of discriminants,
+it makes sense that when an object is created using that constraint, a random value of the
+set is used to set the discriminants. We arbitrarily choose the first value simply so that
+the value chosen is the same on all compilers. This avoids the complications of new kinds
+of constraints (which would quickly spread to new kinds of generic matching rules, etc.).
+
+---
 
+We don't allow subtypes to specify discriminant values for discriminants that have an
+access type because there would be no obvious value to use for the discriminant if the
+constraint was used to declare an object. We could allow that if we had used the
+partial constraint model instead, but that would also mean that we couldn't use
+discrete_range in the syntax.
+
+---
 
---!corrigendum H.4(19)
+--!corrigendum 3.2.2(7)
 
 !ACATS test
 

Questions? Ask the ACAA Technical Agent