Skip to content

Commit 54d9a6f

Browse files
committed
[Source Warning Control] Rename '@warn' to '@diagnose'
Resolves rdar://173774670
1 parent 51c8c23 commit 54d9a6f

7 files changed

Lines changed: 119 additions & 64 deletions

File tree

Sources/SwiftWarningControl/SwiftWarningControl.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
# SwiftWarningControl
22

3-
A library to evaluate `@warn` diagnostic group controls within a Swift syntax tree.
3+
A library to evaluate `@diagnose` diagnostic group controls within a Swift syntax tree.
44

55
## Overview
66

7-
Swift provides a mechanism to control the behavior of specific diagnostic groups for a given declaration's lexical scope with the `@warn` attribute.
7+
Swift provides a mechanism to control the behavior of specific diagnostic groups for a given declaration's lexical scope with the `@diagnose` attribute (also accepts the old `@warn` spelling).
88

9-
The syntax tree and its parser do not reason about warning group controls. The syntax tree produced by the parser represents the `@warn` attribute in a generic fashion, as it would any other basic attribute on a declaration. The per-declaration nature of the attribute means that for any given lexical scope, the behavior of a given diagnostic group can be queried by checking for the presence of this attribute in its parent declaration scope.
9+
The syntax tree and its parser do not reason about warning group controls. The syntax tree produced by the parser represents the `@diagnose` attribute in a generic fashion, as it would any other basic attribute on a declaration. The per-declaration nature of the attribute means that for any given lexical scope, the behavior of a given diagnostic group can be queried by checking for the presence of this attribute in its parent declaration scope.
1010

1111
```swift
12-
@warn(Deprecate, as: error)
12+
@diagnose(Deprecate, as: error)
1313
func foo() {
1414
...
15-
@warn(Deprecate, as: warning)
15+
@diagnose(Deprecate, as: warning)
1616
func bar() {
1717
...
18-
@warn("Deprecate", as: ignored, reason: "Foo")
18+
@diagnose("Deprecate", as: ignored, reason: "Foo")
1919
func baz() {
2020
...
2121
}
2222
}
2323
}
2424
```
2525

26-
The `SwiftWarningControl` library provides a utility to determine, for a given source location and diagnostic group identifier, whether or not its behavior is affected by an `@warn` attribute of any of its parent declaration scope.
26+
The `SwiftWarningControl` library provides a utility to determine, for a given source location and diagnostic group identifier, whether or not its behavior is affected by an `@diagnose` attribute of any of its parent declaration scope.
2727

2828
* `SyntaxProtocol.getWarningGroupControl(for diagnosticGroupIdentifier:)` produces the behavior control specifier (`WarningGroupControl`: `error`, `warning`, `ignored`) which applies at this node.
2929

