Skip to content

Commit 97a4cba

Browse files
add the symbol graph dir to the supplementary file map
rdar://75582169
1 parent 64c7582 commit 97a4cba

File tree

9 files changed

+78
-9
lines changed

9 files changed

+78
-9
lines changed

include/swift/Basic/FileTypes.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ TYPE("index-unit-output-path", IndexUnitOutputPath, "", "")
8383
TYPE("yaml-opt-record", YAMLOptRecord, "opt.yaml", "")
8484
TYPE("bitstream-opt-record",BitstreamOptRecord, "opt.bitstream", "")
8585

86+
TYPE("symbol-graph-output-path", SymbolGraphOutputPath, "", "")
87+
8688
// Overlay files declare wrapper modules, called "separately-imported overlays",
8789
// that should be automatically imported when a particular module is imported.
8890
// Cross-import directories conditionalize overlay files so they only take

include/swift/Basic/SupplementaryOutputPaths.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ struct SupplementaryOutputPaths {
152152

153153
/// The path to which we should emit module summary file.
154154
std::string ModuleSummaryOutputPath;
155+
156+
/// The directory to which we should emit symbol graphs for the current module.
157+
std::string SymbolGraphOutputDir;
155158

156159
SupplementaryOutputPaths() = default;
157160
SupplementaryOutputPaths(const SupplementaryOutputPaths &) = default;
@@ -186,6 +189,8 @@ struct SupplementaryOutputPaths {
186189
fn(LdAddCFilePath);
187190
if (!ModuleSummaryOutputPath.empty())
188191
fn(ModuleSummaryOutputPath);
192+
if (!SymbolGraphOutputDir.empty())
193+
fn(SymbolGraphOutputDir);
189194
}
190195

191196
bool empty() const {
@@ -194,7 +199,8 @@ struct SupplementaryOutputPaths {
194199
ReferenceDependenciesFilePath.empty() &&
195200
SerializedDiagnosticsPath.empty() && LoadedModuleTracePath.empty() &&
196201
TBDPath.empty() && ModuleInterfaceOutputPath.empty() &&
197-
ModuleSourceInfoOutputPath.empty() && LdAddCFilePath.empty();
202+
ModuleSourceInfoOutputPath.empty() && LdAddCFilePath.empty() &&
203+
SymbolGraphOutputDir.empty();
198204
}
199205
};
200206
} // namespace swift

include/swift/Driver/Driver.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,11 @@ class Driver {
416416
const TypeToPathMap *OutputMap,
417417
StringRef workingDirectory,
418418
CommandOutput *Output) const;
419+
420+
void chooseSymbolGraphOutputPath(Compilation &C,
421+
const TypeToPathMap *OutputMap,
422+
StringRef workingDirectory,
423+
CommandOutput *Output) const;
419424

