|
| 1 | +- Feature ID: mandatory_end_designator |
| 2 | +- Start Date: 2025-11-06 |
| 3 | +- Status: Proposed |
| 4 | + |
| 5 | +Summary |
| 6 | +======= |
| 7 | + |
| 8 | +This RFC proposes to standardize and mandate the use of the designator name in the end statement for all block-like constructs. Currently, the repetition of the designator (e.g., `end My_Procedure;`) is optional for subprograms, packages, tasks, and protected types. This proposal makes this end designator mandatory in all such cases. As a key part of this standardization, this RFC also proposes to replace the inconsistent end record terminator for record type declarations. This construct will be deprecated in favor of the now-mandatory `end <designator>;` syntax (e.g., `end My_Record_Type;`). |
| 9 | + |
| 10 | +Motivation |
| 11 | +========== |
| 12 | + |
| 13 | +The primary motivation for this change is to improve language consistency and code readability in long or nested code blocks, by explicitly linking the end of a block to its beginning. |
| 14 | + |
| 15 | +The current `end record` syntax is inconsistent with other block terminators. This proposal aligns record declarations with the termination syntax used by subprograms, packages, tasks, and protected types. This change would establish a clear rule: "If a construct has a name in its declaration, that name must be repeated at its end". This rule also finds precedent in Ada's named loops, where a loop's name must be repeated at its `end loop` termination. |
| 16 | + |
| 17 | +In addition, the proposal is particularly well-suited for upcoming language features, such as `class record`s. In such a construct, the `class record body` could be substantially longer, containing the implementations of various methods. |
| 18 | + |
| 19 | +Guide-level explanation |
| 20 | +======================= |
| 21 | + |
| 22 | +For subprograms, packages, tasks, protected types, record types, class record types and named loops, their name must be repeated at the end. The old syntax, where the name was optional or a different keyword was used (like `end record`), is illegal. |
| 23 | + |
| 24 | +```ada |
| 25 | +-- Old syntax, now illegal |
| 26 | +procedure My_Procedure is |
| 27 | +begin |
| 28 | + null; |
| 29 | +end; -- No designator |
| 30 | +
|
| 31 | +-- New syntax, mandatory |
| 32 | +procedure My_Procedure is |
| 33 | +begin |
| 34 | + null; |
| 35 | +end My_Procedure; -- Designator is mandatory |
| 36 | +``` |
| 37 | + |
| 38 | +The most significant change is to record declarations. The special `end record;` syntax has been removed from the language and replaced by the same universal `end <designator>;` rule. |
| 39 | + |
| 40 | +```ada |
| 41 | +-- Old syntax, now illegal |
| 42 | +type My_Record is record |
| 43 | + Foo : Unbounded_String; |
| 44 | + Bar : Natural; |
| 45 | +end My_Record; |
| 46 | +
|
| 47 | +-- New syntax, mandatory |
| 48 | +type My_Record is record |
| 49 | + Foo : Unbounded_String; |
| 50 | + Bar : Natural; |
| 51 | +end My_Record; -- Designator is mandatory |
| 52 | +``` |
| 53 | + |
| 54 | + |
| 55 | +Reference-level explanation |
| 56 | +=========================== |
| 57 | + |
| 58 | +Nothing specific at this stage. |
| 59 | + |
| 60 | +Rationale and alternatives |
| 61 | +========================== |
| 62 | + |
| 63 | +An alternative was to only deprecate `end record;` in favor of an optional `end <record_name>;`. This was deemed a missed opportunity. While it would fix the end record inconsistency, it would not bring the benefits of making the designator mandatory everywhere. |
| 64 | + |
| 65 | +Drawbacks |
| 66 | +========= |
| 67 | + |
| 68 | +The primary drawbacks are related to backward compatibility and verbosity. |
| 69 | + |
| 70 | +For backward compatibility, see the Compatibility section below. |
| 71 | + |
| 72 | +Mandating the designator makes the code more verbose, as it will be required to type the designator at the end of every block. This is a trade-off and the benefit of improved readability and consistency is argued to outweigh the inconvenience of extra typing. |
| 73 | + |
| 74 | +Compatibility |
| 75 | +============= |
| 76 | + |
| 77 | +This is a significant breaking change. All existing Ada code that currently uses the optional designator (or `end record`) would become non-compliant. |
| 78 | + |
| 79 | +Open questions |
| 80 | +============== |
| 81 | + |
| 82 | +None at this stage. |
| 83 | + |
| 84 | +Prior art |
| 85 | +========= |
| 86 | + |
| 87 | +Ada itself has named loops, (e.g., `Outer_Loop: loop ... end loop Outer_Loop;`) which already enforce the proposed pattern. |
| 88 | + |
| 89 | +Unresolved questions |
| 90 | +==================== |
| 91 | + |
| 92 | +None at this stage. |
| 93 | + |
| 94 | +Future possibilities |
| 95 | +==================== |
| 96 | + |
| 97 | +Nothing specific at this stage. |
0 commit comments