You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 warningsor as errors.
14
15
15
16
## Motivation
16
17
@@ -25,7 +26,6 @@ This lack of flexibility leads to situations where users who want to use `-warni
25
26
26
27
This proposal suggests adding new options that will allow the behavior of warnings to be controlled based on their diagnostic group.
27
28
-`-Werror <group>` - upgrades warnings in the specified group to errors
28
-
-`-Wsuppress <group>` - disables the emission of warnings in the specified group
29
29
-`-Wwarning <group>` - indicates that warnings in the specified group should remain warnings, even if they were previously suppressed or upgraded to errors
30
30
31
31
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
80
80
Compiler options for controlling the behavior of groups are now processed as a single list. These options include:
81
81
```
82
82
-Werror <group>
83
-
-Wsuppress <group>
84
83
-Wwarning <group>
85
84
-warnings-as-errors
86
85
-no-warnings-as-errors
87
-
-suppress-warnings
88
86
```
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.
92
88
93
89
Examples of option combinations:
94
90
-`-warnings-as-errors -Wwarning deprecated`
95
91
96
92
Warnings from the `deprecated` group will be kept as warnings, but all the rest will be upgraded to errors.
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.
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.
105
97
106
98
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.
107
99
@@ -110,6 +102,14 @@ For example, as mentioned above, the `unsafe_global_actor_deprecated` group is p
110
102
-`-Wwarning deprecated -Werror concurrency` will make it an error,
111
103
-`-Werror concurrency -Wwarning deprecated` will keep it as a warning.
112
104
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
+
113
113
### Usage of `-print-diagnostic-groups` and `-debug-diagnostic-names`
114
114
115
115
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
153
153
154
154
### Support in the language
155
155
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.
157
157
158
158
### Support in SwiftPM
159
159
@@ -204,18 +204,15 @@ During the design process, other names for the compiler options were considered,
However, with this naming, the combination `-suppress-warning deprecated -no-warning-as-error availability_deprecated` might be misleading.
210
207
211
208
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.
212
209
| Clang | Swift |
213
210
|-------------------|----------------------|
214
211
|`-W<group>`|`-Wwarning <group>`|
215
-
|`-Wno-<group>`|`-Wsuppress <group>`|
212
+
|`-Wno-<group>`||
216
213
|`-Werror=<group>`|`-Werror <group>`|
217
214
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.
219
216
220
217
### Alternative format for `-print-diagnostic-groups`
221
218
@@ -232,3 +229,12 @@ However, even this does not eliminate the possibility of breaking code that pars
232
229
233
230
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.
234
231
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