Skip to content

Commit 84ae100

Browse files
committed
[Features] Added CoroutineAccessors.
1 parent 131a52c commit 84ae100

File tree

6 files changed

+42
-0
lines changed

6 files changed

+42
-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
@@ -417,6 +417,9 @@ EXPERIMENTAL_FEATURE(ValueGenerics, true)
417417
// When a parameter has unspecified isolation, infer it as main actor isolated.
418418
EXPERIMENTAL_FEATURE(UnspecifiedMeansMainActorIsolated, false)
419419

420+
/// modify/read single-yield coroutines
421+
SUPPRESSIBLE_EXPERIMENTAL_FEATURE(CoroutineAccessors, true)
422+
420423
#undef EXPERIMENTAL_FEATURE_EXCLUDED_FROM_MODULE_INTERFACE
421424
#undef EXPERIMENTAL_FEATURE
422425
#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
@@ -319,6 +319,14 @@ static bool usesFeatureValueGenerics(Decl *decl) {
319319
return false;
320320
}
321321

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

lib/ASTGen/Sources/ASTGen/SourceFile.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ extension Parser.ExperimentalFeatures {
7474
mapFeature(.DoExpressions, to: .doExpressions)
7575
mapFeature(.NonescapableTypes, to: .nonescapableTypes)
7676
mapFeature(.TrailingComma, to: .trailingComma)
77+
mapFeature(.CoroutineAccessors, to: .coroutineAccessors)
7778
}
7879
}
7980

0 commit comments

Comments
 (0)