Skip to content

Commit a2c998f

Browse files
committed
Rename to definite constrained arrays, improve example, clarify behavior
1 parent 9907edb commit a2c998f

File tree

1 file changed

+35
-19
lines changed

1 file changed

+35
-19
lines changed

considered/constrained_indefinite_arrays.md renamed to considered/definite_unconstrained_arrays.md

+35-19
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Constrained Indefinite Arrays RFC
1+
# Definite Unconstrained Arrays RFC
22

33
## Summary
44

@@ -7,15 +7,32 @@ with a static maximum size but still use them as if they were unconstrained.
77

88
An array defined with
99
```Ada
10-
type Index is range 0 .. 32;
10+
type Index is range 0 .. 7;
1111
12-
type Static_Array is array (Index range <>) of Element with
13-
Constrained;
12+
type Static_Array is array (Index range <>) of Natural with
13+
Definite;
1414
```
1515

16-
Adding the aspect `Constrained` will force the compiler to always reserve
17-
enough space to fit every possible range of an object of this type without
18-
changing the high level behaviour of the type.
16+
Adding the aspect `Definite` will force the compiler to always reserve
17+
enough space to fit every possible range of an object of this type. As the
18+
possible range for this array is preallocated objects of that type can be
19+
resized.
20+
21+
```Ada
22+
declare
23+
subtype Static_Subtype is Static_Array (1 .. 3);
24+
A : Static_Array := (1, 2, 3, 4);
25+
B : Static_Array := (2, 3);
26+
S : Static_Subtype := (1, 2, 3);
27+
begin
28+
A := B;
29+
A := A & S;
30+
A := A & (8, 9);
31+
pragma Assert (A'Capcity = 8);
32+
A := (0, 1, 2, 3, 4, 5, 6, 7, 8); -- forbidden as it exceeds the array capacity
33+
S := (1, 2); -- forbidden as Static_Subtype is a constrained array
34+
end;
35+
```
1936

2037
## Motivation
2138

@@ -49,25 +66,30 @@ cannot use the `&` operator and slices easily.
4966

5067
## Reference Level Explanation
5168

52-
A new aspect `Constrained` is added.
69+
A new aspect `Definite` is added. An array declared with this aspect is
70+
resizable within its index type boundaries. Assignments of slices that do not
71+
fit the original length of that array are allowed.
72+
73+
Additionally objects of that type have the `'Capacity` attribute that returns
74+
the maximum number of elements the object can hold.
5375

5476
## Syntax
5577

5678
No custom Syntax.
5779

5880
## Static Legality Rules
5981

60-
`Constrained` can only be added to array declarations that would create an
61-
indefinite array. It can be used on both types and subtypes.
82+
`Definite` can only be added to array declarations that would create an
83+
unconstrained array. It can be used on both types and subtypes.
6284

6385
A subtype of a constrained array has the same behaviour as a subtype to a
64-
regular array. If defined as indefinite, it will keep the `Constrained`
86+
regular array. If defined as unconstrained, it will keep the `Definite`
6587
modifier but with a reduced static size. If defined with a specific constrained
6688
range it will behave the same way it does without that aspect.
6789

6890
## Operational Semantics
6991

70-
Objects of an array type declared with `Constrained` will always be stored in a
92+
Objects of an array type declared with `Definite` will always be stored in a
7193
memory zone that has the maximum size of that array type.
7294
When returned from a function they behave as constrained types and do not
7395
require the secondary stack.
@@ -79,13 +101,7 @@ as they do for indefinite arrays.
79101
* Whether there is a hard limit on the size of these arrays. Theoretically
80102
an array with that aspect and the index type `Long_Integer` would be
81103
2 ***** 64 * element size bytes large.
82-
* Whether `Constrained` is a good name for that aspect.
83-
* Whether the behaviour of arrays with this aspect is different from regular arrays.
84-
Assignments to regular arrays must have the same size as the current contents
85-
of that array. As contrained arrays have their maximum possible size allocated
86-
in memory it is possible to assign them values of different lengths or append
87-
additional elements with the `&` operator. Both operations must not exceed the
88-
maximum size of the array type.
104+
* Whether `Definite` is a good name for that aspect.
89105

90106
## Alternatives
91107

0 commit comments

Comments
 (0)