[Serialization] Move loading swiftmodule files as volatile behind a flag

Introduce a new frontend flag -enable-volatile-modules to trigger
loading swiftmodule files as volatile and avoid using mmap. Revert the
default behavior to using mmap.
This commit is contained in:
Alexis Laferrière
2020-07-22 11:22:06 -07:00
parent 0ede7282bb
commit 2c66f0c75d
4 changed files with 12 additions and 2 deletions

View File

@@ -348,7 +348,8 @@ std::error_code SerializedModuleLoaderBase::openModuleFile(
// Actually load the file and error out if necessary.
//
// Use the default arguments except for IsVolatile. Force avoiding the use of
// Use the default arguments except for IsVolatile that is set by the
// frontend option -enable-volatile-modules. If set, we avoid the use of
// mmap to workaround issues on NFS when the swiftmodule file loaded changes
// on disk while it's in use.
//
@@ -361,11 +362,12 @@ std::error_code SerializedModuleLoaderBase::openModuleFile(
// the surface look like memory corruption.
//
// rdar://63755989
bool enableVolatileModules = Ctx.LangOpts.EnableVolatileModules;
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> ModuleOrErr =
FS.getBufferForFile(ModulePath,
/*FileSize=*/-1,
/*RequiresNullTerminator=*/true,
/*IsVolatile=*/true);
/*IsVolatile=*/enableVolatileModules);
if (!ModuleOrErr)
return ModuleOrErr.getError();