Skip to content

Commit e5c521c

Browse files
committed
[CursorInfo] Fix issues found by the stress tester
1 parent eb67297 commit e5c521c

File tree

7 files changed

+55
-12
lines changed

7 files changed

+55
-12
lines changed

include/swift/IDE/CursorInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace ide {
2626
class CursorInfoConsumer {
2727
public:
2828
virtual ~CursorInfoConsumer() {}
29-
virtual void handleResults(SmallVector<ResolvedCursorInfoPtr>) = 0;
29+
virtual void handleResults(std::vector<ResolvedCursorInfoPtr>) = 0;
3030
};
3131

3232
/// Create a factory for code completion callbacks.

include/swift/IDETool/IDEInspectionInstance.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ struct ConformingMethodListResults {
8282
/// The results returned from \c IDEInspectionInstance::cursorInfo.
8383
struct CursorInfoResults {
8484
/// The actual results.
85-
SmallVector<ResolvedCursorInfoPtr> ResolvedCursorInfos;
85+
std::vector<ResolvedCursorInfoPtr> ResolvedCursorInfos;
8686
/// Whether an AST was reused to produce the results.
8787
bool DidReuseAST;
8888
};

lib/IDE/CursorInfo.cpp

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,9 @@ class NodeFinder : ASTWalker {
216216
if (auto CaptureList = dyn_cast<CaptureListExpr>(E)) {
217217
for (auto ShorthandShadows :
218218
getShorthandShadows(CaptureList, getCurrentDeclContext())) {
219-
assert(ShorthandShadowedDecls.count(ShorthandShadows.first) == 0);
219+
assert(ShorthandShadowedDecls.count(ShorthandShadows.first) == 0 ||
220+
ShorthandShadowedDecls[ShorthandShadows.first] ==
221+
ShorthandShadows.second);
220222
ShorthandShadowedDecls[ShorthandShadows.first] =
221223
ShorthandShadows.second;
222224
}
@@ -346,7 +348,7 @@ class CursorInfoDoneParsingCallback : public IDEInspectionCallbacks {
346348
: IDEInspectionCallbacks(P), Consumer(Consumer),
347349
RequestedLoc(RequestedLoc) {}
348350

349-
SmallVector<ResolvedCursorInfoPtr>
351+
std::vector<ResolvedCursorInfoPtr>
350352
getDeclResult(NodeFinderDeclResult *DeclResult, SourceFile *SrcFile,
351353
NodeFinder &Finder) const {
352354
typeCheckDeclAndParentClosures(DeclResult->getDecl());
@@ -363,18 +365,20 @@ class CursorInfoDoneParsingCallback : public IDEInspectionCallbacks {
363365
return {CursorInfo};
364366
}
365367

366-
SmallVector<ResolvedCursorInfoPtr>
368+
std::vector<ResolvedCursorInfoPtr>
367369
getExprResult(NodeFinderExprResult *ExprResult, SourceFile *SrcFile,
368370
NodeFinder &Finder) const {
369371
Expr *E = ExprResult->getExpr();
370372
DeclContext *DC = ExprResult->getDeclContext();
371373

372374
// Type check the statemnt containing E and listen for solutions.
373375
CursorInfoTypeCheckSolutionCallback Callback(*DC, RequestedLoc);
374-
llvm::SaveAndRestore<TypeCheckCompletionCallback *> CompletionCollector(
375-
DC->getASTContext().SolutionCallback, &Callback);
376-
typeCheckASTNodeAtLoc(TypeCheckASTNodeAtLocContext::declContext(DC),
377-
E->getLoc());
376+
{
377+
llvm::SaveAndRestore<TypeCheckCompletionCallback *> CompletionCollector(
378+
DC->getASTContext().SolutionCallback, &Callback);
379+
typeCheckASTNodeAtLoc(TypeCheckASTNodeAtLocContext::declContext(DC),
380+
E->getLoc());
381+
}
378382

379383
if (Callback.getResults().empty()) {
380384
// No results.
@@ -389,9 +393,14 @@ class CursorInfoDoneParsingCallback : public IDEInspectionCallbacks {
389393

390394
// Deliver results
391395

392-
SmallVector<ResolvedCursorInfoPtr> Results;
396+
std::vector<ResolvedCursorInfoPtr> Results;
393397
for (auto Res : Callback.getResults()) {
394398
SmallVector<NominalTypeDecl *> ReceiverTypes;
399+
if (isa<ModuleDecl>(Res.ReferencedDecl)) {
400+
// ResolvedModuleRefCursorInfo is not supported by solver-based cursor
401+
// info yet.
402+
continue;
403+
}
395404
if (Res.IsDynamicRef && Res.BaseType) {
396405
if (auto ReceiverType = Res.BaseType->getAnyNominal()) {
397406
ReceiverTypes = {ReceiverType};
@@ -426,7 +435,7 @@ class CursorInfoDoneParsingCallback : public IDEInspectionCallbacks {
426435
if (!Result) {
427436
return;
428437
}
429-
SmallVector<ResolvedCursorInfoPtr> CursorInfo;
438+
std::vector<ResolvedCursorInfoPtr> CursorInfo;
430439
switch (Result->getKind()) {
431440
case NodeFinderResultKind::Decl:
432441
CursorInfo = getDeclResult(cast<NodeFinderDeclResult>(Result.get()),

lib/IDETool/IDEInspectionInstance.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ void swift::ide::IDEInspectionInstance::cursorInfo(
827827
: ReusingASTContext(ReusingASTContext),
828828
CancellationFlag(CancellationFlag), Callback(Callback) {}
829829

830-
void handleResults(SmallVector<ResolvedCursorInfoPtr> result) override {
830+
void handleResults(std::vector<ResolvedCursorInfoPtr> result) override {
831831
HandleResultsCalled = true;
832832
if (CancellationFlag &&
833833
CancellationFlag->load(std::memory_order_relaxed)) {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
struct GorEach<Data, Content> {
2+
public init(_ data: Data, content: (Data) -> Void) {}
3+
}
4+
5+
struct MavigationLink<Label, Destination> {
6+
init(destination: PeopleDetail) {}
7+
}
8+
9+
struct PeopleDetail {
10+
init(peopleId: Int) {}
11+
}
12+
13+
func test(peoples: [Int]) {
14+
GorEach(peoples) { people in
15+
// Should not crash
16+
// RUN: %sourcekitd-test -req=cursor -pos=%(line + 1):56 %s -- %s
17+
MavigationLink(destination: PeopleDetail(peopleId: people))
18+
}
19+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class Items {
2+
func test() {
3+
// Should not crash
4+
// RUN: %sourcekitd-test -req=cursor -pos=%(line + 1):9 %s -- %s
5+
_ = Invalid.sink { [weak self] items in
6+
}
7+
}
8+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
func test() {
2+
// RUN: %sourcekitd-test -req=cursor -pos=%(line + 1):3 %s -- %s | %FileCheck %s
3+
Swift.min
4+
}
5+
6+
// CHECK: source.lang.swift.ref.module ()
7+
// CHECK-NEXT: Swift

0 commit comments

Comments
 (0)