Sources/SwiftWarningControl/SyntaxProtocol+WarningControl.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ extension SyntaxProtocol {
2323
/// - globalControls: The global controls to consider, specified by the client (compiler)
2424
/// representing module-wide diagnostic group emission configuration, for example
2525
/// with `-Wwarning` and `-Werror` flags. These controls can be overriden at
26-
/// finer-grained scopes with the `@warn` attribute.
26+
/// finer-grained scopes with the `@diagnose` attribute.
2727
@_spi(ExperimentalLanguageFeatures)
2828
public func warningGroupControl(
2929
for diagnosticGroupIdentifier: DiagnosticGroupIdentifier,

Sources/SwiftWarningControl/WarningControlDeclSyntax.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414

1515
extension AttributeSyntax {
1616
var warningGroupControl: (DiagnosticGroupIdentifier, WarningGroupControl)? {
17-
// `@warn` attributes
18-
guard attributeName.as(IdentifierTypeSyntax.self)?.name.text == "warn"
17+
// `@diagnose` attributes (also accepts the old `@warn` spelling)
18+
guard let attrName = attributeName.as(IdentifierTypeSyntax.self)?.name.text,
19+
attrName == "diagnose" || attrName == "warn"
1920
else {
2021
return nil
2122
}
@@ -51,7 +52,7 @@ extension AttributeSyntax {
5152
}
5253

5354
extension WithAttributesSyntax {
54-
/// Compute a dictionary of all `@warn` diagnostic group behavior controls
55+
/// Compute a dictionary of all `@diagnose` diagnostic group behavior controls
5556
/// specified on this warning control declaration scope.
5657
var allWarningGroupControls: [(DiagnosticGroupIdentifier, WarningGroupControl)] {
5758
attributes.reduce(into: [(DiagnosticGroupIdentifier, WarningGroupControl)]()) { result, attr in

Sources/SwiftWarningControl/WarningControlRegionBuilder.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ extension SyntaxProtocol {
4545
}
4646
}
4747

48-
/// Add this warning control decl syntax node warning group controls (as specified with `@warn`)
48+
/// Add this warning control decl syntax node warning group controls (as specified with `@diagnose`)
4949
/// to the tree.
5050
extension WarningControlRegionTree {
5151
mutating func addWarningControlRegions(for syntax: some WithAttributesSyntax) {

Sources/SwiftWarningControl/WarningControlRegions.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,27 +43,27 @@ public struct DiagnosticGroupIdentifier: Hashable, Sendable, ExpressibleByString
4343
public let identifier: String
4444
}
4545

46-
/// Describes all of the `@warn` diagnostic group behavior controls within the
46+
/// Describes all of the `@diagnose` diagnostic group behavior controls within the
4747
/// given syntax node, indicating each group's active behavior at a given position.
4848
///
4949
/// For example, given code like the following:
5050
///
5151
/// ```
52-
/// 1 | @warn(Deprecate, as: error)
52+
/// 1 | @diagnose(Deprecate, as: error)
5353
/// 2 | func foo() {
5454
/// 3 | let a = dep
55-
/// 4 | @warn(Deprecate, as: warning)
55+
/// 4 | @diagnose(Deprecate, as: warning)
5656
/// 5 | func bar() {
5757
/// 6 | let b = dep
58-
/// 7 | @warn(Deprecate, as: ignored)
58+
/// 7 | @diagnose(Deprecate, as: ignored)
5959
/// 8 | func baz() {
6060
/// 9 | let c = dep
6161
/// 10 | }
62-
/// 11 | @warn(Deprecate, as: error)
63-
/// 12 | @warn(OtherGroup, as: error)
62+
/// 11 | @diagnose(Deprecate, as: error)
63+
/// 12 | @diagnose(OtherGroup, as: error)
6464
/// 13 | func qux() {
6565
/// 14 | let d = dep
66-
/// 15 | @warn(SomeOtherGroup, as: warning)
66+
/// 15 | @diagnose(SomeOtherGroup, as: warning)
6767
/// 16 | func corge() {
6868
/// 17 | let e = dep
6969
/// 18 | }
@@ -150,7 +150,7 @@ public struct WarningControlRegionTree {
150150
}
151151

152152
/// Add warning control regions to the tree root node.
153-
/// For example, controls corresponding to a top-level `using @warn()` statement.
153+
/// For example, controls corresponding to a top-level `using @diagnose()` statement.
154154
mutating func addRootWarningGroupControls(controls: [(DiagnosticGroupIdentifier, WarningGroupControl)]) {
155155
addWarningGroupControls(range: rootRegionNode.range, controls: controls)
156156
}

Tests/SwiftParserTest/DeclarationTests.swift

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3757,6 +3757,39 @@ final class UsingDeclarationTests: ParserTestCase {
37573757
)
37583758
)
37593759

3760+
assertParse(
3761+
"using @diagnose(DiagGroupID, as: error)",
3762+
substructure: UsingDeclSyntax(
3763+
usingKeyword: .keyword(.using),
3764+
specifier: .attribute(
3765+
AttributeSyntax(
3766+
attributeName: IdentifierTypeSyntax(
3767+
name: .identifier("diagnose")
3768+
),
3769+
leftParen: .leftParenToken(),
3770+
arguments: .argumentList(
3771+
LabeledExprListSyntax([
3772+
LabeledExprSyntax(
3773+
expression: DeclReferenceExprSyntax(
3774+
baseName: .identifier("DiagGroupID")
3775+
),
3776+
trailingComma: .commaToken()
3777+
),
3778+
LabeledExprSyntax(
3779+
label: .identifier("as"),
3780+
colon: .colonToken(),
3781+
expression: DeclReferenceExprSyntax(
3782+
baseName: .identifier("error")
3783+
)
3784+
),
3785+
])
3786+
),
3787+
rightParen: .rightParenToken()
3788+
)
3789+
)
3790+
)
3791+
)
3792+
37603793
assertParse(
37613794
"""
37623795
nonisolated

0 commit comments

Comments
 (0)