J3/05-267 Date: 05 October 2005 To: J3 From: Richard Maine Subject: Rank remapping and contiguous This paper proposes an enhancement of pointer bounds remapping as an integration issue for the contiguous attribute feature. BACKGROUND F2003 allows bounds remapping in a pointer assignment statement, but such remapping is limited to rank 1 targets. Thus, it is allowed to have a pointer of rank 2 (or higher) with a target of rank 1, but it is not allowed to have a pointer of rank 1 with a target of rank 2. It is particularly irksome that this restriction even disallows reversing the effect of a remapping. For example, if we started with a rank 1 target and created a rank 2 pointer to it with p2(1:n,1:n) => target(1:n**2) we cannot get back to a rank 1 pointer from the rank 2 one. If we want a rank 1 pointer to target, we cannot do something like p1(1:n**2) => p2(1:n,1:n) but instead have to do p1 => target(1:n**2) which means that it isn't adequate to pass p2 around if one might need to get back to a rank 1 form. The only reason for the current restriction on remapping is that targets with rank other than 1 might have memory layouts that are not compatible with the descriptive capability of the usual pointer descriptors. One could describe various special cases that would work, but that can rapidly get complicated. However, by far the most common special case is when the target is contiguous. With the contiguous proposal, it is now simple to describe that case. The combination of being a commonly desired case and also being simple to describe translates directly into a good cost/benefit ratio for a feature. One of the common applications would involve procedure calls. Currently, if a procedure has an assumed-shape dummy argument of rank 1, there is no good way to use an array of any other rank with it. This sometimes forces the use of explicit-shape dummy arguments and sequence argument association in contexts where they are not otherwise desirable. Questions about how to address this problem are fairly common. I do not propose modifying anything about argument association rules. Such modifications can easily have subtle complications. However, with an appropriate pointer bounds-remapping capability, one could create a suitable pointer and use that pointer as an actual argument with no modification to the argument association rules. SPECIFICATION Allow a data pointer assignment statement to associate a pointer of any rank with a target of any rank, with the following restrictions. The target must either be of rank 1 or be contiguous. All other specifications are identical to the existing feature for bounds remapping, which this proposal enhances. Specifically, bounds remapping must be specified, must agree with the rank of the pointer object, and must have a size no greater than that of the target. Pointer assigment without bounds remapping is unaffected. SYNTAX There is no completely new syntax. Constraint C720 is relaxed to allow the target to be of any rank if it is contiguous. Because contiguity is not necessarily known at compilation time, that part of the constraint becomes a text restriction. As an alternative, this could be retained as a constraint if targets of rank greater than 1 were restricted to having the contiguous attribute. However, my initial proposal does not have that restriction. EDITS All edits here are relative to 04-007. In 7.4.2, Pointer assignment [143:21] in C720, change "is specified...otherwise" to "is not specified: In 7.4.2.1, Data pointer assignment [144:26] In the first line of the penultimate para of the section, before "shall", insert "shall be contiguous ([xref to the definition of contiguous]) or of rank one. It" In 7.4.2.3, Examples [145:First line of Note 7.44] Change "high-rank views of (parts of) rank-one objects" to "different-rank views of parts of an object" [145:Second line of Note 7.44] Insert the sentence "This requires that the object be either rank one or contiguous." After the first sentence of the note.