2323#include " swift/Basic/JSONSerialization.h"
2424#include " swift/Basic/SourceManager.h"
2525#include " swift/Frontend/FrontendOptions.h"
26+ #include " swift/Frontend/ModuleInterfaceSupport.h"
2627#include " swift/IDE/SourceEntityWalker.h"
2728
2829#include " clang/AST/DeclObjC.h"
@@ -819,18 +820,19 @@ bool swift::emitLoadedModuleTraceIfNeeded(ModuleDecl *mainModule,
819820const static unsigned OBJC_METHOD_TRACE_FILE_FORMAT_VERSION = 1 ;
820821
821822class ObjcMethodReferenceCollector : public SourceEntityWalker {
823+ std::string compilerVer;
822824 std::string target;
823825 std::string targetVariant;
824826 SmallVector<StringRef, 32 > FilePaths;
825827 unsigned CurrentFileID;
826- llvm::DenseSet <const clang::ObjCMethodDecl*> results;
828+ llvm::DenseMap <const clang::ObjCMethodDecl*, unsigned > results;
827829 bool visitDeclReference (ValueDecl *D, CharSourceRange Range,
828830 TypeDecl *CtorTyRef, ExtensionDecl *ExtTyRef,
829831 Type T, ReferenceMetaData Data) override {
830832 if (!Range.isValid ())
831833 return true ;
832834 if (auto *clangD = dyn_cast_or_null<clang::ObjCMethodDecl>(D->getClangDecl ())) {
833- results. insert ( clangD) ;
835+ results[ clangD] = CurrentFileID ;
834836 }
835837 return true ;
836838 }
@@ -855,6 +857,8 @@ class ObjcMethodReferenceCollector: public SourceEntityWalker {
855857 }
856858public:
857859 ObjcMethodReferenceCollector (ModuleDecl *MD) {
860+ compilerVer =
861+ getSwiftInterfaceCompilerVersionForCurrentCompiler (MD->getASTContext ());
858862 auto &Opts = MD->getASTContext ().LangOpts ;
859863 target = Opts.Target .str ();
860864 targetVariant = Opts.TargetVariant .has_value () ?
@@ -868,27 +872,29 @@ class ObjcMethodReferenceCollector: public SourceEntityWalker {
868872 void serializeAsJson (llvm::raw_ostream &OS) {
869873 llvm::json::OStream out (OS, /* IndentSize=*/ 4 );
870874 out.object ([&] {
875+ out.attribute (" swift-compiler-version" , compilerVer);
871876 out.attribute (" format-vesion" , OBJC_METHOD_TRACE_FILE_FORMAT_VERSION);
872877 out.attribute (" target" , target);
873878 if (!targetVariant.empty ())
874879 out.attribute (" target-variant" , targetVariant);
875880 out.attributeArray (" references" , [&] {
876- for (const clang::ObjCMethodDecl* clangD: results) {
881+ for (auto pair: results) {
882+ auto *clangD = pair.first ;
877883 auto &SM = clangD->getASTContext ().getSourceManager ();
878884 clang::SourceLocation Loc = clangD->getLocation ();
879885 if (!Loc.isValid ()) {
880886 continue ;
881887 }
882888 out.object ([&] {
883889 if (auto *parent = dyn_cast_or_null<clang::NamedDecl>(clangD
884- ->getParent ())) {
890+ ->getParent ())) {
885891 auto pName = parent->getName ();
886892 if (!pName.empty ())
887893 out.attribute (selectMethodOwnerKey (parent), pName);
888894 }
889895 out.attribute (selectMethodKey (clangD), clangD->getNameAsString ());
890896 out.attribute (" declared_at" , Loc.printToString (SM));
891- out.attribute (" referenced_at_file_id" , CurrentFileID );
897+ out.attribute (" referenced_at_file_id" , pair. second );
892898 });
893899 }
894900 });
0 commit comments