Skip to content

Commit 51a68ec

Browse files
committed
ModuleObjCTrace/CAS: compute objc trace file paths via the canoical supplementary output paths computation
CAS support in compiler relies on supplementary paths to decide the mapping between input and output files. Therefore, we have to compute the paths of the module ObjC trace files in this canonical place to have CAS support for this newly added ObjC message trace files.
1 parent fc1dac7 commit 51a68ec

File tree

8 files changed

+32
-10
lines changed

8 files changed

+32
-10
lines changed

include/swift/Basic/FileTypes.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ TYPE("tbd", TBD, "tbd", "")
7373
// engineers can see more details on the "Swift module traces" page in the
7474
// Swift section of the internal wiki.
7575
TYPE("module-trace", ModuleTrace, "trace.json", "")
76+
TYPE("module-objc-trace", ModuleObjCTrace, "", "")
7677

7778
// Complete dependency information for the given Swift files as JSON.
7879
TYPE("json-dependencies", JSONDependencies, "dependencies.json", "")

include/swift/Basic/SupplementaryOutputPaths.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ OUTPUT(FixItsOutputPath, TY_SwiftFixIt)
106106
/// to each .swiftmodule that was loaded while building module NAME for target
107107
/// TARGET. This format is subject to arbitrary change, however.
108108
OUTPUT(LoadedModuleTracePath, TY_ModuleTrace)
109+
OUTPUT(ModuleObjCTracePath, TY_ModuleObjCTrace)
109110

110111
/// The path to which we should output a TBD file.
111112
///

