Skip to content

Commit d1343c8

Browse files
committed
[Frontend] Intro flags to control deserialization safety
Deserialization safety remains off by default at the moment.
1 parent c76dab7 commit d1343c8

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

include/swift/Basic/LangOptions.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,11 +357,15 @@ namespace swift {
357357
bool EnableTargetOSChecking = true;
358358

359359
/// Whether to attempt to recover from missing cross-references and other
360-
/// errors when deserializing from a Swift module.
360+
/// errors when deserializing from a binary swiftmodule file.
361361
///
362-
/// This is a staging flag; eventually it will be removed.
362+
/// This flag should only be used in testing.
363363
bool EnableDeserializationRecovery = true;
364364

365+
/// Enable early skipping deserialization of decls that are marked as
366+
/// unsafe to read.
367+
bool EnableDeserializationSafety = false;
368+
365369
/// Whether to enable the new operator decl and precedencegroup lookup
366370
/// behavior. This is a staging flag, and will be removed in the future.
367371
bool EnableNewOperatorLookup = false;

include/swift/Option/FrontendOptions.td

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,13 @@ def disable_deserialization_recovery :
564564
Flag<["-"], "disable-deserialization-recovery">,
565565
HelpText<"Don't attempt to recover from missing xrefs (etc) in swiftmodules">;
566566

567+
def enable_deserialization_safety :
568+
Flag<["-"], "enable-deserialization-safety">,
569+
HelpText<"Avoid reading potentially unsafe decls in swiftmodules">;
570+
def disable_deserialization_safety :
571+
Flag<["-"], "disable-deserialization-safety">,
572+
HelpText<"Don't avoid reading potentially unsafe decls in swiftmodules">;
573+
567574
def enable_experimental_string_processing :
568575
Flag<["-"], "enable-experimental-string-processing">,
569576
HelpText<"Enable experimental string processing">;

lib/Frontend/CompilerInvocation.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,12 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
500500
= A->getOption().matches(OPT_enable_deserialization_recovery);
501501
}
502502

503+
if (auto A = Args.getLastArg(OPT_enable_deserialization_safety,
504+
OPT_disable_deserialization_safety)) {
505+
Opts.EnableDeserializationSafety
506+
= A->getOption().matches(OPT_enable_deserialization_safety);
507+
}
508+
503509
// Whether '/.../' regex literals are enabled. This implies experimental
504510
// string processing.
505511
if (Args.hasArg(OPT_enable_bare_slash_regex)) {

lib/Frontend/Frontend.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,11 @@ bool CompilerInstance::setUpASTContextIfNeeded() {
274274

275275
registerIRGenSILTransforms(*Context);
276276

277+
if (Invocation.getFrontendOptions().RequestedAction ==
278+
FrontendOptions::ActionType::MergeModules ||
279+
Invocation.getLangOptions().DebuggerSupport)
280+
Invocation.getLangOptions().EnableDeserializationSafety = false;
281+
277282
if (setUpModuleLoaders())
278283
return true;
279284

0 commit comments

Comments
 (0)