-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Add DiagGroupID to Diagnostic #77928
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
Conversation
This change addresses the following issue: when an error is being wrapped in a warning, the diagnostic message will use the wrapper's `DiagGroupID` as the warning's name. However, we want to retain the original error's group for use. For example, in Swift 5, async_unavailable_decl is wrapped in error_in_future_swift_version. When we print a diagnostic of this kind, we want to keep the `DiagGroupID` of `async_unavailable_decl`, not that of `error_in_future_swift_version`. To achieve this, we add `DiagGroupID` to the `Diagnostic` class. When an active diagnostic is wrapped in DiagnosticEngine, we retain the original `DiagGroupID`. For illustration purposes, this change also introduces a new group: `DeclarationUnavailableFromAsynchronousContext`. With this change, we produce errors and warnings of this kind with messages like the following: ``` global function 'fNoAsync' is unavailable from asynchronous contexts [DeclarationUnavailableFromAsynchronousContext] global function 'fNoAsync' is unavailable from asynchronous contexts; this is an error in the Swift 6 language mode [DeclarationUnavailableFromAsynchronousContext] ```
@DougGregor Can you take a look and run the test, please? |
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.
This looks great!
@swift-ci please smoke test |
@@ -25,6 +25,7 @@ GROUP(no_group, "") | |||
GROUP(DeprecatedDeclaration, "DeprecatedDeclaration.md") | |||
GROUP(Unsafe, "Unsafe.md") | |||
GROUP(UnknownWarningGroup, "UnknownWarningGroup.md") | |||
GROUP(DeclarationUnavailableFromAsynchronousContext, "DeclarationUnavailableFromAsynchronousContext.md") |
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.
As far as I am concerned, we cannot afford to remove a group once it ships, which calls for very mindful additions. If this group is purely intended to support test coverage, we should establish and document mechanisms for defining and conveying its experimental or internal status. Otherwise, I don’t think it wise to modify the group tree without at least an approving review from the Language Steering Group, if not a proposal.
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 was hoping to gather all the concurrency related groups and start a thread on the forum. Unfortunately, I didn't find enough time to do that. This commit was merged after the 6.1 release was branched. So we can still remove this group for now.
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 have a few ideas about how to make this a unit test. I will tag you in the PR.
This change addresses the following issue: when an error is being wrapped in a warning, the diagnostic message will use the wrapper's
DiagGroupID
as the warning's name. However, we want to retain the original error's group for use. For example, in Swift 5, async_unavailable_decl is wrapped in error_in_future_swift_version. When we print a diagnostic of this kind, we want to keep theDiagGroupID
ofasync_unavailable_decl
, not that oferror_in_future_swift_version
. To achieve this, we addDiagGroupID
to theDiagnostic
class. When an active diagnostic is wrapped in DiagnosticEngine, we retain the originalDiagGroupID
.For illustration purposes, this change also introduces a new group:
DeclarationUnavailableFromAsynchronousContext
.With this change, we produce errors and warnings of this kind with messages like the following: