Skip to content

Commit dac52cb

Browse files
committed
[Frontend] Move initial REPL file creation logic
Move the logic out of the frontend and into its only client, swift-ide-test.
1 parent 590f83c commit dac52cb

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

lib/Frontend/Frontend.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -779,15 +779,6 @@ void CompilerInstance::performSemaUpTo(SourceFile::ASTStage_t LimitStage) {
779779
// references, this can be removed.
780780
(void)MainModule->getImplicitImports();
781781

782-
if (Invocation.getInputKind() == InputFileKind::SwiftREPL) {
783-
// Create the initial empty REPL file. This only exists to feed in the
784-
// implicit imports such as the standard library.
785-
auto *replFile =
786-
createSourceFileForMainModule(SourceFileKind::Main, /*BufferID*/ None);
787-
performImportResolution(*replFile);
788-
return;
789-
}
790-
791782
// Make sure the main file is the first file in the module, so do this now.
792783
if (MainBufferID != NO_SUCH_BUFFER) {
793784
(void)createSourceFileForMainModule(Invocation.getSourceFileKind(),

tools/swift-ide-test/swift-ide-test.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -897,13 +897,21 @@ static int doREPLCodeCompletion(const CompilerInvocation &InitInvok,
897897
CI.addDiagnosticConsumer(&PrintDiags);
898898
if (CI.setup(Invocation))
899899
return 1;
900-
registerIDERequestFunctions(CI.getASTContext().evaluator);
901-
CI.performSema();
902-
903-
SourceFile &SF = CI.getMainModule()->getMainSourceFile(SourceFileKind::Main);
900+
auto &ctx = CI.getASTContext();
901+
registerIDERequestFunctions(ctx.evaluator);
902+
903+
// Create an initial empty SourceFile. This only exists to feed in the
904+
// implicit stdlib import.
905+
ImplicitImportInfo importInfo;
906+
importInfo.StdlibKind = ImplicitStdlibKind::Stdlib;
907+
auto *M = ModuleDecl::create(ctx.getIdentifier(Invocation.getModuleName()),
908+
ctx, importInfo);
909+
auto *SF = new (ctx) SourceFile(*M, SourceFileKind::Main, /*BufferID*/ None);
910+
M->addFile(*SF);
911+
performImportResolution(*SF);
904912

905913
REPLCompletions REPLCompl;
906-
REPLCompl.populate(SF, BufferText);
914+
REPLCompl.populate(*SF, BufferText);
907915
llvm::outs() << "Begin completions\n";
908916
for (StringRef S : REPLCompl.getCompletionList()) {
909917
llvm::outs() << S << "\n";

0 commit comments

Comments
 (0)