Skip to content

Serialize and Deserialize Debug Scopes #76934

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/swift/Frontend/FrontendOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ class FrontendOptions {
/// Include local definitions/references in the index data.
bool IndexIncludeLocals = false;

bool SerializeDebugInfoSIL = false;
/// If building a module from interface, ignore compiler flags
/// specified in the swiftinterface.
bool ExplicitInterfaceBuild = false;
Expand Down
4 changes: 4 additions & 0 deletions include/swift/Option/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,10 @@ def experimental_package_interface_load:
Flags<[FrontendOption, HelpHidden]>,
HelpText<"Enables loading a package interface if in the same package specified with package-name">;

def experimental_serialize_debug_info:
Flag<["-"], "experimental-serialize-debug-info">,
Flags<[FrontendOption, HelpHidden]>,
HelpText<"Enables seriailzation/deserialization of debug scopes">;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should become on by default eventually, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it should be. I am not sure if we want to turn it on right now. @kubamracek Do you have a suggestion here? Thanks

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think this is a staging flag, correct? Sounds like a good approach to me.

// Diagnostic control options
def suppress_warnings : Flag<["-"], "suppress-warnings">,
Flags<[FrontendOption]>,
Expand Down
1 change: 1 addition & 0 deletions include/swift/Serialization/SerializationOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ class SerializationOptions {

bool AutolinkForceLoad = false;
bool SerializeAllSIL = false;
bool SerializeDebugInfoSIL = false;
bool SerializeOptionsForDebugging = false;
bool IsSIB = false;
bool DisableCrossModuleIncrementalInfo = false;
Expand Down
6 changes: 6 additions & 0 deletions lib/Driver/ToolChains.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,12 @@ void ToolChain::addCommonFrontendArgs(const OutputInfo &OI,
arguments.push_back("-disable-objc-interop");
}

if (const Arg *arg = inputArgs.getLastArg(
options::OPT_experimental_serialize_debug_info)) {
arguments.push_back(
inputArgs.MakeArgString(Twine("-experimental-serialize-debug-info")));
}

if (inputArgs.hasArg(options::OPT_experimental_hermetic_seal_at_link)) {
arguments.push_back("-enable-llvm-vfe");
arguments.push_back("-enable-llvm-wme");
Expand Down
2 changes: 2 additions & 0 deletions lib/Frontend/ArgsToFrontendOptionsConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ bool ArgsToFrontendOptionsConverter::convert(
Opts.IndexSystemModules |= Args.hasArg(OPT_index_system_modules);
Opts.IndexIgnoreStdlib |= Args.hasArg(OPT_index_ignore_stdlib);
Opts.IndexIncludeLocals |= Args.hasArg(OPT_index_include_locals);
Opts.SerializeDebugInfoSIL |=
Args.hasArg(OPT_experimental_serialize_debug_info);

Opts.EmitVerboseSIL |= Args.hasArg(OPT_emit_verbose_sil);
Opts.EmitSortedSIL |= Args.hasArg(OPT_emit_sorted_sil);
Expand Down
1 change: 1 addition & 0 deletions lib/Frontend/Frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ SerializationOptions CompilerInvocation::computeSerializationOptions(
serializationOpts.ModuleLinkName = opts.ModuleLinkName;
serializationOpts.UserModuleVersion = opts.UserModuleVersion;
serializationOpts.AllowableClients = opts.AllowableClients;
serializationOpts.SerializeDebugInfoSIL = opts.SerializeDebugInfoSIL;

serializationOpts.PublicDependentLibraries =
getIRGenOptions().PublicLinkLibraries;
Expand Down
14 changes: 12 additions & 2 deletions lib/SIL/Parser/ParseSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,16 @@ SILParserState::~SILParserState() {
}

// Turn any debug-info-only function declarations into zombies.
for (auto *Fn : PotentialZombieFns)
if (Fn->isExternalDeclaration()) {
markZombies();
}

void SILParserState::markZombies() {
for (auto *Fn : PotentialZombieFns) {
if (Fn->isExternalDeclaration() && !Fn->isZombie()) {
Fn->setInlined();
M.eraseFunction(Fn);
}
}
}

std::unique_ptr<SILModule>
Expand Down Expand Up @@ -124,6 +129,11 @@ ParseSILModuleRequest::evaluate(Evaluator &evaluator,
"Failed to parse SIL but did not emit any errors!");
return SILModule::createEmptyModule(desc.context, desc.conv, desc.opts);
}

// Mark functions as zombies before calling SILVerifier as functions referred
//to by debug scopes only can fail verifier checks
parserState.markZombies();

// If SIL parsing succeeded, verify the generated SIL.
if (!parser.Diags.hadAnyError() && !DisableInputVerify) {
silMod->verify(/*SingleFunction=*/true, !ParseIncompleteOSSA);
Expand Down
3 changes: 3 additions & 0 deletions lib/SIL/Parser/SILParserState.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ class SILParserState : public SILParserStateBase {
bool parseSILCoverageMap(Parser &P) override;
bool parseSILProperty(Parser &P) override;
bool parseSILScope(Parser &P) override;

/// Mark potential zombie functions as zombies.
void markZombies();
};

} // end namespace swift
Expand Down
Loading