include/swift/Frontend/InputFile.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ class InputFile final {
133133
StringRef getLoadedModuleTracePath() const {
134134
return getPrimarySpecificPaths().SupplementaryOutputs.LoadedModuleTracePath;
135135
}
136+
StringRef getModuleObjCTracePath() const {
137+
return getPrimarySpecificPaths().SupplementaryOutputs.ModuleObjCTracePath;
138+
}
136139
StringRef getSerializedDiagnosticsPath() const {
137140
return getPrimarySpecificPaths().SupplementaryOutputs
138141
.SerializedDiagnosticsPath;

lib/Basic/FileTypes.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ bool file_types::isTextual(ID Id) {
105105
case file_types::TY_ImportedModules:
106106
case file_types::TY_TBD:
107107
case file_types::TY_ModuleTrace:
108+
case file_types::TY_ModuleObjCTrace:
108109
case file_types::TY_YAMLOptRecord:
109110
case file_types::TY_SwiftModuleInterfaceFile:
110111
case file_types::TY_PrivateSwiftModuleInterfaceFile:
@@ -186,6 +187,7 @@ bool file_types::isAfterLLVM(ID Id) {
186187
case file_types::TY_Remapping:
187188
case file_types::TY_IndexData:
188189
case file_types::TY_ModuleTrace:
190+
case file_types::TY_ModuleObjCTrace:
189191
case file_types::TY_YAMLOptRecord:
190192
case file_types::TY_BitstreamOptRecord:
191193
case file_types::TY_SwiftModuleInterfaceFile:
@@ -249,6 +251,7 @@ bool file_types::isPartOfSwiftCompilation(ID Id) {
249251
case file_types::TY_Remapping:
250252
case file_types::TY_IndexData:
251253
case file_types::TY_ModuleTrace:
254+
case file_types::TY_ModuleObjCTrace:
252255
case file_types::TY_YAMLOptRecord:
253256
case file_types::TY_BitstreamOptRecord:
254257
case file_types::TY_JSONDependencies:
@@ -311,6 +314,7 @@ bool file_types::isProducedFromDiagnostics(ID Id) {
311314
case file_types::TY_Remapping:
312315
case file_types::TY_IndexData:
313316
case file_types::TY_ModuleTrace:
317+
case file_types::TY_ModuleObjCTrace:
314318
case file_types::TY_YAMLOptRecord:
315319
case file_types::TY_BitstreamOptRecord:
316320
case file_types::TY_JSONDependencies:

lib/Driver/Driver.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1691,6 +1691,7 @@ void Driver::buildActions(SmallVectorImpl<const Action *> &TopLevelActions,
16911691
case file_types::TY_PCH:
16921692
case file_types::TY_ImportedModules:
16931693
case file_types::TY_ModuleTrace:
1694+
case file_types::TY_ModuleObjCTrace:
16941695
case file_types::TY_YAMLOptRecord:
16951696
case file_types::TY_BitstreamOptRecord:
16961697
case file_types::TY_SwiftModuleInterfaceFile:

lib/Driver/ToolChains.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,7 @@ const char *ToolChain::JobContext::computeFrontendModeForCompile() const {
763763
case file_types::TY_SwiftDeps:
764764
case file_types::TY_ExternalSwiftDeps:
765765
case file_types::TY_ModuleTrace:
766+
case file_types::TY_ModuleObjCTrace:
766767
case file_types::TY_TBD:
767768
case file_types::TY_YAMLOptRecord:
768769
case file_types::TY_BitstreamOptRecord:
@@ -1038,6 +1039,7 @@ ToolChain::constructInvocation(const BackendJobAction &job,
10381039
case file_types::TY_ExternalSwiftDeps:
10391040
case file_types::TY_Remapping:
10401041
case file_types::TY_ModuleTrace:
1042+
case file_types::TY_ModuleObjCTrace:
10411043
case file_types::TY_YAMLOptRecord:
10421044
case file_types::TY_BitstreamOptRecord:
10431045
case file_types::TY_SwiftModuleInterfaceFile:

lib/Frontend/ArgsToFrontendOutputsConverter.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,23 @@ SupplementaryOutputPathsComputer::computeOutputPathsForOneInput(
455455
file_types::TY_ModuleTrace, "",
456456
defaultSupplementaryOutputPathExcludingExtension);
457457

458+
// We piggy-back on the loadedModuleTracePath to decide (1) whether
459+
// to emit the ObjC Trace file, and (2) where to emit the objc trace file if
460+
// the path isn't explicitly given by SWIFT_COMPILER_OBJC_MESSAGE_TRACE_PATH.
461+
// FIXME: we probably need to move this to a frontend argument.
462+
llvm::SmallString<128> ModuleObjCTracePath;
463+
if (!loadedModuleTracePath.empty()) {
464+
if (const char *P = ::getenv("SWIFT_COMPILER_OBJC_MESSAGE_TRACE_PATH")) {
465+
StringRef FilePath = P;
466+
llvm::sys::path::append(ModuleObjCTracePath, FilePath);
467+
} else {
468+
llvm::sys::path::append(ModuleObjCTracePath, loadedModuleTracePath);
469+
llvm::sys::path::remove_filename(ModuleObjCTracePath);
470+
llvm::sys::path::append(ModuleObjCTracePath,
471+
".SWIFT_FINE_DEPENDENCY_TRACE.json");
472+
}
473+
}
474+
458475
auto tbdPath = determineSupplementaryOutputFilename(
459476
OPT_emit_tbd, pathsFromArguments.TBDPath, file_types::TY_TBD, "",
460477
defaultSupplementaryOutputPathExcludingExtension);
@@ -520,6 +537,7 @@ SupplementaryOutputPathsComputer::computeOutputPathsForOneInput(
520537
sop.SerializedDiagnosticsPath = serializedDiagnosticsPath;
521538
sop.FixItsOutputPath = fixItsOutputPath;
522539
sop.LoadedModuleTracePath = loadedModuleTracePath;
540+
sop.ModuleObjCTracePath = ModuleObjCTracePath.str().str();
523541
sop.TBDPath = tbdPath;
524542
sop.ModuleInterfaceOutputPath = ModuleInterfaceOutputPath;
525543
sop.PrivateModuleInterfaceOutputPath = PrivateModuleInterfaceOutputPath;

lib/FrontendTool/LoadedModuleTrace.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,8 @@ class ObjcMethodReferenceCollector: public SourceEntityWalker {
854854
};
855855

856856
static void createObjCMessageTraceFile(const InputFile &input, ModuleDecl *MD) {
857-
if (input.getLoadedModuleTracePath().empty()) {
857+
StringRef tracePath = input.getModuleObjCTracePath();
858+
if (tracePath.empty()) {
858859
// we basically rely on the passing down of module trace file path
859860
// as an indicator that this job needs to emit an ObjC message trace file.
860861
// FIXME: add a separate swift-frontend flag for ObjC message trace path
@@ -882,15 +883,6 @@ static void createObjCMessageTraceFile(const InputFile &input, ModuleDecl *MD) {
882883
if (filesToWalk.empty()) {
883884
return;
884885
}
885-
llvm::SmallString<128> tracePath;
886-
if (const char *P = ::getenv("SWIFT_COMPILER_OBJC_MESSAGE_TRACE_PATH")) {
887-
StringRef FilePath = P;
888-
llvm::sys::path::append(tracePath, FilePath);
889-
} else {
890-
llvm::sys::path::append(tracePath, input.getLoadedModuleTracePath());
891-
llvm::sys::path::remove_filename(tracePath);
892-
llvm::sys::path::append(tracePath, ".SWIFT_FINE_DEPENDENCY_TRACE.json");
893-
}
894886
// Write output via atomic append.
895887
llvm::vfs::OutputConfig config;
896888
config.setAppend().setAtomicWrite();

0 commit comments

Comments
 (0)