Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SPARK instantiation error w.r.t. volatile type

I have a data structure approximately (I am unable to share the full source but can provide additional information on request) as follows:

generic
    type Item_Type is private;
package Util.Pool is
    type Pool is limited new Ada.Finalization.Limited_Controlled with private;

    procedure Get_Available (From: in out Pool; Available: out Natural);
    overriding procedure Finalize (Object: in out Pool);
private
    type Item_Array is array (Positive range <>) of Item_Type;
    type Item_Array_Access is access all Item_Array;

    Null_Item_Array: constant Item_Array_Access := null;

    protected type Protected_Pool is
        function Get_Available return Natural;
    private
        Available: Natural := 0;
        Items: Item_Array_Access := Null_Item_Array;
    end Protected_Pool;

    type Pool is limited new Ada.Finalization.Limited_Controlled with record
        List: Protected_Pool;
    end record;
end Util.Pool;

The full code compiles without errors and warnings but the SPARK prove step fails with the following:

gnatprove -PX:\Path\To\project.gpr -j0 --mode=flow --ide-progress-bar -u main.adb
Phase 1 of 2: generation of Global contracts ...
main.adb:11:05: instantiation error at util-pool.ads:34
main.adb:11:05: effectively volatile type "Protected_Pool" must be declared at library level (SPARK RM 7.1.3(3))
main.adb:11:05: instantiation error at util-pool.ads:45
main.adb:11:05: component "List" of non-volatile type "Pool" cannot be volatile
gnatprove: error during generation of Global contracts

I have read the corresponding parts of the SPARK manual but I fail to understand how to fix my code according to them. TIA.

like image 991
Arets Paeglis Avatar asked Mar 02 '23 22:03

Arets Paeglis


1 Answers

Looks as though you’re instantiating the generic within your Main. This is not 'at library level'.

Instantiate as a library level package, should work better. This needs to go in a file (in this case) my_util_pool.ads:

with Util.Pool;
package My_Util_Pool is new Util.Pool (Integer);

main.adb now starts

with My_Util_Pool;
with ...;
procedure Main is
   ...
like image 169
Simon Wright Avatar answered Mar 10 '23 09:03

Simon Wright