Skip to content

Commit a22419f

Browse files
committed
Fix sourcekitd persistent file-locks on Windows
1 parent a8713ad commit a22419f

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

include/swift/Basic/SourceManager.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ class SourceManager {
9494
private:
9595
llvm::SourceMgr LLVMSourceMgr;
9696
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FileSystem;
97+
bool EditorMode = false;
9798
unsigned IDEInspectionTargetBufferID = 0U;
9899
unsigned IDEInspectionTargetOffset;
99100

@@ -166,6 +167,10 @@ class SourceManager {
166167
return FileSystem;
167168
}
168169

170+
void setEditorMode() {
171+
EditorMode = true;
172+
}
173+
169174
void setIDEInspectionTarget(unsigned BufferID, unsigned Offset) {
170175
assert(BufferID != 0U && "Buffer should be valid");
171176

lib/Basic/SourceLoc.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,11 @@ unsigned SourceManager::getExternalSourceBufferID(StringRef Path) {
695695
return It->getSecond();
696696
}
697697
unsigned Id = 0u;
698-
auto InputFileOrErr = swift::vfs::getFileOrSTDIN(*getFileSystem(), Path);
698+
auto InputFileOrErr =
699+
swift::vfs::getFileOrSTDIN(*getFileSystem(), Path,
700+
/* FileSize */ -1,
701+
/* RequiresNullTerminator */ true,
702+
/* isVolatile */ this->EditorMode);
699703
if (InputFileOrErr) {
700704
// This assertion ensures we can look up from the map in the future when
701705
// using the same Path.

lib/Frontend/Frontend.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,12 @@ bool CompilerInstance::setup(const CompilerInvocation &Invoke,
552552
if (LangOpts.EnableModuleLoadingRemarks) {
553553
Invocation.getSearchPathOptions().dump(LangOpts.Target.isOSDarwin());
554554
}
555+
556+
// If the compiler instance is managed by an IDE, inform the source manager to avoid
557+
// memory-mapping source files that are likely to be mutated in an editor.
558+
if (LangOpts.DiagnosticsEditorMode) {
559+
this->getSourceMgr().setEditorMode();
560+
}
555561

556562
// If we expect an implicit stdlib import, load in the standard library. If we
557563
// either fail to find it or encounter an error while loading it, bail early. Continuing will at best

0 commit comments

Comments
 (0)