Skip to content

Commit 305ac20

Browse files
authored
Serialize and Deserialize Debug Scopes (#76934)
This patch adds support for serialization and deserialization of debug scopes. Debug scopes are serialized in post order and enablement is controlled through the experimental-serialize-debug-info flag which is turned off by default. Functions only referred to by these debug scopes are deserialized as zombie functions directly.
1 parent 919ec93 commit 305ac20

File tree

16 files changed

+440
-44
lines changed

16 files changed

+440
-44
lines changed

include/swift/Frontend/FrontendOptions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ class FrontendOptions {
129129
/// Include local definitions/references in the index data.
130130
bool IndexIncludeLocals = false;
131131

132+
bool SerializeDebugInfoSIL = false;
132133
/// If building a module from interface, ignore compiler flags
133134
/// specified in the swiftinterface.
134135
bool ExplicitInterfaceBuild = false;

include/swift/Option/Options.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,10 @@ def experimental_package_interface_load:
827827
Flags<[FrontendOption, HelpHidden]>,
828828
HelpText<"Enables loading a package interface if in the same package specified with package-name">;
829829

830+
def experimental_serialize_debug_info:
831+
Flag<["-"], "experimental-serialize-debug-info">,
832+
Flags<[FrontendOption, HelpHidden]>,
833+
HelpText<"Enables seriailzation/deserialization of debug scopes">;
830834
// Diagnostic control options
831835
def suppress_warnings : Flag<["-"], "suppress-warnings">,
832836
Flags<[FrontendOption]>,

include/swift/Serialization/SerializationOptions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ class SerializationOptions {
151151

152152
bool AutolinkForceLoad = false;
153153
bool SerializeAllSIL = false;
154+
bool SerializeDebugInfoSIL = false;
154155
bool SerializeOptionsForDebugging = false;
155156
bool IsSIB = false;
156157
bool DisableCrossModuleIncrementalInfo = false;

lib/Driver/ToolChains.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,12 @@ void ToolChain::addCommonFrontendArgs(const OutputInfo &OI,
204204
arguments.push_back("-disable-objc-interop");
205205
}
206206

207+
if (const Arg *arg = inputArgs.getLastArg(
208+
options::OPT_experimental_serialize_debug_info)) {
209+
arguments.push_back(
210+
inputArgs.MakeArgString(Twine("-experimental-serialize-debug-info")));
211+
}
212+
207213
if (inputArgs.hasArg(options::OPT_experimental_hermetic_seal_at_link)) {
208214
arguments.push_back("-enable-llvm-vfe");
209215
arguments.push_back("-enable-llvm-wme");

lib/Frontend/ArgsToFrontendOptionsConverter.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ bool ArgsToFrontendOptionsConverter::convert(
8989
Opts.IndexSystemModules |= Args.hasArg(OPT_index_system_modules);
9090
Opts.IndexIgnoreStdlib |= Args.hasArg(OPT_index_ignore_stdlib);
9191
Opts.IndexIncludeLocals |= Args.hasArg(OPT_index_include_locals);
92+
Opts.SerializeDebugInfoSIL |=
93+
Args.hasArg(OPT_experimental_serialize_debug_info);
9294

9395
Opts.EmitVerboseSIL |= Args.hasArg(OPT_emit_verbose_sil);
9496
Opts.EmitSortedSIL |= Args.hasArg(OPT_emit_sorted_sil);

lib/Frontend/Frontend.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ SerializationOptions CompilerInvocation::computeSerializationOptions(
200200
serializationOpts.ModuleLinkName = opts.ModuleLinkName;
201201
serializationOpts.UserModuleVersion = opts.UserModuleVersion;
202202
serializationOpts.AllowableClients = opts.AllowableClients;
203+
serializationOpts.SerializeDebugInfoSIL = opts.SerializeDebugInfoSIL;
203204

204205
serializationOpts.PublicDependentLibraries =
205206
getIRGenOptions().PublicLinkLibraries;

lib/SIL/Parser/ParseSIL.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,16 @@ SILParserState::~SILParserState() {
8686
}
8787

8888
// Turn any debug-info-only function declarations into zombies.
89-
for (auto *Fn : PotentialZombieFns)
90-
if (Fn->isExternalDeclaration()) {
89+
markZombies();
90+
}
91+
92+
void SILParserState::markZombies() {
93+
for (auto *Fn : PotentialZombieFns) {
94+
if (Fn->isExternalDeclaration() && !Fn->isZombie()) {
9195
Fn->setInlined();
9296
M.eraseFunction(Fn);
9397
}
98+
}
9499
}
95100

96101
std::unique_ptr<SILModule>
@@ -124,6 +129,11 @@ ParseSILModuleRequest::evaluate(Evaluator &evaluator,
124129
"Failed to parse SIL but did not emit any errors!");
125130
return SILModule::createEmptyModule(desc.context, desc.conv, desc.opts);
126131
}
132+
133+
// Mark functions as zombies before calling SILVerifier as functions referred
134+
//to by debug scopes only can fail verifier checks
135+
parserState.markZombies();
136+
127137
// If SIL parsing succeeded, verify the generated SIL.
128138
if (!parser.Diags.hadAnyError() && !DisableInputVerify) {
129139
silMod->verify(/*SingleFunction=*/true, !ParseIncompleteOSSA);

lib/SIL/Parser/SILParserState.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ class SILParserState : public SILParserStateBase {
6262
bool parseSILCoverageMap(Parser &P) override;
6363
bool parseSILProperty(Parser &P) override;
6464
bool parseSILScope(Parser &P) override;
65+
66+
/// Mark potential zombie functions as zombies.
67+
void markZombies();
6568
};
6669

6770
} // end namespace swift

0 commit comments

Comments
 (0)