Skip to content

Commit f75dea4

Browse files
Merge pull request swiftlang#23910 from adrian-prantl/49751363
Record parseable interface imports in the debug info.
2 parents 7bab318 + 8d03cb7 commit f75dea4

File tree

13 files changed

+77
-10
lines changed

13 files changed

+77
-10
lines changed

include/swift/AST/Module.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,10 @@ class FileUnit : public DeclContext {
843843
return getParentModule()->getName().str();
844844
}
845845

846+
/// If this is a module imported from a parseable interface, return the path
847+
/// to the interface file, otherwise an empty StringRef.
848+
virtual StringRef getParseableInterface() const { return {}; }
849+
846850
/// Traverse the decls within this file.
847851
///
848852
/// \returns true if traversal was aborted, false if it completed

include/swift/Serialization/ModuleFormat.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,8 @@ namespace input_block {
643643
IMPORTED_HEADER_CONTENTS,
644644
MODULE_FLAGS, // [unused]
645645
SEARCH_PATH,
646-
FILE_DEPENDENCY
646+
FILE_DEPENDENCY,
647+
PARSEABLE_INTERFACE_PATH
647648
};
648649

649650
using ImportedModuleLayout = BCRecordLayout<
@@ -690,6 +691,12 @@ namespace input_block {
690691
BCFixed<1>, // SDK-relative?
691692
BCBlob // path
692693
>;
694+
695+
using ParseableInterfaceLayout = BCRecordLayout<
696+
PARSEABLE_INTERFACE_PATH,
697+
BCBlob // file path
698+
>;
699+
693700
}
694701

695702
/// The record types within the "decls-and-types" block.

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
StringRef GroupInfoPath;
3434
StringRef ImportedHeader;
3535
StringRef ModuleLinkName;
36+
StringRef ParseableInterface;
3637
ArrayRef<std::string> ExtraClangOptions;
3738

3839
/// Describes a single-file dependency for this module, along with the

include/swift/Serialization/SerializedModuleLoader.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,11 @@ class SerializedASTFile final : public LoadedFile {
198198
friend class ModuleFile;
199199

200200
ModuleFile &File;
201+
202+
/// The parseable interface this module was generated from if any.
203+
/// Used for debug info.
204+
std::string ParseableInterface;
205+
201206
bool IsSIB;
202207

203208
~SerializedASTFile() = default;
@@ -294,6 +299,13 @@ class SerializedASTFile final : public LoadedFile {
294299

295300
virtual const clang::Module *getUnderlyingClangModule() const override;
296301

302+
/// If this is a module imported from a parseable interface, return the path
303+
/// to the interface file, otherwise an empty StringRef.
304+
virtual StringRef getParseableInterface() const override {
305+
return ParseableInterface;
306+
}
307+
void setParseableInterface(StringRef PI) { ParseableInterface = PI; }
308+
297309
virtual bool getAllGenericSignatures(
298310
SmallVectorImpl<GenericSignature*> &genericSignatures)
299311
override;

include/swift/Serialization/Validation.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ struct ValidationInfo {
9292
class ExtendedValidationInfo {
9393
SmallVector<StringRef, 4> ExtraClangImporterOpts;
9494
StringRef SDKPath;
95+
StringRef ParseableInterface;
9596
struct {
9697
unsigned ArePrivateImportsEnabled : 1;
9798
unsigned IsSIB : 1;
@@ -113,6 +114,8 @@ class ExtendedValidationInfo {
113114
void addExtraClangImporterOption(StringRef option) {
114115
ExtraClangImporterOpts.push_back(option);
115116
}
117+
StringRef getParseableInterface() const { return ParseableInterface; }
118+
void setParseableInterface(StringRef PI) { ParseableInterface = PI; }
116119

117120
bool isSIB() const { return Bits.IsSIB; }
118121
void setIsSIB(bool val) {

lib/AST/Module.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,6 +1157,10 @@ StringRef ModuleDecl::getModuleFilename() const {
11571157
// per-file names. Modules can consist of more than one file.
11581158
StringRef Result;
11591159
for (auto F : getFiles()) {
1160+
Result = F->getParseableInterface();
1161+
if (!Result.empty())
1162+
return Result;
1163+
11601164
if (auto SF = dyn_cast<SourceFile>(F)) {
11611165
if (!Result.empty())
11621166
return StringRef();

lib/Frontend/Frontend.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,8 @@ CompilerInvocation::getParseableInterfaceOutputPathForWholeModule() const {
124124
.SupplementaryOutputs.ParseableInterfaceOutputPath;
125125
}
126126

127-
SerializationOptions
128-
CompilerInvocation::computeSerializationOptions(const SupplementaryOutputPaths &outs,
129-
bool moduleIsPublic) {
127+
SerializationOptions CompilerInvocation::computeSerializationOptions(
128+
const SupplementaryOutputPaths &outs, bool moduleIsPublic) {
130129
const FrontendOptions &opts = getFrontendOptions();
131130

132131
SerializationOptions serializationOpts;

lib/Frontend/ParseableInterfaceModuleLoader.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,12 @@ class swift::ParseableInterfaceBuilder {
582582
std::string OutPathStr = OutPath;
583583
SerializationOpts.OutputPath = OutPathStr.c_str();
584584
SerializationOpts.ModuleLinkName = FEOpts.ModuleLinkName;
585+
586+
// Record any non-SDK parseable interface files for the debug info.
587+
StringRef SDKPath = SubInstance.getASTContext().SearchPathOpts.SDKPath;
588+
if (!getRelativeDepPath(InPath, SDKPath))
589+
SerializationOpts.ParseableInterface = InPath;
590+
585591
SmallVector<FileDependency, 16> Deps;
586592
if (collectDepsForSerialization(SubInstance, Deps,
587593
FEOpts.SerializeModuleInterfaceDependencyHashes)) {

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,14 +191,13 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
191191

192192
private:
193193
static StringRef getFilenameFromDC(const DeclContext *DC) {
194-
if (auto LF = dyn_cast<LoadedFile>(DC))
194+
if (auto *LF = dyn_cast<LoadedFile>(DC))
195195
return LF->getFilename();
196-
if (auto SF = dyn_cast<SourceFile>(DC))
196+
if (auto *SF = dyn_cast<SourceFile>(DC))
197197
return SF->getFilename();
198-
else if (auto M = dyn_cast<ModuleDecl>(DC))
198+
if (auto *M = dyn_cast<ModuleDecl>(DC))
199199
return M->getModuleFilename();
200-
else
201-
return StringRef();
200+
return {};
202201
}
203202

204203
using DebugLoc = SILLocation::DebugLoc;
@@ -717,7 +716,6 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
717716
ModuleDecl *M = IM.second;
718717
if (Optional<ASTSourceDescriptor> ModuleDesc = getClangModule(*M))
719718
return getOrCreateModule(*ModuleDesc, ModuleDesc->getModuleOrNull());
720-
721719
StringRef Path = getFilenameFromDC(M);
722720
StringRef Name = M->getName().str();
723721
return getOrCreateModule(M, TheCU, Name, Path);

lib/Serialization/ModuleFile.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,6 +1335,11 @@ ModuleFile::ModuleFile(
13351335
SearchPaths.push_back({blobData, isFramework, isSystem});
13361336
break;
13371337
}
1338+
case input_block::PARSEABLE_INTERFACE_PATH: {
1339+
if (extInfo)
1340+
extInfo->setParseableInterface(blobData);
1341+
break;
1342+
}
13381343
default:
13391344
// Unknown input kind, possibly for use by a future version of the
13401345
// module format.

0 commit comments

Comments
 (0)