1414// features.
1515//
1616//
17- // LANGUAGE_FEATURE(FeatureName, SENumber, Description)
17+ // LANGUAGE_FEATURE(FeatureName, IsAdoptable, SENumber, Description)
1818//
1919// The LANGUAGE_FEATURE macro describes each named feature that is
2020// introduced in Swift. It allows Swift code to check for a particular
2121// feature with "#if $FeatureName" in source code.
2222//
2323// FeatureName: The name given to this feature to be used in source code,
2424// 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+ //
2539// SENumber: The number assigned to this feature in the Swift Evolution
2640// process, or 0 if there isn't one.
2741// Description: A string literal describing the feature.
91105#endif
92106
93107#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)
96111#endif
97112
98113#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)
101116#endif
102117
103118// A feature that's both conditionally-suppressible and experimental.
116131#endif
117132
118133#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
121150#endif
122151
123152#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)
126156#endif
127157
128158#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)
133163#endif
134164
135165#ifndef EXPERIMENTAL_FEATURE_EXCLUDED_FROM_MODULE_INTERFACE
138168#endif
139169
140170#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)
143174#endif
144175
145176BASELINE_LANGUAGE_FEATURE (AsyncAwait, 296 , " async/await" )
@@ -210,10 +241,14 @@ BASELINE_LANGUAGE_FEATURE(BodyMacros, 415, "Function body macros")
210241SUPPRESSIBLE_LANGUAGE_FEATURE(SendingArgsAndResults, 430 , " Sending arg and results" )
211242BASELINE_LANGUAGE_FEATURE(BorrowingSwitch, 432 , " Noncopyable type pattern matching" )
212243CONDITIONALLY_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" )
217252SUPPRESSIBLE_LANGUAGE_FEATURE(MemorySafetyAttributes, 458 , " @unsafe attribute" )
218253
219254// Swift 6
@@ -234,7 +269,7 @@ UPCOMING_FEATURE(NonfrozenEnumExhaustivity, 192, 6)
234269UPCOMING_FEATURE(GlobalActorIsolatedTypesUsability, 0434 , 6 )
235270
236271// Swift 7
237- UPCOMING_FEATURE (ExistentialAny, 335 , 7 )
272+ ADOPTABLE_UPCOMING_FEATURE (ExistentialAny, 335 , 7 )
238273UPCOMING_FEATURE(InternalImportsByDefault, 409 , 7 )
239274UPCOMING_FEATURE(MemberImportVisibility, 444 , 7 )
240275
@@ -485,6 +520,7 @@ EXPERIMENTAL_FEATURE(CompileTimeValues, true)
485520#undef EXPERIMENTAL_FEATURE_EXCLUDED_FROM_MODULE_INTERFACE
486521#undef EXPERIMENTAL_FEATURE
487522#undef UPCOMING_FEATURE
523+ #undef ADOPTABLE_UPCOMING_FEATURE
488524#undef BASELINE_LANGUAGE_FEATURE
489525#undef OPTIONAL_LANGUAGE_FEATURE
490526#undef CONDITIONALLY_SUPPRESSIBLE_EXPERIMENTAL_FEATURE
0 commit comments