420425
void chooseLoadedModuleTracePath(Compilation &C,
421426
StringRef workingDirectory,

lib/Basic/FileTypes.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ bool file_types::isTextual(ID Id) {
106106
case file_types::TY_IndexData:
107107
case file_types::TY_BitstreamOptRecord:
108108
case file_types::TY_IndexUnitOutputPath:
109+
case file_types::TY_SymbolGraphOutputPath:
109110
return false;
110111
case file_types::TY_INVALID:
111112
llvm_unreachable("Invalid type ID.");
@@ -157,6 +158,7 @@ bool file_types::isAfterLLVM(ID Id) {
157158
case file_types::TY_JSONDependencies:
158159
case file_types::TY_JSONFeatures:
159160
case file_types::TY_IndexUnitOutputPath:
161+
case file_types::TY_SymbolGraphOutputPath:
160162
return false;
161163
case file_types::TY_INVALID:
162164
llvm_unreachable("Invalid type ID.");
@@ -208,6 +210,7 @@ bool file_types::isPartOfSwiftCompilation(ID Id) {
208210
case file_types::TY_JSONDependencies:
209211
case file_types::TY_JSONFeatures:
210212
case file_types::TY_IndexUnitOutputPath:
213+
case file_types::TY_SymbolGraphOutputPath:
211214
return false;
212215
case file_types::TY_INVALID:
213216
llvm_unreachable("Invalid type ID.");

lib/Driver/Driver.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2044,6 +2044,7 @@ void Driver::buildActions(SmallVectorImpl<const Action *> &TopLevelActions,
20442044
case file_types::TY_RawSIL:
20452045
case file_types::TY_Nothing:
20462046
case file_types::TY_IndexUnitOutputPath:
2047+
case file_types::TY_SymbolGraphOutputPath:
20472048
case file_types::TY_INVALID:
20482049
llvm_unreachable("these types should never be inferred");
20492050
}
@@ -2943,6 +2944,10 @@ Job *Driver::buildJobsForAction(Compilation &C, const JobAction *JA,
29432944
options::OPT_emit_objc_header_path))
29442945
chooseObjectiveCHeaderOutputPath(C, OutputMap, workingDirectory,
29452946
Output.get());
2947+
2948+
if (C.getArgs().hasArg(options::OPT_emit_symbol_graph)) {
2949+
chooseSymbolGraphOutputPath(C, OutputMap, workingDirectory, Output.get());
2950+
}
29462951

29472952
// 4. Construct a Job which produces the right CommandOutput.
29482953
std::unique_ptr<Job> ownedJob = TC.constructJob(*JA, C, std::move(InputJobs),
@@ -3413,6 +3418,31 @@ void Driver::chooseOptimizationRecordPath(Compilation &C,
34133418
Diags.diagnose({}, diag::warn_opt_remark_disabled);
34143419
}
34153420

3421+
void Driver::chooseSymbolGraphOutputPath(Compilation &C,
3422+
const TypeToPathMap *OutputMap,
3423+
StringRef workingDirectory,
3424+
CommandOutput *Output) const {
3425+
StringRef optionOutput = C.getArgs().getLastArgValue(options::OPT_emit_symbol_graph_dir);
3426+
if (hasExistingAdditionalOutput(*Output, file_types::TY_SymbolGraphOutputPath, optionOutput)) {
3427+
return;
3428+
}
3429+
3430+
StringRef SymbolGraphDir;
3431+
if (OutputMap) {
3432+
auto iter = OutputMap->find(file_types::TY_SymbolGraphOutputPath);
3433+
if (iter != OutputMap->end())
3434+
SymbolGraphDir = iter->second;
3435+
}
3436+
3437+
if (SymbolGraphDir.empty() && !optionOutput.empty()) {
3438+
SymbolGraphDir = optionOutput;
3439+
}
3440+
3441+
if (!SymbolGraphDir.empty()) {
3442+
Output->setAdditionalOutputForType(file_types::TY_SymbolGraphOutputPath, SymbolGraphDir);
3443+
}
3444+
}
3445+
34163446
void Driver::chooseObjectiveCHeaderOutputPath(Compilation &C,
34173447
const TypeToPathMap *OutputMap,
34183448
StringRef workingDirectory,

lib/Driver/ToolChains.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -574,11 +574,6 @@ ToolChain::constructInvocation(const CompileJobAction &job,
574574
options::
575575
OPT_disable_autolinking_runtime_compatibility_dynamic_replacements);
576576

577-
if (context.OI.CompilerMode == OutputInfo::Mode::SingleCompile) {
578-
context.Args.AddLastArg(Arguments, options::OPT_emit_symbol_graph);
579-
context.Args.AddLastArg(Arguments, options::OPT_emit_symbol_graph_dir);
580-
}
581-
582577
return II;
583578
}
584579

@@ -656,6 +651,7 @@ const char *ToolChain::JobContext::computeFrontendModeForCompile() const {
656651
case file_types::TY_SwiftCrossImportDir:
657652
case file_types::TY_SwiftOverlayFile:
658653
case file_types::TY_IndexUnitOutputPath:
654+
case file_types::TY_SymbolGraphOutputPath:
659655
llvm_unreachable("Output type can never be primary output.");
660656
case file_types::TY_INVALID:
661657
llvm_unreachable("Invalid type ID");
@@ -797,6 +793,8 @@ void ToolChain::JobContext::addFrontendSupplementaryOutputArguments(
797793
addOutputsOfType(arguments, Output, Args,
798794
file_types::TY_SwiftModuleSummaryFile,
799795
"-emit-module-summary-path");
796+
addOutputsOfType(arguments, Output, Args, file_types::TY_SymbolGraphOutputPath,
797+
"-emit-symbol-graph-dir");
800798
}
801799

802800
ToolChain::InvocationInfo
@@ -914,6 +912,7 @@ ToolChain::constructInvocation(const BackendJobAction &job,
914912
case file_types::TY_SwiftCrossImportDir:
915913
case file_types::TY_SwiftOverlayFile:
916914
case file_types::TY_IndexUnitOutputPath:
915+
case file_types::TY_SymbolGraphOutputPath:
917916
llvm_unreachable("Output type can never be primary output.");
918917
case file_types::TY_INVALID:
919918
llvm_unreachable("Invalid type ID");

lib/Frontend/ArgsToFrontendOutputsConverter.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,11 +341,14 @@ SupplementaryOutputPathsComputer::getSupplementaryOutputPathsFromArguments()
341341
options::OPT_emit_ldadd_cfile_path);
342342
auto moduleSummaryOutput = getSupplementaryFilenamesFromArguments(
343343
options::OPT_emit_module_summary_path);
344+
auto symbolGraphOutput = getSupplementaryFilenamesFromArguments(
345+
options::OPT_emit_symbol_graph_dir);
344346
if (!objCHeaderOutput || !moduleOutput || !moduleDocOutput ||
345347
!dependenciesFile || !referenceDependenciesFile ||
346348
!serializedDiagnostics || !fixItsOutput || !loadedModuleTrace || !TBD ||
347349
!moduleInterfaceOutput || !privateModuleInterfaceOutput ||
348-
!moduleSourceInfoOutput || !ldAddCFileOutput || !moduleSummaryOutput) {
350+
!moduleSourceInfoOutput || !ldAddCFileOutput || !moduleSummaryOutput ||
351+
!symbolGraphOutput) {
349352
return None;
350353
}
351354
std::vector<SupplementaryOutputPaths> result;
@@ -368,6 +371,7 @@ SupplementaryOutputPathsComputer::getSupplementaryOutputPathsFromArguments()
368371
sop.ModuleSourceInfoOutputPath = (*moduleSourceInfoOutput)[i];
369372
sop.LdAddCFilePath = (*ldAddCFileOutput)[i];
370373
sop.ModuleSummaryOutputPath = (*moduleSummaryOutput)[i];
374+
sop.SymbolGraphOutputDir = (*symbolGraphOutput)[i];
371375
result.push_back(sop);
372376
}
373377
return result;
@@ -459,6 +463,11 @@ SupplementaryOutputPathsComputer::computeOutputPathsForOneInput(
459463
OPT_emit_module_summary, pathsFromArguments.ModuleSummaryOutputPath,
460464
file_types::TY_SwiftModuleSummaryFile, "",
461465
defaultSupplementaryOutputPathExcludingExtension);
466+
467+
auto symbolGraphOutputDir = determineSupplementaryOutputFilename(
468+
OPT_emit_symbol_graph_dir, pathsFromArguments.SymbolGraphOutputDir,
469+
file_types::TY_SymbolGraphOutputPath, "",
470+
defaultSupplementaryOutputPathExcludingExtension);
462471

463472
// There is no non-path form of -emit-interface-path
464473
auto ModuleInterfaceOutputPath =
@@ -492,6 +501,7 @@ SupplementaryOutputPathsComputer::computeOutputPathsForOneInput(
492501
sop.ModuleSourceInfoOutputPath = moduleSourceInfoOutputPath;
493502
sop.LdAddCFilePath = pathsFromArguments.LdAddCFilePath;
494503
sop.ModuleSummaryOutputPath = moduleSummaryOutputPath;
504+
sop.SymbolGraphOutputDir = symbolGraphOutputDir;
495505
return sop;
496506
}
497507

@@ -574,6 +584,7 @@ createFromTypeToPathMap(const TypeToPathMap *map) {
574584
{file_types::TY_SwiftModuleSummaryFile, paths.ModuleSummaryOutputPath},
575585
{file_types::TY_PrivateSwiftModuleInterfaceFile,
576586
paths.PrivateModuleInterfaceOutputPath},
587+
{file_types::TY_SymbolGraphOutputPath, paths.SymbolGraphOutputDir},
577588
};
578589
for (const std::pair<file_types::ID, std::string &> &typeAndString :
579590
typesAndStrings) {
@@ -597,7 +608,8 @@ SupplementaryOutputPathsComputer::readSupplementaryOutputFileMap() const {
597608
options::OPT_emit_private_module_interface_path,
598609
options::OPT_emit_module_source_info_path,
599610
options::OPT_emit_tbd_path,
600-
options::OPT_emit_ldadd_cfile_path)) {
611+
options::OPT_emit_ldadd_cfile_path,
612+
options::OPT_emit_symbol_graph_dir)) {
601613
Diags.diagnose(SourceLoc(),
602614
diag::error_cannot_have_supplementary_outputs,
603615
A->getSpelling(), "-supplementary-output-file-map");

lib/Frontend/Frontend.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,9 @@ SerializationOptions CompilerInvocation::computeSerializationOptions(
156156
serializationOpts.ModuleLinkName = opts.ModuleLinkName;
157157
serializationOpts.ExtraClangOptions = getClangImporterOptions().ExtraArgs;
158158

159-
if (opts.EmitSymbolGraph) {
159+
if (!outs.SymbolGraphOutputDir.empty()) {
160+
serializationOpts.SymbolGraphOutputDir = outs.SymbolGraphOutputDir;
161+
} else if (opts.EmitSymbolGraph) {
160162
if (!opts.SymbolGraphOutputDir.empty()) {
161163
serializationOpts.SymbolGraphOutputDir = opts.SymbolGraphOutputDir;
162164
} else {

test/Driver/filelists.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@
3535
// CHECK-WMO-NOT: Handled
3636

3737

38+
// RUN: %swiftc_driver -save-temps -driver-print-jobs -c %S/Inputs/lib.swift -module-name lib -target x86_64-apple-macosx10.9 -driver-filelist-threshold=0 -whole-module-optimization -emit-module -emit-symbol-graph -emit-symbol-graph-dir %t 2>&1 | tee %t/forWMOFilelistCapture | %FileCheck -check-prefix=CHECK-WMO-SYM-FILELIST %s
39+
// RUN: tail -2 %t/forWMOFilelistCapture | head -1 | sed 's/.*-supplementary-output-file-map //' | sed 's/ .*//' > %t/supplementary-output
40+
// RUN: cat $(cat %t/supplementary-output) | %FileCheck -check-prefix CHECK-WMO-SYM-SUPP %s
41+
42+
// CHECK-WMO-SYM-FILELIST: swift
43+
// CHECK-WMO-SYM-FILELIST-DAG: -supplementary-output-file-map
44+
45+
// CHECK-WMO-SYM-SUPP: symbol-graph-output-path
46+
47+
3848
// RUN: %empty-directory(%t/bin)
3949
// RUN: ln -s %S/Inputs/filelists/fake-ld.py %t/bin/ld
4050

0 commit comments

Comments
 (0)