1
- # Constrained Indefinite Arrays RFC
1
+ # Definite Unconstrained Arrays RFC
2
2
3
3
## Summary
4
4
@@ -7,15 +7,32 @@ with a static maximum size but still use them as if they were unconstrained.
7
7
8
8
An array defined with
9
9
``` Ada
10
- type Index is range 0 .. 32 ;
10
+ type Index is range 0 .. 7 ;
11
11
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 ;
14
14
```
15
15
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
+ ```
19
36
20
37
## Motivation
21
38
@@ -49,25 +66,30 @@ cannot use the `&` operator and slices easily.
49
66
50
67
## Reference Level Explanation
51
68
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.
53
75
54
76
## Syntax
55
77
56
78
No custom Syntax.
57
79
58
80
## Static Legality Rules
59
81
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.
62
84
63
85
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 `
65
87
modifier but with a reduced static size. If defined with a specific constrained
66
88
range it will behave the same way it does without that aspect.
67
89
68
90
## Operational Semantics
69
91
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
71
93
memory zone that has the maximum size of that array type.
72
94
When returned from a function they behave as constrained types and do not
73
95
require the secondary stack.
@@ -79,13 +101,7 @@ as they do for indefinite arrays.
79
101
* Whether there is a hard limit on the size of these arrays. Theoretically
80
102
an array with that aspect and the index type ` Long_Integer ` would be
81
103
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.
89
105
90
106
## Alternatives
91
107
0 commit comments