I'm developing a DBMS (database management software) completely in Ada and DSA. But I've encountered some problem; rows are implemented as documents (MongoDB-style), and they're a protected interface, then implemented in the same package as a protected type. I had to make it an interface first so it would be possible to have a remote access type for it (protected types canNOT have remote access types, for they are not tagged). I'm getting the same messages for all functions being overrode (but not procedures):
safira-documents.ads:845:27: illegal overriding of subprogram inherited from interface
safira-documents.ads:845:27: first formal of "Is_Version_Controlled" declared at line 737 must be of mode "in" or access-to-constant
safira-documents.ads:856:27: illegal overriding of subprogram inherited from interface
safira-documents.ads:856:27: first formal of "Get_Contents" declared at line 753 must be of mode "in" or access-to-constant
safira-documents.ads:861:27: illegal overriding of subprogram inherited from interface
safira-documents.ads:861:27: first formal of "Get_Version" declared at line 760 must be of mode "in" or access-to-constant
safira-documents.ads:880:27: illegal overriding of subprogram inherited from interface
safira-documents.ads:880:27: first formal of "Has_Key" declared at line 785 must be of mode "in" or access-to-constant
safira-documents.ads:888:27: illegal overriding of subprogram inherited from interface
safira-documents.ads:888:27: first formal of "Get_Value" declared at line 795 must be of mode "in" or access-to-constant
safira-documents.ads:900:27: illegal overriding of subprogram inherited from interface
safira-documents.ads:900:27: first formal of "Get_Id" declared at line 810 must be of mode "in" or access-to-constant
safira-documents.ads:902:27: illegal overriding of subprogram inherited from interface
safira-documents.ads:902:27: first formal of "Get_Location" declared at line 812 must be of mode "in" or access-to-constant
safira-documents.ads:904:27: illegal overriding of subprogram inherited from interface
safira-documents.ads:904:27: first formal of "Database" declared at line 816 must be of mode "in" or access-to-constant
safira-documents.ads:906:27: illegal overriding of subprogram inherited from interface
safira-documents.ads:906:27: first formal of "Collection" declared at line 820 must be of mode "in" or access-to-constant
safira-documents.ads:908:27: illegal overriding of subprogram inherited from interface
safira-documents.ads:908:27: first formal of "Get_Creation_Time_As_Dictionary" declared at line 824 must be of mode "in" or access-to-constant
safira-documents.ads:911:27: illegal overriding of subprogram inherited from interface
safira-documents.ads:911:27: first formal of "Get_Last_Update_Time_As_Dictionary" declared at line 828 must be of mode "in" or access-to-constant
gprbuild: *** compilation phase failed
The relevant code is this:
package Safira.Documents with Remote_Types, Spark_Mode => On, Elaborate_Body is
type Update_Value_Operation is
access procedure
(K : in Key;
V : in out Value);
type Base_Document is protected interface;
-- Documents live in Storage_Nodes only. Clients access them through remote
-- access types.
-- This allows them to be declared as protected types with trustworthy atomic
-- operations that won't corrupt their content.
type Base_Document_Xs is access all Base_Document'Class;
-- << Many subprograms for the interface here >>
protected type Document is new Base_Document with
overriding function Is_Version_Controlled return Boolean;
overriding procedure Set_Mirror
(N : in Nodename_String.Bounded_String);
overriding procedure Remove_From_Mirror
(N : in Nodename_String.Bounded_String);
overriding procedure Set_Contents
(D : in Dictionary'Class);
overriding function Get_Contents return Dictionary'Class;
overriding procedure Revert_To
(Version : in Document_Version);
overriding function Get_Version
(Version : in Document_Version)
return Dictionary'Class;
overriding procedure Delete_Version
(Version : in Document_Version);
overriding procedure Define_New_Origin
(From : in Document_Version);
overriding procedure Delete_Entire_History;
overriding procedure Clone_From
(Origin : access Document);
overriding procedure Clone_From
(Origin : access Document;
Version : in Document_Version);
overriding function Has_Key
(K : in Key)
return Boolean;
overriding procedure Set_Value
(K : in Key;
V : in Value'Class);
overriding function Get_Value
(K : in Key)
return Value'Class;
overriding procedure Update_Value
(K : in Key;
V : in Value'Class);
overriding procedure Update_Value
(K : in Key;
Op : in Update_Value_Operation);
overriding function Get_Id return Document_Id;
overriding function Get_Location return Nodename_String.Bounded_String;
overriding function Database return Blueprint_String.Bounded_String;
overriding function Collection return Blueprint_String.Bounded_String;
overriding function Get_Creation_Time_As_Dictionary
return Dictionary'Class;
overriding function Get_Last_Update_Time_As_Dictionary
return Dictionary'Class;
private
Contents : Dictionary;
end Document;
end Safira.Documents;
Turning those access
parameters into in
ones in the interface's spec (apparently) fixes the problem. But I don't know if this will break the remote functionality. All Remote_Types examples I could find in the internet used access parameters for remote types' methods.
Apparently, the interface's functions expect an access to constant argument (i.e. actual parameter), I didn't ask for it, so I'm sure this is some Ada default security/safety feature.
Now... Can I just change the access
parameters to in
ones without breaking the remote functionality? If not, is there any way to avoid this default behavior (in other words, make them access to variable parameters)?
All examples I found for Remote_Types used access
parameters, so I'm afraid my solution of turning them into in
parameters could make them normal (non-remote) methods, which would render this package useless as a Remote_Types in a distributed application. I could try to make it Pure, but don't know if that could be done easily.
P.S.: It's supposed to be open-sourced in the future (when it's ready), so if I really need to, I can publish the whole file or the whole project now. I don't like to publish my projects before they're ready, but if it's necessary in order for someone to find a solution for this... I'll do it.