Skip to content

Commit d9a88b9

Browse files
authored
Merge pull request swiftlang#33052 from xymus/swiftmodule-files-are-volatile-opt
[Serialization] Move loading swiftmodule files as volatile behind a flag
2 parents 1bfe559 + 2c66f0c commit d9a88b9

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
@@ -372,6 +372,9 @@ namespace swift {
372372
/// Enable verification when every SubstitutionMap is constructed.
373373
bool VerifyAllSubstitutionMaps = false;
374374

375+
/// Load swiftmodule files in memory as volatile and avoid mmap.
376+
bool EnableVolatileModules = false;
377+
375378
/// Sets the target we are building for and updates platform conditions
376379
/// to match.
377380
///

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
@@ -612,6 +612,8 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
612612

613613
Opts.VerifyAllSubstitutionMaps |= Args.hasArg(OPT_verify_all_substitution_maps);
614614

615+
Opts.EnableVolatileModules |= Args.hasArg(OPT_enable_volatile_modules);
616+
615617
Opts.UseDarwinPreStableABIBit =
616618
(Target.isMacOSX() && Target.isMacOSXVersionLT(10, 14, 4)) ||
617619
(Target.isiOS() && Target.isOSVersionLT(12, 2)) ||

lib/Serialization/SerializedModuleLoader.cpp

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

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

0 commit comments

Comments
 (0)