Skip to content

Commit ecf4256

Browse files
authored
Merge pull request #71583 from DougGregor/swift-interfaces-assume-swift-5.5
Stop emitting conditions for Swift 5.5-era features into textual interfaces
2 parents 8c0b056 + 63c8fe3 commit ecf4256

File tree

6 files changed

+122
-302
lines changed

6 files changed

+122
-302
lines changed

include/swift/Basic/Features.def

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434
// imply the existence of earlier features. (This only needs to apply to
3535
// suppressible features.)
3636
//
37+
// BASELINE_LANGUAGE_FEATURE is the same as LANGUAGE_FEATURE, but is used
38+
// for features that can be assumed to be available in any Swift compiler that
39+
// will be used to process the textual interface files produced by this
40+
// Swift compiler.
3741
//===----------------------------------------------------------------------===//
3842

3943
#ifndef LANGUAGE_FEATURE
@@ -62,29 +66,34 @@
6266
EXPERIMENTAL_FEATURE(FeatureName, AvailableInProd)
6367
#endif
6468

65-
LANGUAGE_FEATURE(AsyncAwait, 296, "async/await")
66-
LANGUAGE_FEATURE(EffectfulProp, 310, "Effectful properties")
67-
LANGUAGE_FEATURE(MarkerProtocol, 0, "@_marker protocol")
68-
LANGUAGE_FEATURE(Actors, 0, "actors")
69-
LANGUAGE_FEATURE(ConcurrentFunctions, 0, "@concurrent functions")
69+
#ifndef BASELINE_LANGUAGE_FEATURE
70+
# define BASELINE_LANGUAGE_FEATURE(FeatureName, SENumber, Description) \
71+
LANGUAGE_FEATURE(FeatureName, SENumber, Description)
72+
#endif
73+
74+
BASELINE_LANGUAGE_FEATURE(AsyncAwait, 296, "async/await")
75+
BASELINE_LANGUAGE_FEATURE(EffectfulProp, 310, "Effectful properties")
76+
BASELINE_LANGUAGE_FEATURE(MarkerProtocol, 0, "@_marker protocol")
77+
BASELINE_LANGUAGE_FEATURE(Actors, 0, "actors")
78+
BASELINE_LANGUAGE_FEATURE(ConcurrentFunctions, 0, "@concurrent functions")
7079
LANGUAGE_FEATURE(RethrowsProtocol, 0, "@rethrows protocol")
71-
LANGUAGE_FEATURE(GlobalActors, 316, "Global actors")
72-
LANGUAGE_FEATURE(BuiltinJob, 0, "Builtin.Job type")
73-
LANGUAGE_FEATURE(Sendable, 0, "Sendable and @Sendable")
74-
LANGUAGE_FEATURE(BuiltinExecutor, 0, "Builtin.Executor type")
75-
LANGUAGE_FEATURE(BuiltinContinuation, 0, "Continuation builtins")
76-
LANGUAGE_FEATURE(BuiltinHopToActor, 0, "Builtin.HopToActor")
77-
LANGUAGE_FEATURE(BuiltinTaskGroupWithArgument, 0, "TaskGroup builtins")
78-
LANGUAGE_FEATURE(InheritActorContext, 0, "@_inheritActorContext attribute")
79-
LANGUAGE_FEATURE(ImplicitSelfCapture, 0, "@_implicitSelfCapture attribute")
80+
BASELINE_LANGUAGE_FEATURE(GlobalActors, 316, "Global actors")
81+
BASELINE_LANGUAGE_FEATURE(BuiltinJob, 0, "Builtin.Job type")
82+
BASELINE_LANGUAGE_FEATURE(Sendable, 0, "Sendable and @Sendable")
83+
BASELINE_LANGUAGE_FEATURE(BuiltinExecutor, 0, "Builtin.Executor type")
84+
BASELINE_LANGUAGE_FEATURE(BuiltinContinuation, 0, "Continuation builtins")
85+
BASELINE_LANGUAGE_FEATURE(BuiltinHopToActor, 0, "Builtin.HopToActor")
86+
BASELINE_LANGUAGE_FEATURE(BuiltinTaskGroupWithArgument, 0, "TaskGroup builtins")
87+
BASELINE_LANGUAGE_FEATURE(InheritActorContext, 0, "@_inheritActorContext attribute")
88+
BASELINE_LANGUAGE_FEATURE(ImplicitSelfCapture, 0, "@_implicitSelfCapture attribute")
8089
LANGUAGE_FEATURE(BuiltinBuildTaskExecutorRef, 0, "TaskExecutor-building builtins")
8190
LANGUAGE_FEATURE(BuiltinBuildExecutor, 0, "Executor-building builtins")
8291
LANGUAGE_FEATURE(BuiltinBuildComplexEqualityExecutor, 0, "Executor-building for 'complexEquality executor' builtins")
83-
LANGUAGE_FEATURE(BuiltinBuildMainExecutor, 0, "MainActor executor building builtin")
84-
LANGUAGE_FEATURE(BuiltinCreateAsyncTaskInGroup, 0, "Task create in task group builtin with extra flags")
92+
BASELINE_LANGUAGE_FEATURE(BuiltinBuildMainExecutor, 0, "MainActor executor building builtin")
93+
BASELINE_LANGUAGE_FEATURE(BuiltinCreateAsyncTaskInGroup, 0, "Task create in task group builtin with extra flags")
8594
LANGUAGE_FEATURE(BuiltinCreateAsyncTaskInGroupWithExecutor, 0, "Task create in task group builtin with extra flags")
8695
LANGUAGE_FEATURE(BuiltinCreateAsyncDiscardingTaskInGroup, 0, "Task create in discarding task group builtin, accounting for the Void return type")
87-
LANGUAGE_FEATURE(BuiltinCreateAsyncTaskWithExecutor, 0, "Task create builtin with extra executor preference")
96+
BASELINE_LANGUAGE_FEATURE(BuiltinCreateAsyncTaskWithExecutor, 0, "Task create builtin with extra executor preference")
8897
LANGUAGE_FEATURE(BuiltinCreateAsyncDiscardingTaskInGroupWithExecutor, 0, "Task create in discarding task group with extra executor preference")
8998
LANGUAGE_FEATURE(BuiltinCopy, 0, "Builtin.copy()")
9099
LANGUAGE_FEATURE(BuiltinStackAlloc, 0, "Builtin.stackAlloc")
@@ -287,5 +296,6 @@ EXPERIMENTAL_FEATURE(IsolatedAny, false)
287296
#undef EXPERIMENTAL_FEATURE_EXCLUDED_FROM_MODULE_INTERFACE
288297
#undef EXPERIMENTAL_FEATURE
289298
#undef UPCOMING_FEATURE
299+
#undef BASELINE_LANGUAGE_FEATURE
290300
#undef SUPPRESSIBLE_LANGUAGE_FEATURE
291301
#undef LANGUAGE_FEATURE

