Skip to content

Commit 66e6c59

Browse files
committed
[Features] Added CoroutineAccessors.
1 parent 053e79e commit 66e6c59

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
@@ -55,6 +55,22 @@ enum class AccessorKind {
5555
#undef LAST_ACCESSOR
5656
};
5757

58+
inline bool requiresFeatureCoroutineAccessors(AccessorKind kind) {
59+
switch (kind) {
60+
case AccessorKind::Get:
61+
case AccessorKind::DistributedGet:
62+
case AccessorKind::Set:
63+
case AccessorKind::Read:
64+
case AccessorKind::Modify:
65+
case AccessorKind::WillSet:
66+
case AccessorKind::DidSet:
67+
case AccessorKind::Address:
68+
case AccessorKind::MutableAddress:
69+
case AccessorKind::Init:
70+
return false;
71+
}
72+
}
73+
5874
inline bool isYieldingAccessor(AccessorKind kind) {
5975
switch (kind) {
6076
case AccessorKind::Read:

include/swift/Basic/Features.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,9 @@ EXPERIMENTAL_FEATURE(ValueGenerics, true)
418418
// When a parameter has unspecified isolation, infer it as main actor isolated.
419419
EXPERIMENTAL_FEATURE(UnspecifiedMeansMainActorIsolated, false)
420420

421+
/// modify/read single-yield coroutines
422+
SUPPRESSIBLE_EXPERIMENTAL_FEATURE(CoroutineAccessors, true)
423+
421424
#undef EXPERIMENTAL_FEATURE_EXCLUDED_FROM_MODULE_INTERFACE
422425
#undef EXPERIMENTAL_FEATURE
423426
#undef UPCOMING_FEATURE

lib/AST/ASTPrinter.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3164,6 +3164,13 @@ suppressingFeatureNonescapableTypes(PrintOptions &options,
31643164
options.ExcludeAttrList.resize(originalExcludeAttrCount);
31653165
}
31663166

3167+
static void
3168+
suppressingFeatureCoroutineAccessors(PrintOptions &options,
3169+
llvm::function_ref<void()> action) {
3170+
llvm::SaveAndRestore<bool> scope(options.SuppressCoroutineAccessors, true);
3171+
action();
3172+
}
3173+
31673174
/// Suppress the printing of a particular feature.
31683175
static void suppressingFeature(PrintOptions &options, Feature feature,
31693176
llvm::function_ref<void()> action) {
@@ -4038,6 +4045,10 @@ bool PrintAST::printASTNodes(const ArrayRef<ASTNode> &Elements,
40384045
}
40394046

40404047
void PrintAST::visitAccessorDecl(AccessorDecl *decl) {
4048+
if (Options.SuppressCoroutineAccessors &&
4049+
requiresFeatureCoroutineAccessors(decl->getAccessorKind())) {
4050+
return;
4051+
}
40414052
printDocumentationComment(decl);
40424053
printAttributes(decl);
40434054
// 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
@@ -310,6 +310,14 @@ static bool usesFeatureValueGenerics(Decl *decl) {
310310
return false;
311311
}
312312

313+
static bool usesFeatureCoroutineAccessors(Decl *decl) {
314+
auto *accessor = dyn_cast<AccessorDecl>(decl);
315+
if (!accessor) {
316+
return false;
317+
}
318+
return requiresFeatureCoroutineAccessors(accessor->getAccessorKind());
319+
}
320+
313321
// ----------------------------------------------------------------------------
314322
// MARK: - FeatureSet
315323
// ----------------------------------------------------------------------------

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)