Skip to content

Commit 84ba789

Browse files
committed
ModuleObjcMessageTrace: include target and target variant info and a format version number
1 parent 1b025ba commit 84ba789

File tree

1 file changed

+35
-19
lines changed

1 file changed

+35
-19
lines changed

lib/FrontendTool/LoadedModuleTrace.cpp

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,11 @@ bool swift::emitLoadedModuleTraceIfNeeded(ModuleDecl *mainModule,
816816
return false;
817817
}
818818

819+
const static unsigned OBJC_METHOD_TRACE_FILE_FORMAT_VERSION = 1;
820+
819821
class ObjcMethodReferenceCollector: public SourceEntityWalker {
822+
std::string target;
823+
std::string targetVariant;
820824
StringRef visitingFilePath;
821825
llvm::DenseSet<const clang::ObjCMethodDecl*> results;
822826
bool visitDeclReference(ValueDecl *D, CharSourceRange Range,
@@ -847,31 +851,43 @@ class ObjcMethodReferenceCollector: public SourceEntityWalker {
847851
return "type";
848852
}
849853
public:
854+
ObjcMethodReferenceCollector(ModuleDecl *MD) {
855+
auto &Opts = MD->getASTContext().LangOpts;
856+
target = Opts.Target.str();
857+
targetVariant = Opts.TargetVariant.has_value() ?
858+
Opts.TargetVariant->str() : "";
859+
}
850860
void setFileBeforeVisiting(SourceFile *SF) {
851861
assert(SF && "need to visit actual source files");
852862
visitingFilePath = SF->getFilename();
853863
}
854864
void serializeAsJson(llvm::raw_ostream &OS) {
855865
llvm::json::OStream out(OS, /*IndentSize=*/4);
856-
out.array([&] {
857-
for (const clang::ObjCMethodDecl* clangD: results) {
858-
auto &SM = clangD->getASTContext().getSourceManager();
859-
clang::SourceLocation Loc = clangD->getLocation();
860-
if (!Loc.isValid()) {
861-
continue;
862-
}
863-
out.object([&] {
864-
if (auto *parent = dyn_cast_or_null<clang::NamedDecl>(clangD
865-
->getParent())) {
866-
auto pName = parent->getName();
867-
if (!pName.empty())
868-
out.attribute(selectMethodOwnerKey(parent), pName);
866+
out.object([&] {
867+
out.attribute("format-vesion", OBJC_METHOD_TRACE_FILE_FORMAT_VERSION);
868+
out.attribute("target", target);
869+
if (!targetVariant.empty())
870+
out.attribute("target-variant", targetVariant);
871+
out.attributeArray("references", [&] {
872+
for (const clang::ObjCMethodDecl* clangD: results) {
873+
auto &SM = clangD->getASTContext().getSourceManager();
874+
clang::SourceLocation Loc = clangD->getLocation();
875+
if (!Loc.isValid()) {
876+
continue;
869877
}
870-
out.attribute(selectMethodKey(clangD), clangD->getNameAsString());
871-
out.attribute("declared_at", Loc.printToString(SM));
872-
out.attribute("referenced_at", visitingFilePath);
873-
});
874-
}
878+
out.object([&] {
879+
if (auto *parent = dyn_cast_or_null<clang::NamedDecl>(clangD
880+
->getParent())) {
881+
auto pName = parent->getName();
882+
if (!pName.empty())
883+
out.attribute(selectMethodOwnerKey(parent), pName);
884+
}
885+
out.attribute(selectMethodKey(clangD), clangD->getNameAsString());
886+
out.attribute("declared_at", Loc.printToString(SM));
887+
out.attribute("referenced_at", visitingFilePath);
888+
});
889+
}
890+
});
875891
});
876892
}
877893
};
@@ -900,7 +916,7 @@ bool swift::emitObjCMessageSendTraceIfNeeded(ModuleDecl *mainModule,
900916
}
901917
// Write the contents of the buffer.
902918
llvm::raw_fd_ostream out(tmpFD, /*shouldClose=*/true);
903-
ObjcMethodReferenceCollector collector;
919+
ObjcMethodReferenceCollector collector(mainModule);
904920
for (auto *FU : mainModule->getFiles()) {
905921
if (auto *SF = dyn_cast<SourceFile>(FU)) {
906922
collector.setFileBeforeVisiting(SF);

0 commit comments

Comments
 (0)