Skip to content

Commit 5473cec

Browse files
authored
Merge pull request #41538 from nkcsgexi/89354768
Frontend: add a frontend flag to generate empty ABI descriptors to workaround deserialization issues
2 parents 8cfdb99 + e1aaee4 commit 5473cec

File tree

9 files changed

+32
-9
lines changed

9 files changed

+32
-9
lines changed

include/swift/APIDigester/ModuleAnalyzerNodes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@ int dumpSDKContent(const CompilerInvocation &InitInvok,
816816
const llvm::StringSet<> &ModuleNames,
817817
StringRef OutputFile, CheckerOptions Opts);
818818

819-
void dumpModuleContent(ModuleDecl *MD, StringRef OutputFile, bool ABI);
819+
void dumpModuleContent(ModuleDecl *MD, StringRef OutputFile, bool ABI, bool Empty);
820820

821821
/// Mostly for testing purposes, this function de-serializes the SDK dump in
822822
/// dumpPath and re-serialize them to OutputPath. If the tool performs correctly,

include/swift/Frontend/FrontendOptions.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,11 @@ class FrontendOptions {
447447
/// to encode the actual paths into the .swiftmodule file.
448448
PathObfuscator serializedPathObfuscator;
449449

450+
/// Avoid printing actual module content into the ABI descriptor file.
451+
/// This should only be used as a workaround when emitting ABI descriptor files
452+
/// crashes the compiler.
453+
bool emptyABIDescriptor = false;
454+
450455
private:
451456
static bool canActionEmitDependencies(ActionType);
452457
static bool canActionEmitReferenceDependencies(ActionType);

include/swift/Option/FrontendOptions.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ def serialize_debugging_options : Flag<["-"], "serialize-debugging-options">,
169169
def serialized_path_obfuscate : Separate<["-"], "serialized-path-obfuscate">,
170170
HelpText<"Remap source paths in debug info">, MetaVarName<"<prefix=replacement>">;
171171

172+
def empty_abi_descriptor : Flag<["-"], "empty-abi-descriptor">,
173+
HelpText<"Avoid printing actual module content into ABI descriptor file">;
174+
172175
def no_serialize_debugging_options :
173176
Flag<["-"], "no-serialize-debugging-options">,
174177
HelpText<"Never serialize options for debugging (default: only for apps)">;

include/swift/Serialization/SerializationOptions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ namespace swift {
3333
const char *DocOutputPath = nullptr;
3434
const char *SourceInfoOutputPath = nullptr;
3535
std::string ABIDescriptorPath;
36+
bool emptyABIDescriptor = false;
3637
llvm::VersionTuple UserModuleVersion;
3738
std::string SDKName;
3839

lib/APIDigester/ModuleAnalyzerNodes.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2498,7 +2498,7 @@ int swift::ide::api::deserializeSDKDump(StringRef dumpPath, StringRef OutputPath
24982498
}
24992499

25002500
void swift::ide::api::dumpModuleContent(ModuleDecl *MD, StringRef OutputFile,
2501-
bool ABI) {
2501+
bool ABI, bool Empty) {
25022502
CheckerOptions opts;
25032503
opts.ABI = ABI;
25042504
opts.SwiftOnly = true;
@@ -2509,12 +2509,17 @@ void swift::ide::api::dumpModuleContent(ModuleDecl *MD, StringRef OutputFile,
25092509
opts.Verbose = false;
25102510
SDKContext ctx(opts);
25112511
SwiftDeclCollector collector(ctx);
2512-
collector.lookupVisibleDecls({MD});
25132512
ConstExtractor extractor(ctx, MD->getASTContext());
2514-
extractor.extract(MD);
25152513
PayLoad payload;
2516-
payload.allContsValues = &extractor.getAllConstValues();
2517-
dumpSDKRoot(collector.getSDKRoot(), payload, OutputFile);
2514+
SWIFT_DEFER {
2515+
payload.allContsValues = &extractor.getAllConstValues();
2516+
dumpSDKRoot(collector.getSDKRoot(), payload, OutputFile);
2517+
};
2518+
if (Empty) {
2519+
return;
2520+
}
2521+
collector.lookupVisibleDecls({MD});
2522+
extractor.extract(MD);
25182523
}
25192524

25202525
int swift::ide::api::findDeclUsr(StringRef dumpPath, CheckerOptions Opts) {

lib/Frontend/ArgsToFrontendOptionsConverter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ bool ArgsToFrontendOptionsConverter::convert(
297297
auto SplitMap = StringRef(A).split('=');
298298
Opts.serializedPathObfuscator.addMapping(SplitMap.first, SplitMap.second);
299299
}
300+
Opts.emptyABIDescriptor = Args.hasArg(OPT_empty_abi_descriptor);
300301
return false;
301302
}
302303

lib/Frontend/Frontend.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ SerializationOptions CompilerInvocation::computeSerializationOptions(
158158
getIRGenOptions().PublicLinkLibraries;
159159
serializationOpts.SDKName = getLangOptions().SDKName;
160160
serializationOpts.ABIDescriptorPath = outs.ABIDescriptorOutputPath.c_str();
161-
161+
serializationOpts.emptyABIDescriptor = opts.emptyABIDescriptor;
162+
162163
if (!getIRGenOptions().ForceLoadSymbolName.empty())
163164
serializationOpts.AutolinkForceLoad = true;
164165

lib/Serialization/Serialization.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5810,10 +5810,11 @@ bool Serializer::allowCompilerErrors() const {
58105810

58115811
static void emitABIDescriptor(ModuleOrSourceFile DC,
58125812
const SerializationOptions &options) {
5813+
using namespace swift::ide::api;
58135814
if (!options.ABIDescriptorPath.empty()) {
58145815
if (DC.is<ModuleDecl*>()) {
5815-
swift::ide::api::dumpModuleContent(DC.get<ModuleDecl*>(),
5816-
options.ABIDescriptorPath, true);
5816+
dumpModuleContent(DC.get<ModuleDecl*>(), options.ABIDescriptorPath, true,
5817+
options.emptyABIDescriptor);
58175818
}
58185819
}
58195820
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// RUN: %target-swift-frontend -emit-module -o %t/Foo.swiftmodule -emit-abi-descriptor-path %t/abi.json %S/Inputs/ConstExtraction/SimpleReferences.swift -empty-abi-descriptor
4+
// RUN: %api-digester -deserialize-sdk -input-paths %t/abi.json -o %t/abi.result.json
5+
// RUN: %api-digester -generate-empty-baseline -o %t/abi-tool.json -avoid-tool-args -abi
6+
// RUN: diff -u %t/abi-tool.json %t/abi.result.json

0 commit comments

Comments
 (0)