Skip to content

Commit d15e3af

Browse files
committed
[ast] Always emit compiler(>= 5.3) when emitting guards for suppressable features to guard against parser errors.
The code here was assuming that if we already emitted a compiler guard for non-Suppressable features, we could avoid doing it for suppressable features. The problem with this is that compiler() does more than just check for compiler versions... it also tells the compiler that parser errors in the if block should be ignored when if evaluates to false. rdar://129045783 (cherry picked from commit 521a70f)
1 parent 613b321 commit d15e3af

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3295,10 +3295,13 @@ void swift::printWithCompatibilityFeatureChecks(ASTPrinter &printer,
32953295
// features, or else just print the body.
32963296
if (features.hasAnySuppressible()) {
32973297
auto generator = features.generateSuppressibleFeatures();
3298+
3299+
// NOTE: We emit the compiler check here as well since that also implicitly
3300+
// ensures that we ignore parsing errors in the if block. It is harmless
3301+
// otherwise.
32983302
printWithSuppressibleFeatureChecks(printer, options,
3299-
/*first*/ true,
3300-
/*compiler check*/ !hasRequiredFeatures,
3301-
generator,
3303+
/*first*/ true,
3304+
/*compiler check*/ true, generator,
33023305
printBody);
33033306
} else {
33043307
printBody();

test/Concurrency/sending_conditional_suppression.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,23 @@ public struct TestInStruct {
9191
// CHECK-NEXT: #endif
9292
public func testKlassArgAndResult(_ x: NonSendableKlass, _ y: sending NonSendableKlass, z: NonSendableKlass) -> sending NonSendableKlass { fatalError() }
9393
}
94+
95+
// Make sure that we emit compiler(>= 5.3) when emitting the suppressing check
96+
// to make sure we do not fail if we fail to parse sending in the if block.
97+
98+
// CHECK: #if compiler(>=5.3) && $OptionalIsolatedParameters && $ExpressionMacroDefaultArguments
99+
// CHECK-NEXT: #if compiler(>=5.3) && $SendingArgsAndResults
100+
// CHECK-NEXT: @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
101+
// CHECK-NEXT: @backDeployed(before: macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, visionOS 9999)
102+
// CHECK-NEXT: @inlinable public func withCheckedContinuation<T>(isolation:
103+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
104+
@backDeployed(before: macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, visionOS 9999)
105+
@inlinable public func withCheckedContinuation<T>(
106+
isolation: isolated (any _Concurrency.Actor)? = #isolation,
107+
function: String = #function,
108+
_ body: (_Concurrency.CheckedContinuation<T, Swift.Never>) -> Swift.Void
109+
) async -> sending T {
110+
return await withUnsafeContinuation {
111+
body(CheckedContinuation(continuation: $0, function: function))
112+
}
113+
}

0 commit comments

Comments
 (0)