Skip to content

Commit f2a30bb

Browse files
committed
IDE: cache resolved cursor info in the request evaluator
Resolving cursor info is a necessary step both when checking the availability of a refactoring kind and performing the refactoring action. These two steps are two high-level sourcekitd requests issued from IDE. By caching the result of the resolved cursor info in the evaluator of the ASTContext, we can reuse the cursor info result across these separate IDE requests.
1 parent 8915cf8 commit f2a30bb

File tree

5 files changed

+69
-2
lines changed

5 files changed

+69
-2
lines changed

include/swift/IDE/IDERequests.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "swift/AST/Evaluator.h"
2121
#include "swift/AST/SimpleRequest.h"
2222
#include "swift/IDE/Utils.h"
23+
#include "swift/IDE/IDETypeIDs.h"
2324

2425
namespace swift {
2526

@@ -56,7 +57,7 @@ void simple_display(llvm::raw_ostream &out, const CursorInfoOwner &owner);
5657
class CursorInfoRequest:
5758
public SimpleRequest<CursorInfoRequest,
5859
ide::ResolvedCursorInfo(CursorInfoOwner),
59-
CacheKind::Uncached> // FIXME: cache these
60+
CacheKind::Cached>
6061
{
6162
public:
6263
using SimpleRequest::SimpleRequest;

include/swift/IDE/IDETypeIDZone.def

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//===---------- IDETypeIDZone.def ------------------------------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
//
13+
// This definition file describes the types in the IDE type
14+
// TypeID zone, for use with the TypeID template.
15+
//
16+
//===----------------------------------------------------------------------===//
17+
SWIFT_TYPEID_NAMED(ide::ResolvedCursorInfo, ResolvedCursorInfo)

include/swift/IDE/IDETypeIDs.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//===--- IDETypeIDs.h - IDE Type Ids ----------------------------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2019 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
//
13+
// This file defines TypeID support for IDE types.
14+
//
15+
//===----------------------------------------------------------------------===//
16+
17+
#ifndef SWIFT_IDE_IDETYPEIDS_H
18+
#define SWIFT_IDE_IDETYPEIDS_H
19+
20+
#include "swift/Basic/TypeID.h"
21+
namespace swift {
22+
23+
#define SWIFT_IDE_TYPEID_ZONE 136
24+
#define SWIFT_TYPEID_ZONE SWIFT_IDE_TYPEID_ZONE
25+
#define SWIFT_TYPEID_HEADER "swift/IDE/IDETypeIDZone.def"
26+
#include "swift/Basic/DefineTypeIDZone.h"
27+
28+
} // end namespace swift
29+
30+
#endif // SWIFT_IDE_IDETYPEIDS_H

include/swift/IDE/Utils.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,13 @@ struct ResolvedCursorInfo {
163163

164164
ResolvedCursorInfo() = default;
165165
ResolvedCursorInfo(SourceFile *SF) : SF(SF) {}
166-
166+
167+
friend bool operator==(const ResolvedCursorInfo &lhs,
168+
const ResolvedCursorInfo &rhs) {
169+
return lhs.SF == rhs.SF &&
170+
lhs.Loc.getOpaquePointerValue() == rhs.Loc.getOpaquePointerValue();
171+
}
172+
167173
void setValueRef(ValueDecl *ValueD,
168174
TypeDecl *CtorTyRef,
169175
ExtensionDecl *ExtTyRef,
@@ -196,6 +202,8 @@ struct ResolvedCursorInfo {
196202
bool isInvalid() const { return Kind == CursorInfoKind::Invalid; }
197203
};
198204

205+
void simple_display(llvm::raw_ostream &out, const ResolvedCursorInfo &info);
206+
199207
struct UnresolvedLoc {
200208
SourceLoc Loc;
201209
bool ResolveArgLocs;

lib/IDE/IDERequests.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,17 @@ void swift::simple_display(llvm::raw_ostream &out, const CursorInfoOwner &owner)
303303
out << ":" << LC.first << ":" << LC.second;
304304
}
305305

306+
void swift::ide::simple_display(llvm::raw_ostream &out,
307+
const ide::ResolvedCursorInfo &info) {
308+
if (info.isInvalid())
309+
return;
310+
out << "Resolved cursor info at ";
311+
auto &SM = info.SF->getASTContext().SourceMgr;
312+
out << SM.getIdentifierForBuffer(*info.SF->getBufferID());
313+
auto LC = SM.getLineAndColumn(info.Loc);
314+
out << ":" << LC.first << ":" << LC.second;
315+
}
316+
306317
// Define request evaluation functions for each of the IDE requests.
307318
static AbstractRequestFunction *ideRequestFunctions[] = {
308319
#define SWIFT_TYPEID(Name) \

0 commit comments

Comments
 (0)