Skip to content

Commit fb8c418

Browse files
Avoid memory mapping source files opened by SourceKit.
1 parent 5f3f845 commit fb8c418

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

lib/Frontend/Frontend.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -938,11 +938,13 @@ CompilerInstance::getInputBuffersIfPresent(const InputFile &input) {
938938
// FIXME: Working with filenames is fragile, maybe use the real path
939939
// or have some kind of FileManager.
940940
using FileOrError = llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>;
941+
// Avoid memory-mapping when the compiler is run for IDE inspection,
942+
// since that would prevent the user from saving the file.
941943
FileOrError inputFileOrErr =
942944
swift::vfs::getFileOrSTDIN(getFileSystem(), input.getFileName(),
943945
/*FileSize*/-1,
944946
/*RequiresNullTerminator*/true,
945-
/*IsVolatile*/false,
947+
/*IsVolatile*/getInvocation().isIDEInspection(),
946948
/*Bad File Descriptor Retry*/getInvocation().getFrontendOptions()
947949
.BadFileDescriptorRetryCount);
948950
if (!inputFileOrErr) {

tools/SourceKit/lib/SwiftLang/SwiftASTManager.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -884,8 +884,11 @@ SwiftASTManager::Implementation::getMemoryBuffer(
884884
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FileSystem,
885885
std::string &Error) const {
886886
assert(FileSystem);
887+
// Avoid memory-mapping as it could prevent the user from
888+
// saving the file in the editor.
887889
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> FileBufOrErr =
888-
FileSystem->getBufferForFile(Filename);
890+
FileSystem->getBufferForFile(Filename, /*FileSize*/-1,
891+
/*RequiresNullTerminator*/true, /*IsVolatile*/true);
889892
if (FileBufOrErr)
890893
return std::move(FileBufOrErr.get());
891894

0 commit comments

Comments
 (0)