Skip to content

Commit 492bca1

Browse files
committed
[Module interface] Retain #if's with feature checks in inline bodies.
1 parent 669a49a commit 492bca1

File tree

4 files changed

+60
-1
lines changed

4 files changed

+60
-1
lines changed

include/swift/Basic/Features.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,6 @@ LANGUAGE_FEATURE(RethrowsProtocol, 0, "@rethrows protocol", true)
4343
LANGUAGE_FEATURE(GlobalActors, 0, "Global actors", langOpts.EnableExperimentalConcurrency)
4444
LANGUAGE_FEATURE(BuiltinJob, 0, "Builtin.Job type", true)
4545
LANGUAGE_FEATURE(Sendable, 0, "Sendable and @Sendable", true)
46+
LANGUAGE_FEATURE(BuiltinContinuation, 0, "Continuation builtins", true)
4647

4748
#undef LANGUAGE_FEATURE

lib/AST/ASTPrinter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2720,6 +2720,10 @@ static bool usesFeatureBuiltinJob(Decl *decl) {
27202720
return false;
27212721
}
27222722

2723+
static bool usesFeatureBuiltinContinuation(Decl *decl) {
2724+
return false;
2725+
}
2726+
27232727
/// Determine the set of "new" features used on a given declaration.
27242728
///
27252729
/// Note: right now, all features we check for are "new". At some point, we'll

lib/AST/InlinableText.cpp

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
//===----------------------------------------------------------------------===//
1212
#include "InlinableText.h"
1313
#include "swift/AST/ASTContext.h"
14-
#include "swift/AST/ASTWalker.h"
1514
#include "swift/AST/ASTNode.h"
15+
#include "swift/AST/ASTVisitor.h"
16+
#include "swift/AST/ASTWalker.h"
1617
#include "swift/AST/Decl.h"
1718
#include "swift/AST/Expr.h"
1819
#include "swift/Parse/Lexer.h"
@@ -43,6 +44,40 @@ getEffectiveEndLoc(SourceManager &sourceMgr, const IfConfigClause *clause,
4344
}
4445

4546
namespace {
47+
48+
class IsFeatureCheck : public ASTWalker {
49+
public:
50+
bool foundFeature = false;
51+
52+
std::pair<bool, Expr *> walkToExprPre(Expr *expr) override {
53+
if (auto unresolved = dyn_cast<UnresolvedDeclRefExpr>(expr)) {
54+
if (unresolved->getName().getBaseName().userFacingName().startswith("$"))
55+
foundFeature = true;
56+
}
57+
58+
return { !foundFeature, expr };
59+
}
60+
};
61+
62+
bool clauseIsFeatureCheck(Expr *cond) {
63+
IsFeatureCheck checker;
64+
cond->walk(checker);
65+
return checker.foundFeature;
66+
}
67+
68+
/// Whether any of the clauses here involves a feature check
69+
/// (e.g., $AsyncAwait).
70+
bool anyClauseIsFeatureCheck(ArrayRef<IfConfigClause> clauses) {
71+
for (const auto &clause : clauses) {
72+
if (Expr *cond = clause.Cond) {
73+
if (clauseIsFeatureCheck(cond))
74+
return true;
75+
}
76+
}
77+
78+
return false;
79+
}
80+
4681
/// A walker that searches through #if declarations, finding all text that does
4782
/// not contribute to the final evaluated AST.
4883
///
@@ -93,6 +128,13 @@ struct ExtractInactiveRanges : public ASTWalker {
93128
return false;
94129
}
95130

131+
// If the clause is checking for a particular feature with $, keep
132+
// the whole thing.
133+
if (anyClauseIsFeatureCheck(icd->getClauses())) {
134+
addRange(start, end);
135+
return false;
136+
}
137+
96138
// Ignore range from beginning of '#if', '#elseif', or '#else' to the
97139
// beginning of the elements of this clause.
98140
auto elementsBegin = clause->Loc;

stdlib/public/Concurrency/PartialAsyncTask.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ public struct UnsafeContinuation<T, E: Error> {
4444
/// able to reschedule it.
4545
@_alwaysEmitIntoClient
4646
public func resume(returning value: __owned T) where E == Never {
47+
#if compiler(>=5.5) && $BuiltinContinuation
4748
Builtin.resumeNonThrowingContinuationReturning(context, value)
49+
#else
50+
fatalError("Swift compiler is incompatible with this SDK version")
51+
#endif
4852
}
4953

5054
/// Resume the task awaiting the continuation by having it return normally
@@ -61,7 +65,11 @@ public struct UnsafeContinuation<T, E: Error> {
6165
/// able to reschedule it.
6266
@_alwaysEmitIntoClient
6367
public func resume(returning value: __owned T) {
68+
#if compiler(>=5.5) && $BuiltinContinuation
6469
Builtin.resumeThrowingContinuationReturning(context, value)
70+
#else
71+
fatalError("Swift compiler is incompatible with this SDK version")
72+
#endif
6573
}
6674

6775
/// Resume the task awaiting the continuation by having it throw an error
@@ -78,7 +86,11 @@ public struct UnsafeContinuation<T, E: Error> {
7886
/// able to reschedule it.
7987
@_alwaysEmitIntoClient
8088
public func resume(throwing error: __owned E) {
89+
#if compiler(>=5.5) && $BuiltinContinuation
8190
Builtin.resumeThrowingContinuationThrowing(context, error)
91+
#else
92+
fatalError("Swift compiler is incompatible with this SDK version")
93+
#endif
8294
}
8395
}
8496

0 commit comments

Comments
 (0)