Skip to content

Commit 70d998a

Browse files
committed
[Concurrency] Make OptionalIsolatedParameters a conditionally suppressible
language feature, and suppress it for `Clock.measure`. This allows the _Concurrency swiftinterface file to continue building with compilers that do not support `OptionalIsolatedParameters`. The feature suppression drops the `isolated` keyword and replaces `#isolation` with `nil`.
1 parent dfa7b86 commit 70d998a

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

include/swift/AST/PrintOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,9 @@ struct PrintOptions {
379379
/// Suppress the @isolated(any) attribute.
380380
bool SuppressIsolatedAny = false;
381381

382+
/// Suppress 'isolated' and '#isolation' on isolated parameters with optional type.
383+
bool SuppressOptionalIsolatedParams = false;
384+
382385
/// List of attribute kinds that should not be printed.
383386
std::vector<AnyAttrKind> ExcludeAttrList = {
384387
DeclAttrKind::Transparent, DeclAttrKind::Effects,

include/swift/Basic/Features.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ LANGUAGE_FEATURE(FreestandingMacros, 397, "freestanding declaration macros")
164164
SUPPRESSIBLE_LANGUAGE_FEATURE(RetroactiveAttribute, 364, "@retroactive")
165165
SUPPRESSIBLE_LANGUAGE_FEATURE(ExtensionMacroAttr, 0, "@attached(extension)")
166166
LANGUAGE_FEATURE(TypedThrows, 413, "Typed throws")
167-
LANGUAGE_FEATURE(OptionalIsolatedParameters, 420, "Optional isolated parameters")
167+
CONDITIONALLY_SUPPRESSIBLE_LANGUAGE_FEATURE(OptionalIsolatedParameters, 420, "Optional isolated parameters")
168168
SUPPRESSIBLE_LANGUAGE_FEATURE(Extern, 0, "@_extern")
169169
LANGUAGE_FEATURE(ExpressionMacroDefaultArguments, 422, "Expression macro as caller-side default argument")
170170
LANGUAGE_FEATURE(BuiltinStoreRaw, 0, "Builtin.storeRaw")

lib/AST/ASTPrinter.cpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3083,6 +3083,14 @@ static void suppressingFeatureIsolatedAny(PrintOptions &options,
30833083
action();
30843084
}
30853085

3086+
static void suppressingFeatureOptionalIsolatedParameters(
3087+
PrintOptions &options,
3088+
llvm::function_ref<void()> action) {
3089+
llvm::SaveAndRestore<bool> scope(
3090+
options.SuppressOptionalIsolatedParams, true);
3091+
action();
3092+
}
3093+
30863094
static void suppressingFeatureAssociatedTypeImplements(PrintOptions &options,
30873095
llvm::function_ref<void()> action) {
30883096
unsigned originalExcludeAttrCount = options.ExcludeAttrList.size();
@@ -3660,8 +3668,11 @@ static void printParameterFlags(ASTPrinter &printer,
36603668
break;
36613669
}
36623670

3663-
if (flags.isIsolated())
3664-
printer.printKeyword("isolated", options, " ");
3671+
if (flags.isIsolated()) {
3672+
if (!(param && param->getInterfaceType()->isOptional() &&
3673+
options.SuppressOptionalIsolatedParams))
3674+
printer.printKeyword("isolated", options, " ");
3675+
}
36653676

36663677
if (flags.hasResultDependsOn())
36673678
printer.printKeyword("_resultDependsOn", options, " ");
@@ -3809,6 +3820,16 @@ void PrintAST::printOneParameter(const ParamDecl *param,
38093820
}
38103821

38113822
if (param->isDefaultArgument() && Options.PrintDefaultArgumentValue) {
3823+
auto defaultArgKind = param->getDefaultArgumentKind();
3824+
if (param->isIsolated() &&
3825+
defaultArgKind == DefaultArgumentKind::ExpressionMacro &&
3826+
Options.SuppressOptionalIsolatedParams) {
3827+
// If we're suppressing optional isolated parameters, print
3828+
// 'nil' instead of '#isolation'
3829+
Printer << " = nil";
3830+
return;
3831+
}
3832+
38123833
Printer.callPrintStructurePre(PrintStructureKind::DefaultArgumentClause);
38133834
SWIFT_DEFER {
38143835
Printer.printStructurePost(PrintStructureKind::DefaultArgumentClause);

stdlib/public/Concurrency/Clock.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ extension Clock {
6868
/// }
6969
@available(SwiftStdlib 5.7, *)
7070
@_alwaysEmitIntoClient
71+
@_allowFeatureSuppression(OptionalIsolatedParameters)
7172
public func measure(
7273
isolation: isolated (any Actor)? = #isolation,
7374
_ work: () async throws -> Void

0 commit comments

Comments
 (0)