Skip to content

Commit 25c6c16

Browse files
authored
Add frontend option -no-serialize-debugging-options (#20555)
By default, the frontend tries to figure out if the built module is likely to be distributed in some way, and uses that to decide whether to include options that help with debugging (such as local search paths). There's long been a -serialize-debugging-options that forces those options to be included even when it looks like a framework is being built, but the opposite has been absent until now. Note that both of these options are still /frontend/ options, not driver options, which means they could still change in the future. (I'd really like to get to a point where debugging doesn't need to sniff these options out from the module this way, but there are some complications we'd need to work out. Swift 1 expediency coming back to cause trouble again.) rdar://problem/37954803
1 parent df2307e commit 25c6c16

File tree

5 files changed

+18
-6
lines changed

5 files changed

+18
-6
lines changed

include/swift/Frontend/FrontendOptions.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,10 @@ class FrontendOptions {
146146
/// Indicates that the input(s) should be parsed as the Swift stdlib.
147147
bool ParseStdlib = false;
148148

149-
/// If set, emitted module files will always contain options for the
150-
/// debugger to use.
151-
bool AlwaysSerializeDebuggingOptions = false;
149+
/// When true, emitted module files will always contain options for the
150+
/// debugger to use. When unset, the options will only be present if the
151+
/// module appears to not be a public module.
152+
Optional<bool> SerializeOptionsForDebugging;
152153

153154
/// If set, inserts instrumentation useful for testing the debugger.
154155
bool DebuggerTestingTransform = false;

include/swift/Option/FrontendOptions.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ def print_clang_stats : Flag<["-"], "print-clang-stats">,
133133

134134
def serialize_debugging_options : Flag<["-"], "serialize-debugging-options">,
135135
HelpText<"Always serialize options for debugging (default: only for apps)">;
136+
def no_serialize_debugging_options :
137+
Flag<["-"], "no-serialize-debugging-options">,
138+
HelpText<"Never serialize options for debugging (default: only for apps)">;
136139

137140
def autolink_library : Separate<["-"], "autolink-library">,
138141
HelpText<"Add dependent library">, Flags<[FrontendOption]>;

lib/Frontend/ArgsToFrontendOptionsConverter.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,12 @@ bool ArgsToFrontendOptionsConverter::convert(
148148
if (const Arg *A = Args.getLastArg(OPT_module_link_name))
149149
Opts.ModuleLinkName = A->getValue();
150150

151-
Opts.AlwaysSerializeDebuggingOptions |=
152-
Args.hasArg(OPT_serialize_debugging_options);
151+
if (const Arg *A = Args.getLastArg(OPT_serialize_debugging_options,
152+
OPT_no_serialize_debugging_options)) {
153+
Opts.SerializeOptionsForDebugging =
154+
A->getOption().matches(OPT_serialize_debugging_options);
155+
}
156+
153157
Opts.EnableSourceImport |= Args.hasArg(OPT_enable_source_import);
154158
Opts.ImportUnderlyingModule |= Args.hasArg(OPT_import_underlying_module);
155159
Opts.EnableParseableModuleInterface |=

lib/Frontend/Frontend.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ CompilerInvocation::computeSerializationOptions(const SupplementaryOutputPaths &
141141
// so only serialize them if the module isn't going to be shipped to
142142
// the public.
143143
serializationOpts.SerializeOptionsForDebugging =
144-
!moduleIsPublic || opts.AlwaysSerializeDebuggingOptions;
144+
opts.SerializeOptionsForDebugging.getValueOr(!moduleIsPublic);
145145

146146
return serializationOpts;
147147
}

test/Serialization/search-paths.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
// RUN: %target-swift-frontend -emit-module -o %t -I %t/secret -F %t/Frameworks -Fsystem %t/SystemFrameworks -parse-as-library %S/Inputs/has_xref.swift -application-extension
1818
// RUN: %target-swift-frontend %s -typecheck -I %t
1919

20+
// Make sure -no-serialize-debugging-options has the desired effect.
21+
// RUN: %target-swift-frontend -emit-module -o %t -I %t/secret -F %t/Frameworks -Fsystem %t/SystemFrameworks -parse-as-library %S/Inputs/has_xref.swift -application-extension -no-serialize-debugging-options
22+
// RUN: %target-swift-frontend %s -typecheck -I %t -verify -show-diagnostics-after-fatal
23+
2024
// Make sure we don't end up with duplicate search paths.
2125
// RUN: %target-swiftc_driver -emit-module -o %t/has_xref.swiftmodule -I %t/secret -F %t/Frameworks -Fsystem %t/SystemFrameworks -parse-as-library %S/Inputs/has_xref.swift %S/../Inputs/empty.swift -Xfrontend -serialize-debugging-options
2226
// RUN: %target-swift-frontend %s -typecheck -I %t

0 commit comments

Comments
 (0)