Skip to content

Commit 7b12899

Browse files
authored
Merge pull request #2554 from DmT021/wp/warn-flags-amendment
[SE-0443] Exclude -Wsuppress and -suppress-warnings from the proposal
2 parents 30af787 + 7a6910f commit 7b12899

File tree

1 file changed

+25
-19
lines changed

1 file changed

+25
-19
lines changed

proposals/0443-warning-control-flags.md

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
* Status: **Active review (August 22nd...September 2nd, 2024)**
88
* Implementation: [apple/swift#74466](https://github.com/swiftlang/swift/pull/74466)
99
* Review: ([pitch](https://forums.swift.org/t/warnings-as-errors-exceptions/72925)) ([review](https://forums.swift.org/t/se-0443-precise-control-flags-over-compiler-warnings/74116))
10+
* Previous revisions: [1](https://github.com/swiftlang/swift-evolution/blob/57fe29d5d55edb85b14c153b7f4cbead6b6539eb/proposals/0443-warning-control-flags.md)
1011

1112
## Introduction
1213

13-
This proposal introduces new compiler options that allow fine-grained control over how the compiler emits certain warnings: as warnings, as errors, or not at all.
14+
This proposal introduces new compiler options that allow fine-grained control over how the compiler emits certain warnings: as warnings or as errors.
1415

1516
## Motivation
1617

@@ -25,7 +26,6 @@ This lack of flexibility leads to situations where users who want to use `-warni
2526

2627
This proposal suggests adding new options that will allow the behavior of warnings to be controlled based on their diagnostic group.
2728
- `-Werror <group>` - upgrades warnings in the specified group to errors
28-
- `-Wsuppress <group>` - disables the emission of warnings in the specified group
2929
- `-Wwarning <group>` - indicates that warnings in the specified group should remain warnings, even if they were previously suppressed or upgraded to errors
3030

3131
The `<group>` parameter is a string identifier of the diagnostic group.
@@ -80,28 +80,20 @@ Each warning in the compiler is assigned one of three behaviors: `warning`, `err
8080
Compiler options for controlling the behavior of groups are now processed as a single list. These options include:
8181
```
8282
-Werror <group>
83-
-Wsuppress <group>
8483
-Wwarning <group>
8584
-warnings-as-errors
8685
-no-warnings-as-errors
87-
-suppress-warnings
8886
```
89-
When these options are passed to the compiler, we sequentially apply the specified behavior to all warnings within the specified group from left to right. For `-warnings-as-errors`, `-no-warnings-as-errors`, and `-suppress-warnings`, we apply the behavior to all warnings.
90-
91-
The `-no-warnings-as-errors` option should be read as "set the behavior to 'warning' for all warnings". Thus, it overrides all previously set behaviors, including if the `-suppress-warnings` option was applied earlier or if a warning was suppressed by default.
87+
When these options are passed to the compiler, we sequentially apply the specified behavior to all warnings within the specified group from left to right. For `-warnings-as-errors` and `-no-warnings-as-errors`, we apply the behavior to all warnings.
9288

9389
Examples of option combinations:
9490
- `-warnings-as-errors -Wwarning deprecated`
9591

9692
Warnings from the `deprecated` group will be kept as warnings, but all the rest will be upgraded to errors.
9793

98-
- `-warnings-as-errors -Wwarning deprecated -Wsuppress availability_deprecated`
99-
100-
Warnings from the `availability_deprecated` group will be suppressed. Other warnings from the `deprecated` group will remain as warnings. All other warnings will be upgraded to errors.
101-
102-
- `-suppress-warnings -Wwarning deprecated`
94+
- `-Werror deprecated -Wwarning availability_deprecated`
10395

104-
Warnings from the `deprecated` group will remain as warnings. All others will be suppressed.
96+
Warnings from the `availability_deprecated` group will remain as warnings. Other warnings from the `deprecated` group will be upgraded to errors. All others will be kept as warnings.
10597

10698
It’s crucial to understand that the order in which these flags are applied can significantly affect the behavior of diagnostics. The rule is "the last one wins", meaning that if multiple flags apply to the same diagnostic group, the last one specified on the command line will determine the final behavior.
10799

@@ -110,6 +102,14 @@ For example, as mentioned above, the `unsafe_global_actor_deprecated` group is p
110102
- `-Wwarning deprecated -Werror concurrency` will make it an error,
111103
- `-Werror concurrency -Wwarning deprecated` will keep it as a warning.
112104

105+
#### Interaction with `-suppress-warnings`
106+
107+
This proposal deliberately excludes `-suppress-warnings` and its group-based counterpart from the new unified model. We retain the behavior of the existing `-suppress-warnings` flag but forbid its usage with the new options. The following rules will be applied:
108+
109+
- It is forbidden to combine `-suppress-warnings` with `-Wwarning` or `-Werror`. The compiler will produce an error if these options are present in the command line together.
110+
- It is allowed to be combined with `-no-warnings-as-errors`. The current compiler behavior permits the usage of `-no-warnings-as-errors` or `-warnings-as-errors -no-warnings-as-errors` with `-suppress-warnings`. We will maintain this behavior.
111+
- It remains position-independent. Whenever `-no-warnings-as-errors` and `-suppress-warnings` are combined, `-suppress-warnings` will always take precedence over `-no-warnings-as-errors`, regardless of the order in which they are specified.
112+
113113
### Usage of `-print-diagnostic-groups` and `-debug-diagnostic-names`
114114

115115
As mentioned earlier, we are adding support for the `-print-diagnostic-groups` compiler option, which outputs the group name in square brackets.
@@ -153,7 +153,7 @@ The adoption of diagnostic groups and the new compiler options will provide a fo
153153

154154
### Support in the language
155155

156-
While diagnostic groups are introduced to support the compiler options, it may be possible in the future to standardize the structure of the group graph itself. This could open up the possibility of using these same identifiers in the language, implementing something analogous to `#pragma diagnostic` or `[[attribute]]` in C++. However, such standardization and the design of new constructs in the language go far beyond the scope of this proposal, and we need to gain more experience with diagnostic groups before proceeding with this.
156+
While diagnostic groups are introduced to support the compiler options, it may be possible in the future to standardize the structure of the group graph itself. This could open up the possibility of using these same identifiers in the language, implementing something analogous to `#pragma diagnostic` or `[[attribute]]` in C++. It could also address suppressing warnings entirely, which isn't covered by this proposal. However, such standardization and the design of new language constructs go far beyond the scope of this proposal, and we need to gain more experience with diagnostic groups before proceeding with this.
157157

158158
### Support in SwiftPM
159159

@@ -204,18 +204,15 @@ During the design process, other names for the compiler options were considered,
204204
|--------------------------|--------------------------------|
205205
| `-warnings-as-errors` | `-warning-as-error <group>` |
206206
| `-no-warnings-as-errors` | `-no-warning-as-error <group>` |
207-
| `-suppress-warnings` | `-suppress-warning <group>` |
208-
209-
However, with this naming, the combination `-suppress-warning deprecated -no-warning-as-error availability_deprecated` might be misleading.
210207

211208
In Clang, diagnostic behavior is controlled through `-W...` options, but the format suffers from inconsistency. We adopt the `-W` prefix while making the format consistent.
212209
| Clang | Swift |
213210
|-------------------|----------------------|
214211
| `-W<group>` | `-Wwarning <group>` |
215-
| `-Wno-<group>` | `-Wsuppress <group>` |
212+
| `-Wno-<group>` | |
216213
| `-Werror=<group>` | `-Werror <group>` |
217214

218-
Additionally, the option name `-Wwarning` is much better suited when it comes to enabling suppressed-by-default warnings. Today we have several of them behind dedicated flags like `-driver-warn-unused-options` and `-warn-concurrency`. It might be worth having a common infrastructure for warnings that are suppressed by default.
215+
The option name `-Wwarning` is much better suited when it comes to enabling suppressed-by-default warnings. Today we have several of them behind dedicated flags like `-driver-warn-unused-options` and `-warn-concurrency`. It might be worth having a common infrastructure for warnings that are suppressed by default.
219216

220217
### Alternative format for `-print-diagnostic-groups`
221218

@@ -232,3 +229,12 @@ However, even this does not eliminate the possibility of breaking code that pars
232229

233230
Moreover, `-print-diagnostic-groups` provides a formalized version of the same functionality using identifiers suitable for user use. And thus it should supersede the usages of `-debug-diagnostic-names`. Therefore, we believe the best solution would be to use the same format for `-print-diagnostic-groups` and prohibit the simultaneous use of these two options.
234231

232+
## Revision History
233+
234+
- Revisions based on review feedback:
235+
- `-Wsuppress` was excluded from the proposal.
236+
- `-suppress-warnings` was excluded from the unified model and addressed separately by forbidding its usage with the new flags.
237+
238+
## Acknowledgments
239+
240+
Thank you to [Frederick Kellison-Linn](https://forums.swift.org/u/Jumhyn) for the idea of addressing the `-suppress-warnings` behavior without incorporating it into the new model.

0 commit comments

Comments
 (0)