lib/AST/ASTPrinter.cpp

Lines changed: 5 additions & 162 deletions
Original file line numberDiff line numberDiff line change
@@ -2963,73 +2963,12 @@ static bool usesFeatureStaticAssert(Decl *decl) {
29632963
return false;
29642964
}
29652965

2966-
static bool usesFeatureEffectfulProp(Decl *decl) {
2967-
if (auto asd = dyn_cast<AbstractStorageDecl>(decl))
2968-
return asd->getEffectfulGetAccessor() != nullptr;
2969-
return false;
2970-
}
2971-
2972-
static bool usesFeatureAsyncAwait(Decl *decl) {
2973-
if (auto func = dyn_cast<AbstractFunctionDecl>(decl)) {
2974-
if (func->hasAsync())
2975-
return true;
2976-
}
2977-
2978-
// Check for async functions in the types of declarations.
2979-
if (auto value = dyn_cast<ValueDecl>(decl)) {
2980-
if (Type type = value->getInterfaceType()) {
2981-
bool hasAsync = type.findIf([](Type type) {
2982-
if (auto fnType = type->getAs<AnyFunctionType>()) {
2983-
if (fnType->isAsync())
2984-
return true;
2985-
}
2986-
2987-
return false;
2988-
});
2989-
2990-
if (hasAsync)
2991-
return true;
2992-
}
2993-
}
2994-
2995-
return false;
2996-
}
2997-
2998-
static bool usesFeatureMarkerProtocol(Decl *decl) {
2999-
return false;
3000-
}
3001-
3002-
static bool usesFeatureActors(Decl *decl) {
3003-
if (auto classDecl = dyn_cast<ClassDecl>(decl)) {
3004-
if (classDecl->isActor())
3005-
return true;
3006-
}
3007-
3008-
if (auto ext = dyn_cast<ExtensionDecl>(decl)) {
3009-
if (auto classDecl = ext->getSelfClassDecl())
3010-
if (classDecl->isActor())
3011-
return true;
3012-
}
3013-
3014-
// Check for actors in the types of declarations.
3015-
if (auto value = dyn_cast<ValueDecl>(decl)) {
3016-
if (Type type = value->getInterfaceType()) {
3017-
bool hasActor = type.findIf([](Type type) {
3018-
if (auto classDecl = type->getClassOrBoundGenericClass()) {
3019-
if (classDecl->isActor())
3020-
return true;
3021-
}
3022-
3023-
return false;
3024-
});
3025-
3026-
if (hasActor)
3027-
return true;
3028-
}
3029-
}
3030-
3031-
return false;
2966+
#define BASELINE_LANGUAGE_FEATURE(FeatureName, SENumber, Description) \
2967+
static bool usesFeature##FeatureName(Decl *decl) { \
2968+
return false; \
30322969
}
2970+
#define LANGUAGE_FEATURE(FeatureName, SENumber, Description)
2971+
#include "swift/Basic/Features.def"
30332972

