-
Notifications
You must be signed in to change notification settings - Fork 30
RFC for mandatory end designators #178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
joaopsazevedo
wants to merge
1
commit into
master
Choose a base branch
from
mr/mandatory_end_designators
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| - Feature ID: mandatory_end_designator | ||
| - Start Date: 2025-11-06 | ||
| - Status: Proposed | ||
|
|
||
| Summary | ||
| ======= | ||
|
|
||
| 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;`). | ||
|
|
||
| Motivation | ||
| ========== | ||
|
|
||
| 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. | ||
|
|
||
| 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. | ||
|
|
||
| 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. | ||
|
|
||
| Guide-level explanation | ||
| ======================= | ||
|
|
||
| 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. | ||
|
|
||
| ```ada | ||
| -- Old syntax, now illegal | ||
| procedure My_Procedure is | ||
| begin | ||
| null; | ||
| end; -- No designator | ||
|
|
||
| -- New syntax, mandatory | ||
| procedure My_Procedure is | ||
| begin | ||
| null; | ||
| end My_Procedure; -- Designator is mandatory | ||
| ``` | ||
|
|
||
| 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. | ||
|
|
||
| ```ada | ||
| -- Old syntax, now illegal | ||
| type My_Record is record | ||
| Foo : Unbounded_String; | ||
| Bar : Natural; | ||
| end My_Record; | ||
|
|
||
| -- New syntax, mandatory | ||
| type My_Record is record | ||
| Foo : Unbounded_String; | ||
| Bar : Natural; | ||
| end My_Record; -- Designator is mandatory | ||
| ``` | ||
|
|
||
|
|
||
| Reference-level explanation | ||
| =========================== | ||
|
|
||
| Nothing specific at this stage. | ||
|
|
||
| Rationale and alternatives | ||
| ========================== | ||
|
|
||
| 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. | ||
|
|
||
| Drawbacks | ||
| ========= | ||
|
|
||
| The primary drawbacks are related to backward compatibility and verbosity. | ||
|
|
||
| For backward compatibility, see the Compatibility section below. | ||
|
|
||
| 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. | ||
|
|
||
| Compatibility | ||
| ============= | ||
|
|
||
| This is a significant breaking change. All existing Ada code that currently uses the optional designator (or `end record`) would become non-compliant. | ||
|
|
||
| Open questions | ||
| ============== | ||
|
|
||
| None at this stage. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You did not mention the alternative of making this a self-imposed Restriction rather than a massive incompatibility. You could allow the alternative syntax for ending a record, and then define a Restriction that would mandate it for a given project. |
||
|
|
||
| Prior art | ||
| ========= | ||
|
|
||
| Ada itself has named loops, (e.g., `Outer_Loop: loop ... end loop Outer_Loop;`) which already enforce the proposed pattern. | ||
|
|
||
| Unresolved questions | ||
| ==================== | ||
|
|
||
| None at this stage. | ||
|
|
||
| Future possibilities | ||
| ==================== | ||
|
|
||
| Nothing specific at this stage. | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be
end record;here.