Skip to content

Commit ee9bf60

Browse files
committed
[NFC] Requestify Code Completion's Second Pass
Code Completion operates on a CompilerInstance that passes a primary file down for type checking. This means it creates and registers dependencies in the referenced name trackers. Despite the fact that those dependencty edges are unused, because the would-be swiftdeps file is never written to disk, it is still a dependency source that should participate in the request-based dependency tracking refactor.
1 parent c56e799 commit ee9bf60

File tree

6 files changed

+46
-8
lines changed

6 files changed

+46
-8
lines changed

include/swift/AST/ASTTypeIDZone.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ SWIFT_TYPEID(TypePair)
3030
SWIFT_TYPEID(TypeWitnessAndDecl)
3131
SWIFT_TYPEID(Witness)
3232
SWIFT_TYPEID_NAMED(ClosureExpr *, ClosureExpr)
33+
SWIFT_TYPEID_NAMED(CodeCompletionCallbacksFactory *,
34+
CodeCompletionCallbacksFactory)
3335
SWIFT_TYPEID_NAMED(ConstructorDecl *, ConstructorDecl)
3436
SWIFT_TYPEID_NAMED(CustomAttr *, CustomAttr)
3537
SWIFT_TYPEID_NAMED(Decl *, Decl)

include/swift/AST/ASTTypeIDs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ namespace swift {
2424
class AbstractFunctionDecl;
2525
class BraceStmt;
2626
class ClosureExpr;
27+
class CodeCompletionCallbacksFactory;
2728
class ConstructorDecl;
2829
class CustomAttr;
2930
class Decl;

include/swift/AST/ParseRequests.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,24 @@ class ParseSourceFileRequest
101101
void cacheResult(ArrayRef<Decl *> decls) const;
102102
};
103103

104+
void simple_display(llvm::raw_ostream &out,
105+
const CodeCompletionCallbacksFactory *factory);
106+
107+
class CodeCompletionSecondPassRequest
108+
: public SimpleRequest<CodeCompletionSecondPassRequest,
109+
bool(SourceFile *, CodeCompletionCallbacksFactory *),
110+
CacheKind::Uncached> {
111+
public:
112+
using SimpleRequest::SimpleRequest;
113+
114+
private:
115+
friend SimpleRequest;
116+
117+
// Evaluation.
118+
bool evaluate(Evaluator &evaluator, SourceFile *SF,
119+
CodeCompletionCallbacksFactory *Factory) const;
120+
};
121+
104122
/// The zone number for the parser.
105123
#define SWIFT_TYPEID_ZONE Parse
106124
#define SWIFT_TYPEID_HEADER "swift/AST/ParseTypeIDZone.def"

include/swift/AST/ParseTypeIDZone.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
//
1515
//===----------------------------------------------------------------------===//
1616

17+
SWIFT_REQUEST(Parse, CodeCompletionSecondPassRequest,
18+
bool (SourceFile *, CodeCompletionCallbacksFactory *),
19+
Uncached, NoLocationInfo)
1720
SWIFT_REQUEST(Parse, ParseMembersRequest,
1821
FingerprintAndMembers(IterableDeclContext *), Cached, NoLocationInfo)
1922
SWIFT_REQUEST(Parse, ParseAbstractFunctionBodyRequest,

lib/Parse/ParseRequests.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,14 @@ void ParseSourceFileRequest::cacheResult(ArrayRef<Decl *> decls) const {
181181
verify(*SF);
182182
}
183183

184+
//----------------------------------------------------------------------------//
185+
// CodeCompletionSecondPassRequest computation.
186+
//----------------------------------------------------------------------------//
187+
188+
189+
void swift::simple_display(llvm::raw_ostream &out,
190+
const CodeCompletionCallbacksFactory *factory) { }
191+
184192
// Define request evaluation functions for each of the type checker requests.
185193
static AbstractRequestFunction *parseRequestFunctions[] = {
186194
#define SWIFT_REQUEST(Zone, Name, Sig, Caching, LocOptions) \

lib/Parse/Parser.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,25 +114,31 @@ void SILParserTUStateBase::anchor() { }
114114

115115
void swift::performCodeCompletionSecondPass(
116116
SourceFile &SF, CodeCompletionCallbacksFactory &Factory) {
117+
return (void)evaluateOrDefault(SF.getASTContext().evaluator,
118+
CodeCompletionSecondPassRequest{&SF, &Factory},
119+
false);
120+
}
121+
122+
bool CodeCompletionSecondPassRequest::evaluate(
123+
Evaluator &evaluator, SourceFile *SF,
124+
CodeCompletionCallbacksFactory *Factory) const {
117125
// If we didn't find the code completion token, bail.
118-
auto *parserState = SF.getDelayedParserState();
126+
auto *parserState = SF->getDelayedParserState();
119127
if (!parserState->hasCodeCompletionDelayedDeclState())
120-
return;
128+
return true;
121129

122130
auto state = parserState->takeCodeCompletionDelayedDeclState();
123-
auto &Ctx = SF.getASTContext();
124-
125-
FrontendStatsTracer tracer(Ctx.Stats,
126-
"CodeCompletionSecondPass");
131+
auto &Ctx = SF->getASTContext();
127132

128133
auto BufferID = Ctx.SourceMgr.getCodeCompletionBufferID();
129-
Parser TheParser(BufferID, SF, nullptr, parserState, nullptr);
134+
Parser TheParser(BufferID, *SF, nullptr, parserState, nullptr);
130135

131136
std::unique_ptr<CodeCompletionCallbacks> CodeCompletion(
132-
Factory.createCodeCompletionCallbacks(TheParser));
137+
Factory->createCodeCompletionCallbacks(TheParser));
133138
TheParser.setCodeCompletionCallbacks(CodeCompletion.get());
134139

135140
TheParser.performCodeCompletionSecondPassImpl(*state);
141+
return true;
136142
}
137143

138144
void Parser::performCodeCompletionSecondPassImpl(

0 commit comments

Comments
 (0)