Ada-Rapporteur-Group / User-Community-Input

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

Potentially confusing definition of "declarative region" in #42

Closed sttaft closed 11 months ago

sttaft commented 1 year ago

Recently a customer complained that the definition of declarative region in RM 8.1 was unclear:

For each of the following constructs, there is a portion of the program text called its declarative region, within which nested declarations can occur:

  • any declaration, other than that of an enumeration type, that is not a completion of a previous declaration;
  • . . .
  • an exception_handler.

The declarative region includes the text of the construct together with additional text determined (recursively), as follows: . . . A declaration occurs immediately within a declarative region if this region is the innermost declarative region that encloses the declaration (the immediately enclosing declarative region), not counting the declarative region (if any) associated with the declaration itself.

This wording is very old, and I'll admit I have not reviewed it in 25 years or more. His complaint is that the phrase "within which nested declarations can occur" is confusing, since it made him think that the declarative region contains only places where declarations can occur. He was trying to understand exactly what code a pragma Suppress applies to, and that is defined in terms of declarative regions.

The most important part of the definition of declarative region is probably from the middle paragraph of the above, namely "...includes the text of the construct...".

It is arguable that the "within which nested declarations can occur" is not helping understanding, and can be confusing if it is seen as restrictive in some sense. Here is a possible alternative:

For each of the following constructs, there is a portion of the program text called its declarative region: . . . The declarative region includes the text of the construct together with additional text determined (recursively), as follows: . . . Nested declarations can occur within a declarative region. A declaration occurs immediately within a declarative region if this region is the innermost declarative region that encloses the declaration (the immediately enclosing declarative region), not counting the declarative region (if any) associated with the declaration itself.

It is certainly not clear any change is required, but I will admit when I went back and read these paragraphs, I completely missed the key phrase saying the "declarative region includes the text of the construct ...", and so I can see how the customer might have interpreted the initial phrase saying "within which nested declarations can occur" would be interpreted as definitional.

ARG-Editor commented 1 year ago

I've repeatedly been confused reading this section. I recently re-read it when working on AI22-0062-1 and was again confused enough by what it meant that I finally decided to assume the existing wording for current instance and thus designed similar wording for the new case -- rather than actually figuring out what was going on.

So I'd welcome a rewording of this text. Not sure if anything could really make it clearer, but it wouldn't hurt to try.

Randy
sttaft commented 1 year ago

I did suggest a rewording. Any opinion about that suggestion?

ARG-Editor commented 1 year ago

I doubt it would have helped me. I was trying to figure out exactly what is contained in declarative regions in which one can directly refer to the name of a component. But the question was too general to be answered in a reasonable way, and the detailed wording didn't really help (there are too many cases to be able to come up with any general answer). And I don't remember precisely what problem I was worried about anymore; probably the wording I was working on wanted to refer to the declarative region of something and I was trying to figure out if that was right.

I note that AARM 8.1(12.a) makes it clear that the declarative regions that are defined are those that allow the declaration of nested declarations. Constructs that don't have some sort of nested declaration (implicit or explicit) don't define a declarative region. I suspect that is what the remark that caused the confusion was for, and it seems that you lost that in your rewriting. Maybe it is best to lose it and just mention it in the AARM (and is it still true? dunno). But it is necessary to explain why this diverse set of constructs have declarative regions, and other, similar constructs don't define them.

I think it would help to have a better explanation of what a declarative region is. The existing phrase that you removed was too brief to do that (and thus added confusion). Perhaps it would help to say something after the list of constructs:

Constructs that define a declarative region are those that can have (implicit or explicit) nested declarations.

Probably one would mark the above "Redundant". Or we could combine that with the new sentence you suggested? Perhaps one could put this first, before the list of constructs? Not sure what would be best here.

                        Randy.
sttaft commented 1 year ago

How about:

For each of the following constructs, there is a portion of the program text called its declarative region: . . . The declarative region includes the text of the construct together with additional text determined (recursively), as follows: . . . The declarative region of a construct is where nested declarations can occur. A nested declaration occurs immediately within a declarative region if this region is the innermost declarative region that encloses the declaration (the immediately enclosing declarative region), not counting the declarative region (if any) associated with the declaration itself.

ARG-Editor commented 11 months ago

This issue is addressed in AI22-0080-1 (which will be available shortly).

ARG-Editor commented 11 months ago

The ARG approved AI22-0080-1 at meeting #63A, so this issue has been closed.