To: J3 J3/24-172 From: Malcolm Cohen Subject: Formal Requirements DIN-4X: Accessing assumed-rank Date: 2024-October-21 Reference: 24-136r1 1. Introduction This paper proposes formal requirements for DIN-4X, the proposal for allowing direct access to elements of an assumed-rank argument. There is also mention of the traversal part of this in US-07 (23-184r1) and US-24 (24-143). 2. Overview There are two parts to this, viz accessing and traversing. Syntax and semantics for one or both needs to be developed. 3. Technical issues (a) We already have rank-independent syntax for array element accesses, via providing a vector of the subscript values. It would be straightforward to use this syntax for assumed rank, but has the distinct disadvantage of introducing a new kind of runtime error, as the rank, and thus the size of the vector, can never be checked at compile time. Possible solutions are: (a1) Re-use the syntax, but specify that if the rank is not equal to the size of the subscript vector, error termination is initiated. (a2) Re-use the syntax, but leave it up to the compiler writer to decide whether to error-terminate or produce silent wrong answers. (a3) Use an optional syntax that allows catching rank errors, similar to how we handle accessing values on failed images. If the syntax is not used, error termination. (a4) Ditto, but if the syntax is not used, maybe silent wrong answers. (a5) Use a non-optional syntax for catching rank errors. (a6) Forget the whole idea, as it is too error-prone. At this time, there are few if any convincing use cases for accessing random elements of an assumed rank array, so solution (a6) is recommended. If more use cases come to light, solution (a3) appears to most worthy of investigation. (b) We also already have rank-independent syntax for constructing array sections. At this time, multiple-subscript-triplets have constant size, so the rank would be known at compile time. This has all the problems of array element designation, plus if we allowed the rank to vary, it would introduce a new class of (rather complicated) assumed-rank objects. This could be expensive to implement and would certainly be difficult to design and describe. As this seems even more problematic and with a worse cost-benefit ratio than array element accessing, permitting array sections of assumed-rank objects is not recommended at this time. IF (very big if) we had "deferred-rank" pointers, this functionality could follow, and a clean design of that functionality in a future revision would likely produce a better feature. That is another argument for not rushing in to a partial feature now. (c) There are various proposals for rank-independent looping, particularly with a view towards better handling of generic rank as well as assumed rank. The most simplistic of these is merely a "vector DO", and so useless for assumed rank without direct array subscripting. 4. Formal requirements (XR-1) That direct array element subscripting of assumed rank not be pursued at this point in time. (XR-2) That array sectioning of assumed rank not be pursued at this point in time. (XR-3) That development of array traversal of assumed rank be deferred to US-24 "rank-independent looping". That proposal needs to consider the safety and usability with assumed rank. If US-24 development does not produce something suitable for assumed rank, this sub-task should be reactivated at that time. ===END===