30342973
static bool usesFeatureMacros(Decl *decl) {
30352974
return isa<MacroDecl>(decl);
@@ -3095,36 +3034,6 @@ static bool usesFeatureAttachedMacros(Decl *decl) {
30953034
return static_cast<bool>(macro->getMacroRoles() & getAttachedMacroRoles());
30963035
}
30973036

3098-
static bool usesFeatureConcurrentFunctions(Decl *decl) {
3099-
return false;
3100-
}
3101-
3102-
static bool usesFeatureSendable(Decl *decl) {
3103-
if (auto func = dyn_cast<AbstractFunctionDecl>(decl)) {
3104-
if (func->isSendable())
3105-
return true;
3106-
}
3107-
3108-
// Check for sendable functions in the types of declarations.
3109-
if (auto value = dyn_cast<ValueDecl>(decl)) {
3110-
if (Type type = value->getInterfaceType()) {
3111-
bool hasSendable = type.findIf([](Type type) {
3112-
if (auto fnType = type->getAs<AnyFunctionType>()) {
3113-
if (fnType->isSendable())
3114-
return true;
3115-
}
3116-
3117-
return false;
3118-
});
3119-
3120-
if (hasSendable)
3121-
return true;
3122-
}
3123-
}
3124-
3125-
return false;
3126-
}
3127-
31283037
static bool usesFeatureRethrowsProtocol(
31293038
Decl *decl, SmallPtrSet<Decl *, 16> &checked) {
31303039
// Make sure we don't recurse.
@@ -3200,10 +3109,6 @@ static bool usesFeatureRethrowsProtocol(Decl *decl) {
32003109
return usesFeatureRethrowsProtocol(decl, checked);
32013110
}
32023111

3203-
static bool usesFeatureGlobalActors(Decl *decl) {
3204-
return false;
3205-
}
3206-
32073112
static bool usesFeatureRetroactiveAttribute(Decl *decl) {
32083113
auto ext = dyn_cast<ExtensionDecl>(decl);
32093114
if (!ext)
@@ -3226,22 +3131,6 @@ static bool usesTypeMatching(Decl *decl, llvm::function_ref<bool(Type)> fn) {
32263131
return false;
32273132
}
32283133

3229-
static bool usesBuiltinType(Decl *decl, BuiltinTypeKind kind) {
3230-
return usesTypeMatching(decl, [=](Type type) {
3231-
if (auto builtinTy = type->getAs<BuiltinType>())
3232-
return builtinTy->getBuiltinTypeKind() == kind;
3233-
return false;
3234-
});
3235-
}
3236-
3237-
static bool usesFeatureBuiltinJob(Decl *decl) {
3238-
return usesBuiltinType(decl, BuiltinTypeKind::BuiltinJob);
3239-
}
3240-
3241-
static bool usesFeatureBuiltinExecutor(Decl *decl) {
3242-
return usesBuiltinType(decl, BuiltinTypeKind::BuiltinExecutor);
3243-
}
3244-
32453134
static bool usesFeatureBuiltinBuildTaskExecutorRef(Decl *decl) { return false; }
32463135

32473136
static bool usesFeatureBuiltinBuildExecutor(Decl *decl) {
@@ -3252,26 +3141,6 @@ static bool usesFeatureBuiltinBuildComplexEqualityExecutor(Decl *decl) {
32523141
return false;
32533142
}
32543143

3255-
static bool usesFeatureBuiltinBuildMainExecutor(Decl *decl) {
3256-
return false;
3257-
}
3258-
3259-
static bool usesFeatureBuiltinContinuation(Decl *decl) {
3260-
return false;
3261-
}
3262-
3263-
static bool usesFeatureBuiltinHopToActor(Decl *decl) {
3264-
return false;
3265-
}
3266-
3267-
static bool usesFeatureBuiltinTaskGroupWithArgument(Decl *decl) {
3268-
return false;
3269-
}
3270-
3271-
static bool usesFeatureBuiltinCreateAsyncTaskInGroup(Decl *decl) {
3272-
return false;
3273-
}
3274-
32753144
static bool usesFeatureBuiltinCreateAsyncTaskInGroupWithExecutor(Decl *decl) {
32763145
return false;
32773146
}
@@ -3280,10 +3149,6 @@ static bool usesFeatureBuiltinCreateAsyncDiscardingTaskInGroup(Decl *decl) {
32803149
return false;
32813150
}
32823151

3283-
static bool usesFeatureBuiltinCreateAsyncTaskWithExecutor(Decl *decl) {
3284-
return false;
3285-
}
3286-
32873152
static bool
32883153
usesFeatureBuiltinCreateAsyncDiscardingTaskInGroupWithExecutor(Decl *decl) {
32893154
return false;
@@ -3329,28 +3194,6 @@ static void suppressingFeatureSpecializeAttributeWithAvailability(
33293194
action();
33303195
}
33313196

3332-
static bool usesFeatureInheritActorContext(Decl *decl) {
3333-
if (auto func = dyn_cast<AbstractFunctionDecl>(decl)) {
3334-
for (auto param : *func->getParameters()) {
3335-
if (param->getAttrs().hasAttribute<InheritActorContextAttr>())
3336-
return true;
3337-
}
3338-
}
3339-
3340-
return false;
3341-
}
3342-
3343-
static bool usesFeatureImplicitSelfCapture(Decl *decl) {
3344-
if (auto func = dyn_cast<AbstractFunctionDecl>(decl)) {
3345-
for (auto param : *func->getParameters()) {
3346-
if (param->getAttrs().hasAttribute<ImplicitSelfCaptureAttr>())
3347-
return true;
3348-
}
3349-
}
3350-
3351-
return false;
3352-
}
3353-
33543197
static bool usesFeatureBuiltinStackAlloc(Decl *decl) {
33553198
return false;
33563199
}

0 commit comments

Comments
 (0)