AdaCore/ada-spark-rfcs

[Question] Ada 202x container aggregates issue

Closed this issue · 8 comments

In ai12-0212-1 it's implied that "empty" constants (ie Empty_Vector, Empty_Set etc) should be functions now, but in current Ada 202x draft (Draft 21) they're still constants. I suspect this is not intentional. Is it a bug?

To clarify, here is an example (From the same AI) of Empty_Vector as a function:

--  A positional vector aggregate:
V := ["abc", "def"];
--  Is equivalent to:
V := Empty_Vector (2);
Append_One (V, "abc");
Append_One (V, "def");

So Empty_Vector function should act as Reserve_Capacity (at least that is how i understand it).

Sorry for not being clear. Yes, spec allows Empty for an Aggregate aspect to be constant or a function. But Ada containers were not changed to have "empty" functions. So the problem is not with container aggregates per se, but with Ada containers. For example in Vectors spec (A.18.2) there is no Empty_Vector function, although 4.3.5 examples show a Vector_Type (62/5) with Empty function. My understanding is that Empty_Vector function can be used to reserve memory space, similarly to Reserve_Capacity. If Empty_Vector is constant then on every append container is going to increase the vector capacity (177/2), which is not desirable for performance reasons.

AI12-0339 was approved at the recent ARG meeting in Warsaw in response to this issue.
It is not posted yet on the ARG website (which currently shows 337 as the most recently created AI), but it will show up when the changes from that recent meeting are posted.

Nice! I guess this issue can be closed then.

The AI has been approved as I understand it (http://www.ada-auth.org/cgi-bin/cvsweb.cgi/ai12s/ai12-0339-1.txt?rev=1.7), closing this issue. Thanks again!