Ada-Rapporteur-Group / User-Community-Input

Ada User Community Input Working Group - Github Mirror Prototype
27 stars 1 forks source link

Valid_Scalars or equivalent attribute worth standardizing #14

Open sttaft opened 2 years ago

sttaft commented 2 years ago

An attribute to check the validity of records would be valuable to have in the language, especially when exchanging records via streaming (before 'Write/'Output, or after 'Read/'Input, or even inside custom streaming procedures), and when exchanging data across a language boundary.

AdaCore already has a custom attribute for this purpose: 'Valid_Scalars, but it's only available in GNAT. The documentation for the attribute says that it 'can generate a lot of code'... but the alternative is the developer writing a lot of code (literally writing a 'Valid check on every part of a record, and taking some action based on the result. That option isn't even available if the record is private without implementing an additional function.

An unexpected false might result in writing some of that very code to get more details when debugging, but an attribute like 'Valid_Scalars can nonetheless be invaluable for identifying when a record contains invalid data - especially from inside a generic, where the specific type is not known, and can be used to help ensure invalid data doesn't propagate across an interface where the problem will be harder to diagnose.


AdaCore's 'Valid_Scalars attribute is a good solution for this problem. Alternately, the scope of the existing 'Valid attribute itself could be expanded to include records, just like 'Image now includes records and formerly did not.

Joshua Fletcher, fletcher.ua@gmail.com, 6/27/2022 12:36:54

ARG-Editor commented 4 months ago

AI22-0101-1 has been created for this issue.