Skip to content

Commit c7053b8

Browse files
committed
[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. rdar://63755989
1 parent 8b9dd95 commit c7053b8

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

include/swift/Basic/LangOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,9 @@ namespace swift {
350350
/// If set to \c false, fall back to the legacy manual reference name tracking code.
351351
bool EnableRequestBasedIncrementalDependencies = true;
352352

353+
/// Load swiftmodule files in memory as volatile and avoid mmap.
354+
bool EnableVolatileModules = false;
355+
353356
/// Sets the target we are building for and updates platform conditions
354357
/// to match.
355358
///

include/swift/Option/FrontendOptions.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,9 @@ def warn_long_expression_type_checking_EQ : Joined<["-"], "warn-long-expression-
455455
def Rmodule_interface_rebuild : Flag<["-"], "Rmodule-interface-rebuild">,
456456
HelpText<"Emits a remark if an imported module needs to be re-compiled from its module interface">;
457457

458+
def enable_volatile_modules : Flag<["-"], "enable-volatile-modules">,
459+
HelpText<"Load Swift modules in memory">;
460+
458461
def solver_expression_time_threshold_EQ : Joined<["-"], "solver-expression-time-threshold=">;
459462

460463
def solver_disable_shrink :

lib/Frontend/CompilerInvocation.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,8 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
583583

584584
Opts.VerifyAllSubstitutionMaps |= Args.hasArg(OPT_verify_all_substitution_maps);
585585

586+
Opts.EnableVolatileModules |= Args.hasArg(OPT_enable_volatile_modules);
587+
586588
Opts.UseDarwinPreStableABIBit =
587589
(Target.isMacOSX() && Target.isMacOSXVersionLT(10, 14, 4)) ||
588590
(Target.isiOS() && Target.isOSVersionLT(12, 2)) ||

lib/Serialization/SerializedModuleLoader.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,8 @@ std::error_code SerializedModuleLoaderBase::openModuleFile(
338338

339339
// Actually load the file and error out if necessary.
340340
//
341-
// Use the default arguments except for IsVolatile. Force avoiding the use of
341+
// Use the default arguments except for IsVolatile that is set by the
342+
// frontend option -enable-volatile-modules. If set, we avoid the use of
342343
// mmap to workaround issues on NFS when the swiftmodule file loaded changes
343344
// on disk while it's in use.
344345
//
@@ -351,11 +352,12 @@ std::error_code SerializedModuleLoaderBase::openModuleFile(
351352
// the surface look like memory corruption.
352353
//
353354
// rdar://63755989
355+
bool enableVolatileModules = Ctx.LangOpts.EnableVolatileModules;
354356
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> ModuleOrErr =
355357
FS.getBufferForFile(ModulePath,
356358
/*FileSize=*/-1,
357359
/*RequiresNullTerminator=*/true,
358-
/*IsVolatile=*/true);
360+
/*IsVolatile=*/enableVolatileModules);
359361
if (!ModuleOrErr)
360362
return ModuleOrErr.getError();
361363

0 commit comments

Comments
 (0)