|
2 | 2 | - Start Date: 2025-11-06 |
3 | 3 | - Status: Proposed |
4 | 4 |
|
5 | | -Summary |
6 | | -======= |
| 5 | +# Summary |
7 | 6 |
|
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;`). |
| 7 | +This RFC proposes to standardize the use of a single `end[ designator]` terminator for all declaration constructs that use an end designator, in pedantic Ada Flare. |
9 | 8 |
|
10 | | -Motivation |
11 | | -========== |
| 9 | +Currently, the repetition of the designator (for example, `end My_Procedure`) is optional for subprograms, packages, tasks, and protected types. Record type declarations, however, use a distinct and inconsistent terminator: `end record[ designator]`. |
12 | 10 |
|
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. |
| 11 | +This RFC proposes to deprecate the special `end record[ designator]` syntax for record type declarations and replace it with the uniform `end[ designator];` syntax (for example, `end My_Record_Type;`). |
14 | 12 |
|
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. |
| 13 | +For backwards compatibility reasons, non-pedantic Ada Flare continues to accept the Ada 2022 syntax. |
16 | 14 |
|
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. |
| 15 | +# Motivation |
18 | 16 |
|
19 | | -Guide-level explanation |
20 | | -======================= |
| 17 | +The primary motivation for this change is to improve language consistency and code readability in long or nested code blocks, by explicitly and uniformily linking the end of a construct to its beginning. |
21 | 18 |
|
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. |
| 19 | +The current `end record[ designator]` syntax is inconsistent with other declaration terminators. This proposal aligns record declarations with the termination syntax used by subprograms, packages, tasks, and protected types. |
23 | 20 |
|
24 | | -```ada |
25 | | --- Old syntax, now illegal |
26 | | -procedure My_Procedure is |
27 | | -begin |
28 | | - null; |
29 | | -end; -- No designator |
| 21 | +# Guide-level explanation |
30 | 22 |
|
31 | | --- New syntax, mandatory |
32 | | -procedure My_Procedure is |
33 | | -begin |
34 | | - null; |
35 | | -end My_Procedure; -- Designator is mandatory |
36 | | -``` |
| 23 | +The special `end record[ designator];` syntax is removed in pedantic Ada Flare and replaced by the generic `end[ designator];` syntax. |
37 | 24 |
|
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. |
| 25 | +**Ada Syntax:** |
39 | 26 |
|
40 | 27 | ```ada |
41 | | --- Old syntax, now illegal |
42 | | -type My_Record is record |
| 28 | +type My_Record_1 is record |
43 | 29 | Foo : Unbounded_String; |
44 | 30 | Bar : Natural; |
45 | | -end My_Record; |
| 31 | +end record; -- mandatory 'record' |
46 | 32 |
|
47 | | --- New syntax, mandatory |
48 | | -type My_Record is record |
| 33 | +type My_Record_2 is record |
| 34 | + Foo : Unbounded_String; |
| 35 | + Bar : Natural; |
| 36 | +end record My_Record_2; -- mandatory 'record' and optional designator |
| 37 | +``` |
| 38 | + |
| 39 | +**Flare Syntax:** |
| 40 | + |
| 41 | +```ada |
| 42 | +type My_Record_1 is record |
49 | 43 | Foo : Unbounded_String; |
50 | 44 | Bar : Natural; |
51 | | -end My_Record; -- Designator is mandatory |
| 45 | +end; -- No designator |
| 46 | +
|
| 47 | +type My_Record_2 is record |
| 48 | + Foo : Unbounded_String; |
| 49 | + Bar : Natural; |
| 50 | +end My_Record_2; -- With optional designator |
52 | 51 | ``` |
53 | 52 |
|
| 53 | +# Reference-level explanation |
54 | 54 |
|
55 | | -Reference-level explanation |
56 | | -=========================== |
| 55 | +The grammar for record_definition (ARM 3.8) is changed to: |
57 | 56 |
|
58 | | -Nothing specific at this stage. |
| 57 | +``` |
| 58 | +record_definition ::= |
| 59 | + record |
| 60 | + component_list |
| 61 | + end[ record_identifier] |
| 62 | + | null record |
| 63 | +``` |
59 | 64 |
|
60 | | -Rationale and alternatives |
61 | | -========================== |
| 65 | +# Rationale and alternatives |
62 | 66 |
|
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. |
| 67 | +An alternative approach would be to require the designator for all end terminators. This was considered in ealier drafts but rejected in order to preserve the existing Ada philosophy of optional designators for declaration constructs. |
64 | 68 |
|
65 | | -Drawbacks |
66 | | -========= |
| 69 | +# Drawbacks |
67 | 70 |
|
68 | | -The primary drawbacks are related to backward compatibility and verbosity. |
| 71 | +The primary drawbacks are related to compatibility. See the Compatibility section below. |
69 | 72 |
|
70 | | -For backward compatibility, see the Compatibility section below. |
| 73 | +# Compatibility |
71 | 74 |
|
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. |
| 75 | +Code using the new `end[ designator]` syntax for record type declarations will not compile with standard Ada 2022 compilers. |
73 | 76 |
|
74 | | -Compatibility |
75 | | -============= |
| 77 | +In pedantic Ada Flare, the `end record[ designator]` form is rejected and only the generic terminator is accepted. |
76 | 78 |
|
77 | | -This is a significant breaking change. All existing Ada code that currently uses the optional designator (or `end record`) would become non-compliant. |
| 79 | +In non-pedantic Ada Flare, both the Ada 2022 and the Ada Flare syntax remain valid to preserve backward compatibility. |
78 | 80 |
|
79 | | -Open questions |
80 | | -============== |
| 81 | +# Open questions |
81 | 82 |
|
82 | 83 | None at this stage. |
83 | 84 |
|
84 | | -Prior art |
85 | | -========= |
| 85 | +# Prior art |
86 | 86 |
|
87 | | -Ada itself has named loops, (e.g., `Outer_Loop: loop ... end loop Outer_Loop;`) which already enforce the proposed pattern. |
| 87 | +None at this stage. |
88 | 88 |
|
89 | | -Unresolved questions |
90 | | -==================== |
| 89 | +# Unresolved questions |
91 | 90 |
|
92 | 91 | None at this stage. |
93 | 92 |
|
94 | | -Future possibilities |
95 | | -==================== |
| 93 | +# Future possibilities |
96 | 94 |
|
97 | 95 | Nothing specific at this stage. |
0 commit comments