[SourceKit] Add a request to generate object files in SourceKit

Add 'request.compile'
This commit is contained in:
Rintaro Ishizaki
2021-12-20 13:33:50 -08:00
parent 21e13c436c
commit 7c92a8e555
36 changed files with 1000 additions and 84 deletions

View File

@@ -24,6 +24,7 @@
#include "swift/AST/DiagnosticConsumer.h"
#include "swift/Basic/ThreadSafeRefCounted.h"
#include "swift/IDE/CancellableResult.h"
#include "swift/IDE/CompileInstance.h"
#include "swift/IDE/CompletionInstance.h"
#include "swift/IDE/Indenting.h"
#include "swift/IDE/Refactoring.h"
@@ -296,6 +297,51 @@ public:
const swift::DiagnosticInfo &Info) override;
};
namespace compile {
class Session {
swift::ide::CompileInstance Compiler;
public:
Session(const std::string &RuntimeResourcePath,
const std::string &DiagnosticDocumentationPath)
: Compiler(RuntimeResourcePath, DiagnosticDocumentationPath) {}
bool
performCompile(llvm::ArrayRef<const char *> Args,
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FileSystem,
swift::DiagnosticConsumer *DiagC,
std::shared_ptr<std::atomic<bool>> CancellationFlag) {
return Compiler.performCompile(Args, FileSystem, DiagC, CancellationFlag);
}
};
class SessionManager {
const std::string &RuntimeResourcePath;
const std::string &DiagnosticDocumentationPath;
llvm::StringMap<std::shared_ptr<Session>> sessions;
WorkQueue compileQueue{WorkQueue::Dequeuing::Concurrent,
"sourcekit.swift.Compile"};
mutable llvm::sys::Mutex mtx;
public:
SessionManager(std::string &RuntimeResourcePath,
std::string &DiagnosticDocumentationPath)
: RuntimeResourcePath(RuntimeResourcePath),
DiagnosticDocumentationPath(DiagnosticDocumentationPath) {}
std::shared_ptr<Session> getSession(StringRef name);
void clearSession(StringRef name);
void performCompileAsync(
StringRef Name, ArrayRef<const char *> Args,
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fileSystem,
std::shared_ptr<std::atomic<bool>> CancellationFlag,
std::function<void(const RequestResult<CompilationResult> &)> Receiver);
};
} // namespace compile
struct SwiftStatistics {
#define SWIFT_STATISTIC(VAR, UID, DESC) \
Statistic VAR{UIdent{"source.statistic." #UID}, DESC};
@@ -317,6 +363,7 @@ class SwiftLangSupport : public LangSupport {
std::shared_ptr<SwiftStatistics> Stats;
llvm::StringMap<std::unique_ptr<FileSystemProvider>> FileSystemProviders;
std::shared_ptr<swift::ide::CompletionInstance> CompletionInst;
compile::SessionManager CompileManager;
public:
explicit SwiftLangSupport(SourceKit::Context &SKCtx);
@@ -682,6 +729,15 @@ public:
ConformingMethodListConsumer &Consumer,
Optional<VFSOptions> vfsOptions) override;
void
performCompile(StringRef Name, ArrayRef<const char *> Args,
Optional<VFSOptions> vfsOptions,
SourceKitCancellationToken CancellationToken,
std::function<void(const RequestResult<CompilationResult> &)>
Receiver) override;
void closeCompile(StringRef Name) override;
void getStatistics(StatisticsReceiver) override;
private: