Skip to content

Commit 1ac87e7

Browse files
committed
[Basic] Add an experimental feature flag to guard use of ~Sendable
1 parent 6a1ff42 commit 1ac87e7

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

include/swift/AST/PrintOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,9 @@ struct PrintOptions {
406406
/// Suppress @inline(always) attribute and emit @inline(__always) instead.
407407
bool SuppressInlineAlways = false;
408408

409+
/// Suppress printing of ~Sendable in inheritance and requirement lists.
410+
bool SuppressTildeSendable = false;
411+
409412
/// Whether to print the \c{/*not inherited*/} comment on factory initializers.
410413
bool PrintFactoryInitializerComment = true;
411414

include/swift/Basic/Features.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,9 @@ SUPPRESSIBLE_EXPERIMENTAL_FEATURE(InlineAlways, false)
559559
/// Allow use of 'Swift' (Swift runtime version) in @available attributes
560560
EXPERIMENTAL_FEATURE(SwiftRuntimeAvailability, true)
561561

562+
/// Allow use of `~Sendable`.
563+
SUPPRESSIBLE_EXPERIMENTAL_FEATURE(TildeSendable, false)
564+
562565
#undef EXPERIMENTAL_FEATURE_EXCLUDED_FROM_MODULE_INTERFACE
563566
#undef EXPERIMENTAL_FEATURE
564567
#undef UPCOMING_FEATURE

lib/AST/ASTPrinter.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3285,6 +3285,12 @@ suppressingFeatureLifetimes(PrintOptions &options,
32853285
action();
32863286
}
32873287

3288+
static void suppressingFeatureTildeSendable(PrintOptions &options,
3289+
llvm::function_ref<void()> action) {
3290+
llvm::SaveAndRestore<bool> scope(options.SuppressTildeSendable, true);
3291+
action();
3292+
}
3293+
32883294
namespace {
32893295
struct ExcludeAttrRAII {
32903296
std::vector<AnyAttrKind> &ExcludeAttrList;
@@ -3302,7 +3308,7 @@ struct ExcludeAttrRAII {
33023308
ExcludeAttrList.resize(OriginalExcludeAttrCount);
33033309
}
33043310
};
3305-
}
3311+
} // namespace
33063312

33073313
static void
33083314
suppressingFeatureCoroutineAccessors(PrintOptions &options,

lib/AST/FeatureSet.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,26 @@ static bool usesFeatureInlineAlways(Decl *decl) {
450450

451451
UNINTERESTING_FEATURE(SwiftRuntimeAvailability)
452452

453+
static bool usesFeatureTildeSendable(Decl *decl) {
454+
auto *TD = dyn_cast<TypeDecl>(decl);
455+
if (!TD)
456+
return false;
457+
458+
return llvm::any_of(
459+
TD->getInherited().getEntries(), [&decl](const auto &entry) {
460+
if (!entry.isSuppressed())
461+
return false;
462+
463+
auto T = entry.getType();
464+
if (!T)
465+
return false;
466+
467+
auto &C = decl->getASTContext();
468+
return C.getProtocol(KnownProtocolKind::Sendable) == T->getAnyNominal();
469+
});
470+
}
471+
472+
453473
// ----------------------------------------------------------------------------
454474
// MARK: - FeatureSet
455475
// ----------------------------------------------------------------------------

0 commit comments

Comments
 (0)