Skip to content

Commit 8eb9da2

Browse files
authored
Merge pull request #2922 from swiftwasm/main
[pull] swiftwasm from main
2 parents 2290a86 + 6fb9af6 commit 8eb9da2

30 files changed

+375
-108
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

include/swift/IDE/SourceEntityWalker.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ namespace swift {
4141
/// An abstract class used to traverse the AST and provide source information.
4242
/// Visitation happens in source-order and compiler-generated semantic info,
4343
/// like implicit declarations, is ignored.
44+
///
45+
/// If \c walkTo*Pre returns \c true, the children are visited and \c
46+
/// walkTo*Post is called after all children have been visited.
47+
/// If \c walkTo*Pre returns \c false, the corresponding \c walkTo*Post call
48+
/// will not be issued.
49+
///
50+
/// If \c walkTo*Post returns \c false, the traversal is terminated. No more
51+
/// \c walk* calls are issued. Nodes that have already received a \c walkTo*Pre
52+
/// call will *not* receive a \c walkTo*Post call.
53+
/// If \c walkTo*Post returns \c true, the traversal continues.
4454
class SourceEntityWalker {
4555
public:
4656
/// Walks the provided source file.

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;

lib/ClangImporter/ImportDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ static FuncDecl *createFuncOrAccessor(ASTContext &ctx, SourceLoc funcLoc,
172172
accessorInfo->Kind, accessorInfo->Storage,
173173
/*StaticLoc*/ SourceLoc(),
174174
StaticSpellingKind::None,
175-
throws, /*ThrowsLoc=*/SourceLoc(),
176175
async, /*AsyncLoc=*/SourceLoc(),
176+
throws, /*ThrowsLoc=*/SourceLoc(),
177177
genericParams, bodyParams,
178178
resultTy, dc, clangNode);
179179
} else {

lib/IDE/IDERequests.cpp

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -815,12 +815,33 @@ struct RangeResolver::Implementation {
815815
analyzeDecl(D);
816816
auto &DCInfo = getCurrentDC();
817817

818-
auto NodeRange = Node.getSourceRange();
819-
820818
// Widen the node's source range to include all attributes to get a range
821819
// match if a function with its attributes has been selected.
822-
if (auto D = Node.dyn_cast<Decl *>())
823-
NodeRange = D->getSourceRangeIncludingAttrs();
820+
auto getSourceRangeIncludingAttrs = [](ASTNode N) -> SourceRange {
821+
if (auto D = N.dyn_cast<Decl *>()) {
822+
return D->getSourceRangeIncludingAttrs();
823+
} else {
824+
return N.getSourceRange();
825+
}
826+
};
827+
828+
auto NodeRange = getSourceRangeIncludingAttrs(Node);
829+
830+
// SemaAnnotator walks the AST in source order, but considers source order
831+
// for declarations to be defined by their range *excluding* attributes.
832+
// In RangeResolver, we attributes as belonging to their decl (see comment
833+
// on getSourceRAngeIncludingAttrs above).
834+
// Thus, for the purpose RangeResolver, we need to assume that SemaAnnotator
835+
// hands us the nodes in arbitrary order.
836+
//
837+
// Remove any nodes that are contained by the newly added one.
838+
auto removeIterator = std::remove_if(
839+
ContainedASTNodes.begin(), ContainedASTNodes.end(),
840+
[&](ASTNode ContainedNode) {
841+
return SM.rangeContains(NodeRange,
842+
getSourceRangeIncludingAttrs(ContainedNode));
843+
});
844+
ContainedASTNodes.erase(removeIterator, ContainedASTNodes.end());
824845

825846
switch (getRangeMatchKind(NodeRange)) {
826847
case RangeMatchKind::NoneMatch: {
@@ -848,11 +869,16 @@ struct RangeResolver::Implementation {
848869

849870
// If no parent is considered as a contained node; this node should be
850871
// a top-level contained node.
872+
// If a node that contains this one is later discovered, this node will be
873+
// removed from ContainedASTNodes again.
851874
if (std::none_of(ContainedASTNodes.begin(), ContainedASTNodes.end(),
852-
[&](ASTNode N) { return SM.rangeContains(N.getSourceRange(),
853-
Node.getSourceRange()); })) {
854-
ContainedASTNodes.push_back(Node);
855-
}
875+
[&](ASTNode ContainedNode) {
876+
return SM.rangeContains(
877+
getSourceRangeIncludingAttrs(ContainedNode),
878+
NodeRange);
879+
})) {
880+
ContainedASTNodes.push_back(Node);
881+
}
856882

857883
if (DCInfo.isMultiStatement()) {
858884
postAnalysis(DCInfo.EndMatches.back());

0 commit comments

Comments
 (0)