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
Copy file name to clipboardExpand all lines: proposals/0441-formalize-language-mode-terminology.md
+11-10Lines changed: 11 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@
11
11
The term "Swift version” can refer to either the toolchain/compiler version or the language mode. This ambiguity is a consistent source of confusion. This proposal formalizes the term _language mode_ in tool options and APIs.
12
12
13
13
## Proposed Solution
14
-
The proposed solution is to use the term _language mode_ for the appropriate Swift compiler option and Swift Package Manager APIs. Use of "Swift version" to refer to language mode will be deprecated or obsoleted as needed.
14
+
The proposed solution is to use the term _language mode_ for the appropriate Swift compiler option and Swift Package Manager APIs. Use of "Swift version" to refer to language mode will be deprecated.
15
15
16
16
### Terminology
17
17
The term _language mode_ has been consistently used to describe this compiler feature since it was introduced with Swift 4.0 and is an established term of art in the Swift community.
@@ -49,7 +49,7 @@ Add a new `init` method to `Package` with the following changes from the current
49
49
- The parameter `swiftLanguageVersions` is renamed to `swiftLanguageModes`
50
50
- The parameter type is now an optional array of `SwiftLanguageMode` values instead of `SwiftVersion` values
51
51
52
-
The existing init method will be marked as `obsoleted` and `renamed` allowing the compiler to provide a fix-it.
52
+
The existing init method will be marked as `deprecated` and `renamed` allowing the compiler to provide a fix-it. It will also have the @_disfavoredOverload attribute added to allow the compiler to disambiguate.
53
53
54
54
#### 2. Rename `swiftLanguageVersions` property to `swiftLanguageModes`
55
55
Rename the public `Package` property `swiftLanguageVersions` to `swiftLanguageModes`. Add a `swiftLanguageVersions` computed property that accesses `swiftLanguageModes` for backwards compatibility.
@@ -104,7 +104,7 @@ The `-swift-version` option will be suppressed from the top-level help of the co
104
104
### Swift Package Manager
105
105
Proposed Swift Package Manager API changes are limited to manifests \>=6.0:
106
106
107
-
### New Package init method and obsoletedinit method
107
+
### New Package init method and deprecatedinit method
108
108
A new `init` method will be added to `Package` that renames the `swiftLanguageVersions` parameter to `swiftLanguageModes` with the type of the parameter being an optional array of `SwiftLanguageMode` values instead of `SwiftVersion` values:
109
109
110
110
```swift
@@ -123,10 +123,11 @@ Package(
123
123
```
124
124
125
125
126
-
The existing init method will be marked as `obsoleted` and `renamed`, allowing the compiler to provide a fix-it:
126
+
The existing init method will be marked as `deprecated` and `renamed`, allowing the compiler to provide a fix-it. It will also be annotated with `@_disfavoredOverload` to disambiguate the new and existing init methods:
The existing method must be obsoleted because the two methods are ambiguous when the default value for `swiftLanguageVersions` / `swiftLanguageModes` is used:
143
+
#### Deprecating the existing init method by making it a disfavored overload
144
+
In order to deprecate the existing method instead of marking it obsoleted, the existing method needs to be annotated with the `@_disfavoredOverlaod` attribute. This is because the two methods are ambiguous when the default value for `swiftLanguageVersions` / `swiftLanguageModes` is used:
144
145
145
146
```
146
147
Package ( // Error: Ambiguous use of 'init'
@@ -150,7 +151,7 @@ Package ( // Error: Ambiguous use of 'init'
150
151
)
151
152
```
152
153
153
-
This follows the same approach used by all past revisions of the Package `init` method.
154
+
Adding the `@_disfavoredOverlaod` attribute allows the compiler to disambiguate between the two methods.
154
155
155
156
See the **Source compatibility** section for more details about this change.
156
157
@@ -212,11 +213,11 @@ public struct SwiftSetting {
212
213
```
213
214
214
215
## Source compatibility
215
-
The new Package `init` method and obsoleting of the existing `init` method will cause source breakage for package manifests that specify the existing `swiftLanguageVersions` parameter when updating to swift tools version 6.0
216
+
The new Package `init` method and deprecating the existing `init` method will cause a deprecation warning for package manifests that specify the existing `swiftLanguageVersions` parameter when updating to swift tools version 6.0
216
217
217
218
A search of manifest files in public repositories suggests that about 10% of manifest files will encounter this breakage.
218
219
219
-
Because the obsoleted `init` method is annotated as `renamed` the compiler will automatically provide a fix-it to update to the new `init` method.
220
+
Because the deprecated `init` method is annotated as `renamed` the compiler will automatically provide a fix-it to update to the new `init` method.
220
221
221
222
Renaming the public `swiftLanguageVersions` property of `Package` preserves backwards compatibility by introducing a computed property with that name. The computed property will be marked as `deprecated` in 6.0 and annotated as `renamed` to provide a fix-it.
0 commit comments