Skip to content

Commit fc538f3

Browse files
committed
Allow declarations to opt in to suppressing @isolated(any).
1 parent 1437acd commit fc538f3

File tree

5 files changed

+51
-3
lines changed

5 files changed

+51
-3
lines changed

include/swift/AST/PrintOptions.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,11 +376,13 @@ struct PrintOptions {
376376
/// `AsyncIteratorProtocol` for backward-compatibility reasons.
377377
bool AsyncSequenceRethrows = false;
378378

379+
/// Suppress the @isolated(any) attribute.
380+
bool SuppressIsolatedAny = false;
381+
379382
/// List of attribute kinds that should not be printed.
380383
std::vector<AnyAttrKind> ExcludeAttrList = {
381384
DeclAttrKind::Transparent, DeclAttrKind::Effects,
382385
DeclAttrKind::FixedLayout, DeclAttrKind::ShowInInterface,
383-
DeclAttrKind::AllowFeatureSuppression
384386
};
385387

386388
/// List of attribute kinds that should be printed exclusively.

include/swift/Basic/Features.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ EXPERIMENTAL_FEATURE(DynamicActorIsolation, false)
335335
EXPERIMENTAL_FEATURE(BorrowingSwitch, true)
336336

337337
// Enable isolated(any) attribute on function types.
338-
EXPERIMENTAL_FEATURE(IsolatedAny, true)
338+
CONDITIONALLY_SUPPRESSIBLE_EXPERIMENTAL_FEATURE(IsolatedAny, true)
339339

340340
#undef EXPERIMENTAL_FEATURE_EXCLUDED_FROM_MODULE_INTERFACE
341341
#undef EXPERIMENTAL_FEATURE

lib/AST/ASTPrinter.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ PrintOptions PrintOptions::printSwiftInterfaceFile(ModuleDecl *ModuleToPrint,
366366
DeclAttrKind::StaticInitializeObjCMetadata,
367367
DeclAttrKind::RestatedObjCConformance,
368368
DeclAttrKind::NonSendable,
369+
DeclAttrKind::AllowFeatureSuppression,
369370
};
370371

371372
return result;
@@ -3101,6 +3102,12 @@ static void suppressingFeatureExtern(PrintOptions &options,
31013102
options.ExcludeAttrList.resize(originalExcludeAttrCount);
31023103
}
31033104

3105+
static void suppressingFeatureIsolatedAny(PrintOptions &options,
3106+
llvm::function_ref<void()> action) {
3107+
llvm::SaveAndRestore<bool> scope(options.SuppressIsolatedAny, true);
3108+
action();
3109+
}
3110+
31043111
/// Suppress the printing of a particular feature.
31053112
static void suppressingFeature(PrintOptions &options, Feature feature,
31063113
llvm::function_ref<void()> action) {
@@ -6315,7 +6322,8 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
63156322
break;
63166323

63176324
case FunctionTypeIsolation::Kind::Erased:
6318-
Printer << "@isolated(any) ";
6325+
if (!Options.SuppressIsolatedAny)
6326+
Printer << "@isolated(any) ";
63196327
break;
63206328
}
63216329

lib/AST/Attr.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,13 @@ const char *IsolatedTypeAttr::getIsolationKindName(IsolationKind kind) {
254254

255255
void IsolatedTypeAttr::printImpl(ASTPrinter &printer,
256256
const PrintOptions &options) const {
257+
// Suppress the attribute if requested.
258+
switch (getIsolationKind()) {
259+
case IsolationKind::Dynamic:
260+
if (options.SuppressIsolatedAny) return;
261+
break;
262+
}
263+
257264
printer.callPrintStructurePre(PrintStructureKind::BuiltinAttribute);
258265
printer.printAttrName("@isolated");
259266
printer << "(" << getIsolationKindName() << ")";
@@ -1254,6 +1261,15 @@ bool DeclAttribute::printImpl(ASTPrinter &Printer, const PrintOptions &Options,
12541261
Printer << "(" << cast<AlignmentAttr>(this)->getValue() << ")";
12551262
break;
12561263

1264+
case DeclAttrKind::AllowFeatureSuppression:
1265+
Printer.printAttrName("@_allowFeatureSuppression");
1266+
Printer << "(";
1267+
interleave(cast<AllowFeatureSuppressionAttr>(this)->getSuppressedFeatures(),
1268+
[&](Identifier ident) { Printer << ident; },
1269+
[&] { Printer << ", "; });
1270+
Printer << ")";
1271+
break;
1272+
12571273
case DeclAttrKind::SILGenName:
12581274
Printer.printAttrName("@_silgen_name");
12591275
Printer << "(\"" << cast<SILGenNameAttr>(this)->Name << "\")";
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// RUN: %target-swift-frontend -swift-version 5 -enable-library-evolution -module-name isolated_any -emit-module -o %t/isolated_any.swiftmodule -emit-module-interface-path - -enable-experimental-feature IsolatedAny %s | %FileCheck %s
4+
5+
// CHECK: #if compiler(>=5.3) && $IsolatedAny
6+
// CHECK-NEXT: {{^}}public func test1(fn: @isolated(any) () -> ())
7+
// CHECK-NEXT: #endif
8+
public func test1(fn: @isolated(any) () -> ()) {}
9+
10+
// CHECK-NEXT: #if compiler(>=5.3) && $IsolatedAny
11+
// CHECK-NEXT: {{^}}public func test2(fn: @isolated(any) () -> ())
12+
// CHECK-NEXT: #endif
13+
@_allowFeatureSuppression(XXX)
14+
public func test2(fn: @isolated(any) () -> ()) {}
15+
16+
// CHECK-NEXT: #if compiler(>=5.3) && $IsolatedAny
17+
// CHECK-NEXT: {{^}}public func test3(fn: @isolated(any) () -> ())
18+
// CHECK-NEXT: #else
19+
// CHECK-NEXT: {{^}}public func test3(fn: () -> ())
20+
// CHECK-NEXT: #endif
21+
@_allowFeatureSuppression(IsolatedAny)
22+
public func test3(fn: @isolated(any) () -> ()) {}

0 commit comments

Comments
 (0)