This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Avoid memory-mapping files on Windows
ClosedPublic

Authored by ilya-biryukov on Nov 30 2018, 11:50 AM.

Details

Summary

Memory-mapping files on Windows leads to them being locked and prevents
editors from saving changes to those files on disk. This is fine for the
compiler, but not acceptable for an interactive tool like clangd.
Therefore, we choose to avoid using memory-mapped files on Windows.

Diff Detail

Event Timeline

ilya-biryukov created this revision.Nov 30 2018, 11:50 AM

Hi Ilya. Does this apply to compile_commands.json too? I've seen that problem for that file as well. If not, I understand it can be another patch, just curious.

nik added a subscriber: nik.Dec 2 2018, 11:59 PM

Please fix this also for libclang clients. I think it's safe to assume that files might be edited once CXTranslationUnit_PrecompiledPreamble or CXTranslationUnit_CacheCompletionResults is set as flag - that's what clang_defaultEditingTranslationUnitOptions() returns.

kadircet accepted this revision.Dec 3 2018, 12:55 AM

LGTM

clangd/FSProvider.cpp
34

make_unique?

35

can we move once ?

This revision is now accepted and ready to land.Dec 3 2018, 12:55 AM
ilya-biryukov planned changes to this revision.Dec 3 2018, 2:45 AM

We need to keep mmapping the PCH files.

Hi Ilya. Does this apply to compile_commands.json too? I've seen that problem for that file as well. If not, I understand it can be another patch, just curious.

Yeah, this applies to all files, including compiler_commands.json.
I've discussed this with a few smart folks and they pointed out doing it for all files is not ok, most problematic are PCH files, which are (1) huge, (2) produced by clangd itself and never modified after being produced.
(1) means it's very wasteful to fully load them into memory, (2) means it can easily be avoided. That complicated things, though, and the current approach to fix this in libclang D54995 (passing an explicit flag when we know the file should be memory-mapped) starts to look more attractive.
I'll patch it up in this patch by looking at file name and avoiding that for PCH files. There are still PCM files, which are very similar, my hopes are they're not widely used on Windows these days so we should be fine for now, but that would definitely bite us in the future.

Please fix this also for libclang clients. I think it's safe to assume that files might be edited once CXTranslationUnit_PrecompiledPreamble or CXTranslationUnit_CacheCompletionResults is set as flag - that's what clang_defaultEditingTranslationUnitOptions() returns.

libclang clients should be covered by D54995 and previous changes around it. As I mentioned in the previous comment, passing a flag when file cannot be memory-mapped seems like a proper solution anyway.

yvvan added a subscriber: yvvan.Dec 3 2018, 3:20 AM
ilya-biryukov marked an inline comment as done.
  • Keep using memory-mapped files for PCHs
  • Move once
This revision is now accepted and ready to land.Dec 3 2018, 5:50 AM
ilya-biryukov marked an inline comment as done.Dec 3 2018, 5:50 AM
ilya-biryukov added inline comments.
clangd/FSProvider.cpp
34

Unfortunately it doesn't work here - VolatileFile is private in this class.

35

We need moar moves!!! xD

Thanks for noticing, fixed.

ilya-biryukov marked an inline comment as done.
  • s/VolatileFSProvider/VolatileFileSystem
This revision was automatically updated to reflect the committed changes.