Skip to content

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

Merged
merged 1 commit into from
Dec 4, 2024

Conversation

DmT021
Copy link
Contributor

@DmT021 DmT021 commented Dec 3, 2024

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]

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]
```
@DmT021
Copy link
Contributor Author

DmT021 commented Dec 3, 2024

@DougGregor Can you take a look and run the test, please?

Copy link
Member

@DougGregor DougGregor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great!

@DougGregor
Copy link
Member

@swift-ci please smoke test

@DougGregor DougGregor merged commit 867cf28 into swiftlang:main Dec 4, 2024
3 checks passed
@@ -25,6 +25,7 @@ GROUP(no_group, "")
GROUP(DeprecatedDeclaration, "DeprecatedDeclaration.md")
GROUP(Unsafe, "Unsafe.md")
GROUP(UnknownWarningGroup, "UnknownWarningGroup.md")
GROUP(DeclarationUnavailableFromAsynchronousContext, "DeclarationUnavailableFromAsynchronousContext.md")
Copy link
Collaborator

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.

Copy link
Contributor Author

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.

Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants