From 2c66f0c75de8fa29ce93984f7ece2d727e706f93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexis=20Laferrie=CC=80re?= Date: Wed, 22 Jul 2020 11:22:06 -0700 Subject: [PATCH] [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. --- include/swift/Basic/LangOptions.h | 3 +++ include/swift/Option/FrontendOptions.td | 3 +++ lib/Frontend/CompilerInvocation.cpp | 2 ++ lib/Serialization/SerializedModuleLoader.cpp | 6 ++++-- 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/include/swift/Basic/LangOptions.h b/include/swift/Basic/LangOptions.h index 9456b729871b3..60a9099da2b96 100644 --- a/include/swift/Basic/LangOptions.h +++ b/include/swift/Basic/LangOptions.h @@ -372,6 +372,9 @@ namespace swift { /// Enable verification when every SubstitutionMap is constructed. bool VerifyAllSubstitutionMaps = false; + /// Load swiftmodule files in memory as volatile and avoid mmap. + bool EnableVolatileModules = false; + /// Sets the target we are building for and updates platform conditions /// to match. /// diff --git a/include/swift/Option/FrontendOptions.td b/include/swift/Option/FrontendOptions.td index d465a0f1dfb71..e9e824b733c7b 100644 --- a/include/swift/Option/FrontendOptions.td +++ b/include/swift/Option/FrontendOptions.td @@ -457,6 +457,9 @@ def warn_long_expression_type_checking_EQ : Joined<["-"], "warn-long-expression- def Rmodule_interface_rebuild : Flag<["-"], "Rmodule-interface-rebuild">, HelpText<"Emits a remark if an imported module needs to be re-compiled from its module interface">; +def enable_volatile_modules : Flag<["-"], "enable-volatile-modules">, + HelpText<"Load Swift modules in memory">; + def solver_expression_time_threshold_EQ : Joined<["-"], "solver-expression-time-threshold=">; def solver_disable_shrink : diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 78c93dd5fdb71..a638daef23644 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -599,6 +599,8 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args, Opts.VerifyAllSubstitutionMaps |= Args.hasArg(OPT_verify_all_substitution_maps); + Opts.EnableVolatileModules |= Args.hasArg(OPT_enable_volatile_modules); + Opts.UseDarwinPreStableABIBit = (Target.isMacOSX() && Target.isMacOSXVersionLT(10, 14, 4)) || (Target.isiOS() && Target.isOSVersionLT(12, 2)) || diff --git a/lib/Serialization/SerializedModuleLoader.cpp b/lib/Serialization/SerializedModuleLoader.cpp index 9a33b4a4b8f2a..88a8bd2731769 100644 --- a/lib/Serialization/SerializedModuleLoader.cpp +++ b/lib/Serialization/SerializedModuleLoader.cpp @@ -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> ModuleOrErr = FS.getBufferForFile(ModulePath, /*FileSize=*/-1, /*RequiresNullTerminator=*/true, - /*IsVolatile=*/true); + /*IsVolatile=*/enableVolatileModules); if (!ModuleOrErr) return ModuleOrErr.getError();