Skip to content

Commit c14e920

Browse files
committed
[Features] Added CoroutineAccessors.
1 parent 7a4c097 commit c14e920

File tree

5 files changed

+41
-0
lines changed

5 files changed

+41
-0
lines changed

include/swift/AST/PrintOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,9 @@ struct PrintOptions {
390390
/// Suppress ~Escapable types and lifetime dependence annotations
391391
bool SuppressNonEscapableTypes = false;
392392

393+
/// Suppress modify/read accessors.
394+
bool SuppressCoroutineAccessors = false;
395+
393396
/// List of attribute kinds that should not be printed.
394397
std::vector<AnyAttrKind> ExcludeAttrList = {
395398
DeclAttrKind::Transparent, DeclAttrKind::Effects,

include/swift/AST/StorageImpl.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,22 @@ enum class AccessorKind {
4949
#undef LAST_ACCESSOR
5050
};
5151

52+
inline bool requiresFeatureCoroutineAccessors(AccessorKind kind) {
53+
switch (kind) {
54+
case AccessorKind::Get:
55+
case AccessorKind::DistributedGet:
56+
case AccessorKind::Set:
57+
case AccessorKind::Read:
58+
case AccessorKind::Modify:
59+
case AccessorKind::WillSet:
60+
case AccessorKind::DidSet:
61+
case AccessorKind::Address:
62+
case AccessorKind::MutableAddress:
63+
case AccessorKind::Init:
64+
return false;
65+
}
66+
}
67+
5268
inline bool isYieldingAccessor(AccessorKind kind) {
5369
switch (kind) {
5470
case AccessorKind::Read:

include/swift/Basic/Features.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,9 @@ EXPERIMENTAL_FEATURE(WarnUnsafe, true)
411411
// Enable values in generic signatures, e.g. <let N: Int>
412412
EXPERIMENTAL_FEATURE(ValueGenerics, true)
413413

414+
/// modify/read single-yield coroutines
415+
SUPPRESSIBLE_EXPERIMENTAL_FEATURE(CoroutineAccessors, true)
416+
414417
#undef EXPERIMENTAL_FEATURE_EXCLUDED_FROM_MODULE_INTERFACE
415418
#undef EXPERIMENTAL_FEATURE
416419
#undef UPCOMING_FEATURE

lib/AST/ASTPrinter.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3112,6 +3112,13 @@ suppressingFeatureNonescapableTypes(PrintOptions &options,
31123112
options.ExcludeAttrList.resize(originalExcludeAttrCount);
31133113
}
31143114

3115+
static void
3116+
suppressingFeatureCoroutineAccessors(PrintOptions &options,
3117+
llvm::function_ref<void()> action) {
3118+
llvm::SaveAndRestore<bool> scope(options.SuppressCoroutineAccessors, true);
3119+
action();
3120+
}
3121+
31153122
/// Suppress the printing of a particular feature.
31163123
static void suppressingFeature(PrintOptions &options, Feature feature,
31173124
llvm::function_ref<void()> action) {
@@ -3990,6 +3997,10 @@ bool PrintAST::printASTNodes(const ArrayRef<ASTNode> &Elements,
39903997
}
39913998

39923999
void PrintAST::visitAccessorDecl(AccessorDecl *decl) {
4000+
if (Options.SuppressCoroutineAccessors &&
4001+
requiresFeatureCoroutineAccessors(decl->getAccessorKind())) {
4002+
return;
4003+
}
39934004
printDocumentationComment(decl);
39944005
printAttributes(decl);
39954006
// Explicitly print 'mutating' and 'nonmutating' if needed.

lib/AST/FeatureSet.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,14 @@ static bool usesFeatureValueGenerics(Decl *decl) {
317317
return false;
318318
}
319319

320+
static bool usesFeatureCoroutineAccessors(Decl *decl) {
321+
auto *accessor = dyn_cast<AccessorDecl>(decl);
322+
if (!accessor) {
323+
return false;
324+
}
325+
return requiresFeatureCoroutineAccessors(accessor->getAccessorKind());
326+
}
327+
320328
// ----------------------------------------------------------------------------
321329
// MARK: - FeatureSet
322330
// ----------------------------------------------------------------------------

0 commit comments

Comments
 (0)