14
14
// features.
15
15
//
16
16
//
17
- // LANGUAGE_FEATURE(FeatureName, SENumber, Description)
17
+ // LANGUAGE_FEATURE(FeatureName, IsAdoptable, SENumber, Description)
18
18
//
19
19
// The LANGUAGE_FEATURE macro describes each named feature that is
20
20
// introduced in Swift. It allows Swift code to check for a particular
21
21
// feature with "#if $FeatureName" in source code.
22
22
//
23
23
// FeatureName: The name given to this feature to be used in source code,
24
24
// e.g., AsyncAwait.
25
+ // IsAdoptable: Whether the feature implements adoption mode.
26
+ //
27
+ // If the feature is upcoming (source-breaking) and provides for a
28
+ // mechanical code migration, it should implement adoption mode.
29
+ //
30
+ // Adoption mode is a feature-oriented code migration mechanism: a mode
31
+ // of operation that should produce compiler warnings with attached
32
+ // fix-its that can be applied to preserve the behavior of the code once
33
+ // the upcoming feature is enacted.
34
+ // These warnings must belong to a diagnostic group named after the
35
+ // feature. Adoption mode itself *and* the fix-its it produces must be
36
+ // source and binary compatible with how the code is compiled when the
37
+ // feature is disabled.
38
+ //
25
39
// SENumber: The number assigned to this feature in the Swift Evolution
26
40
// process, or 0 if there isn't one.
27
41
// Description: A string literal describing the feature.
91
105
#endif
92
106
93
107
#ifndef SUPPRESSIBLE_LANGUAGE_FEATURE
94
- # define SUPPRESSIBLE_LANGUAGE_FEATURE (FeatureName, SENumber, Description ) \
95
- LANGUAGE_FEATURE (FeatureName, SENumber, Description)
108
+ #define SUPPRESSIBLE_LANGUAGE_FEATURE (FeatureName, SENumber, Description ) \
109
+ LANGUAGE_FEATURE (FeatureName, /* IsAdoptable=*/ false , SENumber, \
110
+ Description)
96
111
#endif
97
112
98
113
#ifndef OPTIONAL_LANGUAGE_FEATURE
99
- # define OPTIONAL_LANGUAGE_FEATURE (FeatureName, SENumber, Description ) \
100
- LANGUAGE_FEATURE (FeatureName, SENumber, Description)
114
+ # define OPTIONAL_LANGUAGE_FEATURE (FeatureName, SENumber, Description ) \
115
+ LANGUAGE_FEATURE (FeatureName, /* IsAdoptable= */ false , SENumber, Description)
101
116
#endif
102
117
103
118
// A feature that's both conditionally-suppressible and experimental.
116
131
#endif
117
132
118
133
#ifndef CONDITIONALLY_SUPPRESSIBLE_LANGUAGE_FEATURE
119
- # define CONDITIONALLY_SUPPRESSIBLE_LANGUAGE_FEATURE (FeatureName, SENumber, Description ) \
120
- LANGUAGE_FEATURE (FeatureName, SENumber, Description)
134
+ #define CONDITIONALLY_SUPPRESSIBLE_LANGUAGE_FEATURE (FeatureName, SENumber, \
135
+ Description) \
136
+ LANGUAGE_FEATURE (FeatureName, /* IsAdoptable=*/ false , SENumber, \
137
+ Description)
138
+ #endif
139
+
140
+ // An upcoming feature that supports adoption mode.
141
+ #ifndef ADOPTABLE_UPCOMING_FEATURE
142
+ #if defined(UPCOMING_FEATURE)
143
+ #define ADOPTABLE_UPCOMING_FEATURE (FeatureName, SENumber, Version ) \
144
+ UPCOMING_FEATURE (FeatureName, SENumber, Version)
145
+ #else
146
+ #define ADOPTABLE_UPCOMING_FEATURE (FeatureName, SENumber, Version ) \
147
+ LANGUAGE_FEATURE (FeatureName, /* IsAdoptable=*/ true , SENumber, \
148
+ #FeatureName)
149
+ #endif
121
150
#endif
122
151
123
152
#ifndef UPCOMING_FEATURE
124
- # define UPCOMING_FEATURE (FeatureName, SENumber, Version ) \
125
- LANGUAGE_FEATURE (FeatureName, SENumber, #FeatureName)
153
+ #define UPCOMING_FEATURE (FeatureName, SENumber, Version ) \
154
+ LANGUAGE_FEATURE (FeatureName, /* IsAdoptable=*/ false , SENumber, \
155
+ #FeatureName)
126
156
#endif
127
157
128
158
#ifndef EXPERIMENTAL_FEATURE
129
- // Warning: setting `AvailableInProd` to `true` on a feature means that the flag
130
- // cannot be dropped in the future.
131
- # define EXPERIMENTAL_FEATURE (FeatureName, AvailableInProd ) \
132
- LANGUAGE_FEATURE (FeatureName, 0 , #FeatureName)
159
+ // Warning: setting `AvailableInProd` to `true` on a feature means that the
160
+ // flag cannot be dropped in the future.
161
+ # define EXPERIMENTAL_FEATURE (FeatureName, AvailableInProd ) \
162
+ LANGUAGE_FEATURE (FeatureName, /* IsAdoptable= */ false , 0 , #FeatureName)
133
163
#endif
134
164
135
165
#ifndef EXPERIMENTAL_FEATURE_EXCLUDED_FROM_MODULE_INTERFACE
138
168
#endif
139
169
140
170
#ifndef BASELINE_LANGUAGE_FEATURE
141
- # define BASELINE_LANGUAGE_FEATURE (FeatureName, SENumber, Description ) \
142
- LANGUAGE_FEATURE (FeatureName, SENumber, Description)
171
+ #define BASELINE_LANGUAGE_FEATURE (FeatureName, SENumber, Description ) \
172
+ LANGUAGE_FEATURE (FeatureName, /* IsAdoptable=*/ false , SENumber, \
173
+ Description)
143
174
#endif
144
175
145
176
BASELINE_LANGUAGE_FEATURE (AsyncAwait, 296 , " async/await" )
@@ -210,10 +241,14 @@ BASELINE_LANGUAGE_FEATURE(BodyMacros, 415, "Function body macros")
210
241
SUPPRESSIBLE_LANGUAGE_FEATURE(SendingArgsAndResults, 430 , " Sending arg and results" )
211
242
BASELINE_LANGUAGE_FEATURE(BorrowingSwitch, 432 , " Noncopyable type pattern matching" )
212
243
CONDITIONALLY_SUPPRESSIBLE_LANGUAGE_FEATURE(IsolatedAny, 431 , " @isolated(any) function types" )
213
- LANGUAGE_FEATURE(IsolatedAny2, 431 , " @isolated(any) function types" )
214
- LANGUAGE_FEATURE(ObjCImplementation, 436 , " @objc @implementation extensions" )
215
- LANGUAGE_FEATURE(NonescapableTypes, 446 , " Nonescapable types" )
216
- LANGUAGE_FEATURE(BuiltinEmplaceTypedThrows, 0 , " Builtin.emplace typed throws" )
244
+ LANGUAGE_FEATURE(IsolatedAny2, /* IsAdoptable=*/ false , 431 ,
245
+ " @isolated(any) function types" )
246
+ LANGUAGE_FEATURE(ObjCImplementation, /* IsAdoptable=*/ false , 436 ,
247
+ " @objc @implementation extensions" )
248
+ LANGUAGE_FEATURE(NonescapableTypes, /* IsAdoptable=*/ false , 446 ,
249
+ " Nonescapable types" )
250
+ LANGUAGE_FEATURE(BuiltinEmplaceTypedThrows, /* IsAdoptable=*/ false , 0 ,
251
+ " Builtin.emplace typed throws" )
217
252
SUPPRESSIBLE_LANGUAGE_FEATURE(MemorySafetyAttributes, 458 , " @unsafe attribute" )
218
253
219
254
// Swift 6
@@ -234,7 +269,7 @@ UPCOMING_FEATURE(NonfrozenEnumExhaustivity, 192, 6)
234
269
UPCOMING_FEATURE(GlobalActorIsolatedTypesUsability, 0434 , 6 )
235
270
236
271
// Swift 7
237
- UPCOMING_FEATURE (ExistentialAny, 335 , 7 )
272
+ ADOPTABLE_UPCOMING_FEATURE (ExistentialAny, 335 , 7 )
238
273
UPCOMING_FEATURE(InternalImportsByDefault, 409 , 7 )
239
274
UPCOMING_FEATURE(MemberImportVisibility, 444 , 7 )
240
275
@@ -485,6 +520,7 @@ EXPERIMENTAL_FEATURE(CompileTimeValues, true)
485
520
#undef EXPERIMENTAL_FEATURE_EXCLUDED_FROM_MODULE_INTERFACE
486
521
#undef EXPERIMENTAL_FEATURE
487
522
#undef UPCOMING_FEATURE
523
+ #undef ADOPTABLE_UPCOMING_FEATURE
488
524
#undef BASELINE_LANGUAGE_FEATURE
489
525
#undef OPTIONAL_LANGUAGE_FEATURE
490
526
#undef CONDITIONALLY_SUPPRESSIBLE_EXPERIMENTAL_FEATURE
0 commit comments