@@ -911,17 +911,34 @@ class ObjcMethodReferenceCollector: public SourceEntityWalker {
911
911
};
912
912
913
913
static std::optional<int > createObjCMessageTraceFile (const InputFile &input,
914
- ModuleDecl *MD) {
914
+ ModuleDecl *MD,
915
+ std::vector<SourceFile*> &filesToWalk) {
916
+ if (input.getLoadedModuleTracePath ().empty ()) {
917
+ // we basically rely on the passing down of module trace file path
918
+ // as an indicator that this job needs to emit an ObjC message trace file.
919
+ // FIXME: add a separate swift-frontend flag for ObjC message trace path
920
+ // specifically.
921
+ return {};
922
+ }
923
+ for (auto *FU : MD->getFiles ()) {
924
+ if (auto *SF = dyn_cast<SourceFile>(FU)) {
925
+ if (SF->getFilename ().ends_with (" .swift" )) {
926
+ filesToWalk.push_back (SF);
927
+ }
928
+ }
929
+ }
930
+ // No source files to walk, abort.
931
+ if (filesToWalk.empty ()) {
932
+ return {};
933
+ }
915
934
llvm::SmallString<128 > tracePath;
916
935
if (const char *P = ::getenv (" SWIFT_COMPILER_OBJC_MESSAGE_TRACE_DIRECTORY" )) {
917
936
StringRef DirPath = P;
918
937
llvm::sys::path::append (tracePath, DirPath);
919
- } else if (!input. getLoadedModuleTracePath (). empty ()) {
938
+ } else {
920
939
llvm::sys::path::append (tracePath, input.getLoadedModuleTracePath ());
921
940
llvm::sys::path::remove_filename (tracePath);
922
941
llvm::sys::path::append (tracePath, " .SWIFT_FINE_DEPENDENCY_TRACE" );
923
- } else {
924
- return {};
925
942
}
926
943
if (!llvm::sys::fs::exists (tracePath)) {
927
944
if (llvm::sys::fs::create_directory (tracePath))
@@ -944,17 +961,16 @@ bool swift::emitObjCMessageSendTraceIfNeeded(ModuleDecl *mainModule,
944
961
" We should've already exited earlier if there was an error." );
945
962
946
963
opts.InputsAndOutputs .forEachInput ([&](const InputFile &input) {
947
- auto tmpFD = createObjCMessageTraceFile (input, mainModule);
964
+ std::vector<SourceFile*> filesToWalk;
965
+ auto tmpFD = createObjCMessageTraceFile (input, mainModule, filesToWalk);
948
966
if (!tmpFD)
949
967
return false ;
950
968
// Write the contents of the buffer.
951
969
llvm::raw_fd_ostream out (*tmpFD, /* shouldClose=*/ true );
952
970
ObjcMethodReferenceCollector collector (mainModule);
953
- for (auto *FU : mainModule->getFiles ()) {
954
- if (auto *SF = dyn_cast<SourceFile>(FU)) {
955
- collector.setFileBeforeVisiting (SF);
956
- collector.walk (*SF);
957
- }
971
+ for (auto *SF : filesToWalk) {
972
+ collector.setFileBeforeVisiting (SF);
973
+ collector.walk (*SF);
958
974
}
959
975
collector.serializeAsJson (out);
960
976
return true ;
0 commit comments