[CursorInfo] Fix issues found by the stress tester

This commit is contained in:
Alex Hoppen
2023-02-15 23:04:05 +01:00
parent eb6729754d
commit e5c521c999
7 changed files with 55 additions and 12 deletions

View File

@@ -26,7 +26,7 @@ namespace ide {
class CursorInfoConsumer {
public:
virtual ~CursorInfoConsumer() {}
virtual void handleResults(SmallVector<ResolvedCursorInfoPtr>) = 0;
virtual void handleResults(std::vector<ResolvedCursorInfoPtr>) = 0;
};
/// Create a factory for code completion callbacks.

View File

@@ -82,7 +82,7 @@ struct ConformingMethodListResults {
/// The results returned from \c IDEInspectionInstance::cursorInfo.
struct CursorInfoResults {
/// The actual results.
SmallVector<ResolvedCursorInfoPtr> ResolvedCursorInfos;
std::vector<ResolvedCursorInfoPtr> ResolvedCursorInfos;
/// Whether an AST was reused to produce the results.
bool DidReuseAST;
};

View File

@@ -216,7 +216,9 @@ private:
if (auto CaptureList = dyn_cast<CaptureListExpr>(E)) {
for (auto ShorthandShadows :
getShorthandShadows(CaptureList, getCurrentDeclContext())) {
assert(ShorthandShadowedDecls.count(ShorthandShadows.first) == 0);
assert(ShorthandShadowedDecls.count(ShorthandShadows.first) == 0 ||
ShorthandShadowedDecls[ShorthandShadows.first] ==
ShorthandShadows.second);
ShorthandShadowedDecls[ShorthandShadows.first] =
ShorthandShadows.second;
}
@@ -346,7 +348,7 @@ public:
: IDEInspectionCallbacks(P), Consumer(Consumer),
RequestedLoc(RequestedLoc) {}
SmallVector<ResolvedCursorInfoPtr>
std::vector<ResolvedCursorInfoPtr>
getDeclResult(NodeFinderDeclResult *DeclResult, SourceFile *SrcFile,
NodeFinder &Finder) const {
typeCheckDeclAndParentClosures(DeclResult->getDecl());
@@ -363,7 +365,7 @@ public:
return {CursorInfo};
}
SmallVector<ResolvedCursorInfoPtr>
std::vector<ResolvedCursorInfoPtr>
getExprResult(NodeFinderExprResult *ExprResult, SourceFile *SrcFile,
NodeFinder &Finder) const {
Expr *E = ExprResult->getExpr();
@@ -371,10 +373,12 @@ public:
// Type check the statemnt containing E and listen for solutions.
CursorInfoTypeCheckSolutionCallback Callback(*DC, RequestedLoc);
llvm::SaveAndRestore<TypeCheckCompletionCallback *> CompletionCollector(
DC->getASTContext().SolutionCallback, &Callback);
typeCheckASTNodeAtLoc(TypeCheckASTNodeAtLocContext::declContext(DC),
E->getLoc());
{
llvm::SaveAndRestore<TypeCheckCompletionCallback *> CompletionCollector(
DC->getASTContext().SolutionCallback, &Callback);
typeCheckASTNodeAtLoc(TypeCheckASTNodeAtLocContext::declContext(DC),
E->getLoc());
}
if (Callback.getResults().empty()) {
// No results.
@@ -389,9 +393,14 @@ public:
// Deliver results
SmallVector<ResolvedCursorInfoPtr> Results;
std::vector<ResolvedCursorInfoPtr> Results;
for (auto Res : Callback.getResults()) {
SmallVector<NominalTypeDecl *> ReceiverTypes;
if (isa<ModuleDecl>(Res.ReferencedDecl)) {
// ResolvedModuleRefCursorInfo is not supported by solver-based cursor
// info yet.
continue;
}
if (Res.IsDynamicRef && Res.BaseType) {
if (auto ReceiverType = Res.BaseType->getAnyNominal()) {
ReceiverTypes = {ReceiverType};
@@ -426,7 +435,7 @@ public:
if (!Result) {
return;
}
SmallVector<ResolvedCursorInfoPtr> CursorInfo;
std::vector<ResolvedCursorInfoPtr> CursorInfo;
switch (Result->getKind()) {
case NodeFinderResultKind::Decl:
CursorInfo = getDeclResult(cast<NodeFinderDeclResult>(Result.get()),

View File

@@ -827,7 +827,7 @@ void swift::ide::IDEInspectionInstance::cursorInfo(
: ReusingASTContext(ReusingASTContext),
CancellationFlag(CancellationFlag), Callback(Callback) {}
void handleResults(SmallVector<ResolvedCursorInfoPtr> result) override {
void handleResults(std::vector<ResolvedCursorInfoPtr> result) override {
HandleResultsCalled = true;
if (CancellationFlag &&
CancellationFlag->load(std::memory_order_relaxed)) {

View File

@@ -0,0 +1,19 @@
struct GorEach<Data, Content> {
public init(_ data: Data, content: (Data) -> Void) {}
}
struct MavigationLink<Label, Destination> {
init(destination: PeopleDetail) {}
}
struct PeopleDetail {
init(peopleId: Int) {}
}
func test(peoples: [Int]) {
GorEach(peoples) { people in
// Should not crash
// RUN: %sourcekitd-test -req=cursor -pos=%(line + 1):56 %s -- %s
MavigationLink(destination: PeopleDetail(peopleId: people))
}
}

View File

@@ -0,0 +1,8 @@
class Items {
func test() {
// Should not crash
// RUN: %sourcekitd-test -req=cursor -pos=%(line + 1):9 %s -- %s
_ = Invalid.sink { [weak self] items in
}
}
}

View File

@@ -0,0 +1,7 @@
func test() {
// RUN: %sourcekitd-test -req=cursor -pos=%(line + 1):3 %s -- %s | %FileCheck %s
Swift.min
}
// CHECK: source.lang.swift.ref.module ()
// CHECK-NEXT: Swift