-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[SourceKit] Don't use SourceEntitityWalker for placeholder expansion #73394
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
rintaro
merged 1 commit into
swiftlang:main
from
rintaro:sourcekit-expandplaceholder-rdar121360941
May 3, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// RUN: %sourcekitd-test -req=expand-placeholder %s | %FileCheck %s | ||
|
||
// FIXME: Make it acccept '-debug-forbid-typecheck-prefix' and ensure no typecheck happens.' | ||
|
||
protocol MyProto {} | ||
|
||
enum MyEnum: Hashable, MyProto { | ||
case foo | ||
case bar | ||
} | ||
|
||
func test(array: [MyEnum]) -> [NyEnum] { | ||
array.filter(<#T##isIncluded: (MyEnum) throws -> Bool##(MyEnum) throws -> Bool#>) | ||
// CHECK: array.filter { <#MyEnum#> in | ||
// CHECK-NEXT: <#code#> | ||
// CHECK-NEXT: } | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -1695,7 +1695,7 @@ class PlaceholderExpansionScanner { | |||||
std::pair<ArgumentList *, bool> enclosingCallExprArg(SourceFile &SF, | ||||||
SourceLoc SL) { | ||||||
|
||||||
class CallExprFinder : public SourceEntityWalker { | ||||||
class CallExprFinder : public ASTWalker { | ||||||
public: | ||||||
const SourceManager &SM; | ||||||
SourceLoc TargetLoc; | ||||||
|
@@ -1719,7 +1719,11 @@ class PlaceholderExpansionScanner { | |||||
return true; | ||||||
} | ||||||
|
||||||
bool walkToExprPre(Expr *E) override { | ||||||
MacroWalking getMacroWalkingBehavior() const override { | ||||||
return MacroWalking::Arguments; | ||||||
} | ||||||
|
||||||
PreWalkResult<Expr *> walkToExprPre(Expr *E) override { | ||||||
auto SR = E->getSourceRange(); | ||||||
if (SR.isValid() && SM.rangeContainsTokenLoc(SR, TargetLoc) && | ||||||
!checkCallExpr(E) && !EnclosingCallAndArg.first) { | ||||||
|
@@ -1732,13 +1736,13 @@ class PlaceholderExpansionScanner { | |||||
OuterExpr = E; | ||||||
} | ||||||
} | ||||||
return true; | ||||||
return Action::Continue(E); | ||||||
} | ||||||
|
||||||
bool walkToExprPost(Expr *E) override { | ||||||
PostWalkResult<Expr *> walkToExprPost(Expr *E) override { | ||||||
if (E->getStartLoc() == TargetLoc) | ||||||
return false; // found what we needed to find, stop walking. | ||||||
return true; | ||||||
return Action::Stop(); // found what we needed to find, stop walking. | ||||||
return Action::Continue(E); | ||||||
} | ||||||
|
||||||
/// Whether this statement body consists of only an implicit "return", | ||||||
|
@@ -1756,7 +1760,7 @@ class PlaceholderExpansionScanner { | |||||
|
||||||
// Before pre-checking, the implicit return will not have been | ||||||
// inserted. Look for a single expression body in a closure. | ||||||
if (auto *ParentE = getWalker().Parent.getAsExpr()) { | ||||||
if (auto *ParentE = Parent.getAsExpr()) { | ||||||
if (isa<ClosureExpr>(ParentE)) { | ||||||
if (auto *innerE = BS->getSingleActiveExpression()) | ||||||
return innerE->getStartLoc() == TargetLoc; | ||||||
|
@@ -1767,7 +1771,7 @@ class PlaceholderExpansionScanner { | |||||
return false; | ||||||
} | ||||||
|
||||||
bool walkToStmtPre(Stmt *S) override { | ||||||
PreWalkResult<Stmt *> walkToStmtPre(Stmt *S) override { | ||||||
auto SR = S->getSourceRange(); | ||||||
if (SR.isValid() && SM.rangeContainsTokenLoc(SR, TargetLoc) && | ||||||
!isImplicitReturnBody(S)) { | ||||||
|
@@ -1791,17 +1795,29 @@ class PlaceholderExpansionScanner { | |||||
break; | ||||||
} | ||||||
} | ||||||
return true; | ||||||
return Action::Continue(S); | ||||||
} | ||||||
|
||||||
bool shouldWalkInactiveConfigRegion() override { return true; } | ||||||
PreWalkAction walkToDeclPre(Decl *D) override { | ||||||
if (auto *ICD = dyn_cast<IfConfigDecl>(D)) { | ||||||
for (auto Clause : ICD->getClauses()) { | ||||||
// Active clase elements are visited normally. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
if (Clause.isActive) | ||||||
continue; | ||||||
for (auto Member : Clause.Elements) | ||||||
Member.walk(*this); | ||||||
} | ||||||
return Action::SkipNode(); | ||||||
} | ||||||
return Action::Continue(); | ||||||
} | ||||||
|
||||||
ArgumentList *findEnclosingCallArg(SourceFile &SF, SourceLoc SL) { | ||||||
EnclosingCallAndArg = {nullptr, nullptr}; | ||||||
OuterExpr = nullptr; | ||||||
OuterStmt = nullptr; | ||||||
TargetLoc = SL; | ||||||
walk(SF); | ||||||
SF.walk(*this); | ||||||
return EnclosingCallAndArg.second; | ||||||
} | ||||||
}; | ||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could use
Action::StopIf
here if you wantThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, thanks for the tip! but let me merge this as is for now 🙏