Skip to content

Commit dd88e0d

Browse files
Merge pull request #39865 from apple/QuietMisdreavus/private-swiftc-symbols
[Driver][SymbolGraph] add new flag -symbol-graph-minimum-access-level rdar://79099869
2 parents 646397a + 583a45c commit dd88e0d

File tree

11 files changed

+58
-34
lines changed

11 files changed

+58
-34
lines changed

include/swift/Option/Options.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,6 +1282,11 @@ def emit_symbol_graph_dir : Separate<["-"], "emit-symbol-graph-dir">,
12821282
HelpText<"Emit a symbol graph to directory <dir>">,
12831283
MetaVarName<"<dir>">;
12841284

1285+
def symbol_graph_minimum_access_level: Separate<["-"], "symbol-graph-minimum-access-level">,
1286+
Flags<[FrontendOption, NoInteractiveOption, SupplementaryOutput, HelpHidden]>,
1287+
HelpText<"Include symbols with this access level or more when emitting a symbol graph">,
1288+
MetaVarName<"<level>">;
1289+
12851290
def pretty_print: Flag<["-"], "pretty-print">,
12861291
Flags<[SwiftAPIExtractOption, SwiftSymbolGraphExtractOption]>,
12871292
HelpText<"Pretty-print the output JSON">;

include/swift/Serialization/SerializationOptions.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,7 @@ namespace swift {
3232
const char *OutputPath = nullptr;
3333
const char *DocOutputPath = nullptr;
3434
const char *SourceInfoOutputPath = nullptr;
35-
std::string SymbolGraphOutputDir;
3635
std::string ABIDescriptorPath;
37-
bool SkipSymbolGraphInheritedDocs = true;
38-
bool IncludeSPISymbolsInSymbolGraph = false;
3936
llvm::VersionTuple UserModuleVersion;
4037
std::string SDKName;
4138

include/swift/Subsystems.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ namespace swift {
8686
class SourceFileDepGraph;
8787
}
8888

89+
namespace symbolgraphgen {
90+
struct SymbolGraphOptions;
91+
}
92+
8993
/// @{
9094

9195
/// \returns true if the declaration should be verified. This can return
@@ -187,6 +191,7 @@ namespace swift {
187191
/// Serializes a module or single source file to the given output file.
188192
void
189193
serialize(ModuleOrSourceFile DC, const SerializationOptions &options,
194+
const symbolgraphgen::SymbolGraphOptions &symbolGraphOptions,
190195
const SILModule *M = nullptr,
191196
const fine_grained_dependencies::SourceFileDepGraph *DG = nullptr);
192197

lib/Driver/ToolChains.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,7 @@ ToolChain::constructInvocation(const CompileJobAction &job,
602602
context.Args.AddLastArg(Arguments, options::OPT_emit_symbol_graph_dir);
603603
}
604604
context.Args.AddLastArg(Arguments, options::OPT_include_spi_symbols);
605+
context.Args.AddLastArg(Arguments, options::OPT_symbol_graph_minimum_access_level);
605606

606607
return II;
607608
}
@@ -1093,6 +1094,7 @@ ToolChain::constructInvocation(const MergeModuleJobAction &job,
10931094
context.Args.AddLastArg(Arguments, options::OPT_emit_symbol_graph);
10941095
context.Args.AddLastArg(Arguments, options::OPT_emit_symbol_graph_dir);
10951096
context.Args.AddLastArg(Arguments, options::OPT_include_spi_symbols);
1097+
context.Args.AddLastArg(Arguments, options::OPT_symbol_graph_minimum_access_level);
10961098

10971099
context.Args.AddLastArg(Arguments, options::OPT_import_objc_header);
10981100

lib/Frontend/CompilerInvocation.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1107,8 +1107,20 @@ static void ParseSymbolGraphArgs(symbolgraphgen::SymbolGraphOptions &Opts,
11071107
Opts.SkipInheritedDocs = Args.hasArg(OPT_skip_inherited_docs);
11081108
Opts.IncludeSPISymbols = Args.hasArg(OPT_include_spi_symbols);
11091109

1110+
if (auto *A = Args.getLastArg(OPT_symbol_graph_minimum_access_level)) {
1111+
Opts.MinimumAccessLevel =
1112+
llvm::StringSwitch<AccessLevel>(A->getValue())
1113+
.Case("open", AccessLevel::Open)
1114+
.Case("public", AccessLevel::Public)
1115+
.Case("internal", AccessLevel::Internal)
1116+
.Case("fileprivate", AccessLevel::FilePrivate)
1117+
.Case("private", AccessLevel::Private)
1118+
.Default(AccessLevel::Public);
1119+
} else {
1120+
Opts.MinimumAccessLevel = AccessLevel::Public;
1121+
}
1122+
11101123
// default values for generating symbol graphs during a build
1111-
Opts.MinimumAccessLevel = AccessLevel::Public;
11121124
Opts.PrettyPrint = false;
11131125
Opts.EmitSynthesizedMembers = true;
11141126
Opts.PrintMessages = false;

lib/Frontend/Frontend.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -153,19 +153,6 @@ SerializationOptions CompilerInvocation::computeSerializationOptions(
153153
getIRGenOptions().PublicLinkLibraries;
154154
serializationOpts.SDKName = getLangOptions().SDKName;
155155
serializationOpts.ABIDescriptorPath = outs.ABIDescriptorOutputPath.c_str();
156-
157-
if (opts.EmitSymbolGraph) {
158-
if (!opts.SymbolGraphOutputDir.empty()) {
159-
serializationOpts.SymbolGraphOutputDir = opts.SymbolGraphOutputDir;
160-
} else {
161-
serializationOpts.SymbolGraphOutputDir = serializationOpts.OutputPath;
162-
}
163-
SmallString<256> OutputDir(serializationOpts.SymbolGraphOutputDir);
164-
llvm::sys::fs::make_absolute(OutputDir);
165-
serializationOpts.SymbolGraphOutputDir = OutputDir.str().str();
166-
}
167-
serializationOpts.SkipSymbolGraphInheritedDocs = opts.SkipInheritedDocs;
168-
serializationOpts.IncludeSPISymbolsInSymbolGraph = opts.IncludeSPISymbolsInSymbolGraph;
169156

170157
if (!getIRGenOptions().ForceLoadSymbolName.empty())
171158
serializationOpts.AutolinkForceLoad = true;

lib/FrontendTool/FrontendTool.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
#include "swift/Serialization/SerializationOptions.h"
6666
#include "swift/Serialization/SerializedModuleLoader.h"
6767
#include "swift/SILOptimizer/PassManager/Passes.h"
68+
#include "swift/SymbolGraphGen/SymbolGraphOptions.h"
6869
#include "swift/Syntax/Serialization/SyntaxSerialization.h"
6970
#include "swift/Syntax/SyntaxNodes.h"
7071
#include "swift/TBDGen/TBDGen.h"
@@ -1301,7 +1302,9 @@ static bool serializeSIB(SILModule *SM, const PrimarySpecificPaths &PSPs,
13011302
serializationOpts.SerializeAllSIL = true;
13021303
serializationOpts.IsSIB = true;
13031304

1304-
serialize(MSF, serializationOpts, SM);
1305+
symbolgraphgen::SymbolGraphOptions symbolGraphOptions;
1306+
1307+
serialize(MSF, serializationOpts, symbolGraphOptions, SM);
13051308
return Context.hadError();
13061309
}
13071310

@@ -1554,11 +1557,11 @@ static bool performCompileStepsPostSILGen(CompilerInstance &Instance,
15541557
fine_grained_dependencies::withReferenceDependencies(
15551558
Mod, *Instance.getDependencyTracker(), Mod->getModuleFilename(),
15561559
alsoEmitDotFile, [&](SourceFileDepGraph &&g) {
1557-
serialize(MSF, serializationOpts, SM.get(), &g);
1560+
serialize(MSF, serializationOpts, Invocation.getSymbolGraphOptions(), SM.get(), &g);
15581561
return false;
15591562
});
15601563
} else {
1561-
serialize(MSF, serializationOpts, SM.get());
1564+
serialize(MSF, serializationOpts, Invocation.getSymbolGraphOptions(), SM.get());
15621565
}
15631566
};
15641567

lib/Serialization/Serialization.cpp

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5753,6 +5753,7 @@ void swift::serializeToBuffers(
57535753

57545754
void swift::serialize(ModuleOrSourceFile DC,
57555755
const SerializationOptions &options,
5756+
const symbolgraphgen::SymbolGraphOptions &symbolGraphOptions,
57565757
const SILModule *M,
57575758
const fine_grained_dependencies::SourceFileDepGraph *DG) {
57585759
assert(!withNullAsEmptyStringRef(options.OutputPath).empty());
@@ -5797,22 +5798,12 @@ void swift::serialize(ModuleOrSourceFile DC,
57975798
});
57985799
}
57995800

5800-
if (!options.SymbolGraphOutputDir.empty()) {
5801+
if (!symbolGraphOptions.OutputDir.empty()) {
58015802
if (DC.is<ModuleDecl *>()) {
58025803
auto *M = DC.get<ModuleDecl*>();
58035804
FrontendStatsTracer tracer(getContext(DC).Stats,
58045805
"Serialization, symbolgraph");
5805-
symbolgraphgen::SymbolGraphOptions SGOpts {
5806-
options.SymbolGraphOutputDir,
5807-
M->getASTContext().LangOpts.Target,
5808-
/* PrettyPrint */false,
5809-
AccessLevel::Public,
5810-
/*EmitSynthesizedMembers*/true,
5811-
/*PrintMessages*/false,
5812-
/*EmitInheritedDocs*/options.SkipSymbolGraphInheritedDocs,
5813-
/*IncludeSPISymbols*/options.IncludeSPISymbolsInSymbolGraph,
5814-
};
5815-
symbolgraphgen::emitSymbolGraphForModule(M, SGOpts);
5806+
symbolgraphgen::emitSymbolGraphForModule(M, symbolGraphOptions);
58165807
}
58175808
}
58185809
emitABIDescriptor(DC, options);

test/SymbolGraph/EmitWhileBuilding.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %target-build-swift %s -module-name EmitWhileBuilding -emit-module -emit-module-path %t/EmitWhileBuilding.swiftmodule -emit-symbol-graph -emit-symbol-graph-dir %t/
33
// RUN: %FileCheck %s --input-file %t/EmitWhileBuilding.symbols.json
4+
// RUN: %FileCheck %s --input-file %t/EmitWhileBuilding.symbols.json --check-prefix PUB
45

56
// also try without the trailing slash on `-emit-symbol-graph-dir` and make sure it works
67

78
// RUN: %empty-directory(%t)
89
// RUN: %target-build-swift %s -module-name EmitWhileBuilding -emit-module -emit-module-path %t/EmitWhileBuilding.swiftmodule -emit-symbol-graph -emit-symbol-graph-dir %t
910
// RUN: %FileCheck %s --input-file %t/EmitWhileBuilding.symbols.json
11+
// RUN: %FileCheck %s --input-file %t/EmitWhileBuilding.symbols.json --check-prefix PUB
1012

1113
// also try while forcing the use of supplementary file maps to make sure the symbol graph path gets
1214
// added to the file map for the inner frontend call
1315

1416
// RUN: %empty-directory(%t)
1517
// RUN: %target-build-swift %s -module-name EmitWhileBuilding -emit-module -emit-module-path %t/EmitWhileBuilding.swiftmodule -emit-symbol-graph -emit-symbol-graph-dir %t -driver-filelist-threshold=0 -O -whole-module-optimization
1618
// RUN: %FileCheck %s --input-file %t/EmitWhileBuilding.symbols.json
19+
// RUN: %FileCheck %s --input-file %t/EmitWhileBuilding.symbols.json --check-prefix PUB
1720

1821
// also try with an up-to-date incremental build to make sure that adding the symbol graph flags
1922
// can get them to be generated
@@ -23,8 +26,21 @@
2326
// RUN: cd %t && %target-build-swift %t/EmitWhileBuilding.swift -module-name EmitWhileBuilding -c -emit-module -emit-module-path %t/EmitWhileBuilding.swiftmodule -emit-dependencies -incremental -output-file-map=%S/Inputs/EmitWhileBuilding.output.json -working-directory %t -v -driver-show-incremental
2427
// RUN: cd %t && %target-build-swift %t/EmitWhileBuilding.swift -module-name EmitWhileBuilding -c -emit-module -emit-module-path %t/EmitWhileBuilding.swiftmodule -emit-dependencies -incremental -output-file-map=%S/Inputs/EmitWhileBuilding.output.json -working-directory %t -v -driver-show-incremental -emit-symbol-graph -emit-symbol-graph-dir %t
2528
// RUN: %FileCheck %s --input-file %t/EmitWhileBuilding.symbols.json
29+
// RUN: %FileCheck %s --input-file %t/EmitWhileBuilding.symbols.json --check-prefix PUB
30+
31+
// now run with -symbol-graph-minimum-access-level to change the available symbols
32+
33+
// RUN: %empty-directory(%t)
34+
// RUN: %target-build-swift %s -module-name EmitWhileBuilding -emit-module -emit-module-path %t/EmitWhileBuilding.swiftmodule -emit-symbol-graph -emit-symbol-graph-dir %t/ -symbol-graph-minimum-access-level private
35+
// RUN: %FileCheck %s --input-file %t/EmitWhileBuilding.symbols.json
36+
// RUN: %FileCheck %s --input-file %t/EmitWhileBuilding.symbols.json --check-prefix PRIV
2637

2738
/// Does a foo.
2839
public func foo() {}
2940

41+
/// Does a bar.
42+
func bar() {}
43+
3044
// CHECK: "precise":"s:17EmitWhileBuilding3fooyyF"
45+
// PUB-NOT: "precise":"s:17EmitWhileBuilding3baryyF"
46+
// PRIV: "precise":"s:17EmitWhileBuilding3baryyF"

tools/sil-func-extractor/SILFunctionExtractor.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "swift/Serialization/SerializedModuleLoader.h"
3737
#include "swift/Serialization/SerializationOptions.h"
3838
#include "swift/Serialization/SerializedSILLoader.h"
39+
#include "swift/SymbolGraphGen/SymbolGraphOptions.h"
3940
#include "swift/Subsystems.h"
4041
#include "llvm/Support/CommandLine.h"
4142
#include "llvm/Support/Debug.h"
@@ -356,7 +357,9 @@ int main(int argc, char **argv) {
356357
serializationOpts.SerializeAllSIL = true;
357358
serializationOpts.IsSIB = true;
358359

359-
serialize(CI.getMainModule(), serializationOpts, SILMod.get());
360+
symbolgraphgen::SymbolGraphOptions symbolGraphOpts;
361+
362+
serialize(CI.getMainModule(), serializationOpts, symbolGraphOpts, SILMod.get());
360363
} else {
361364
const StringRef OutputFile =
362365
OutputFilename.size() ? StringRef(OutputFilename) : "-";

tools/sil-opt/SILOpt.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "swift/Serialization/SerializedModuleLoader.h"
3232
#include "swift/Serialization/SerializedSILLoader.h"
3333
#include "swift/Serialization/SerializationOptions.h"
34+
#include "swift/SymbolGraphGen/SymbolGraphOptions.h"
3435
#include "swift/IRGen/IRGenPublic.h"
3536
#include "swift/IRGen/IRGenSILPasses.h"
3637
#include "llvm/ADT/Statistic.h"
@@ -644,7 +645,9 @@ int main(int argc, char **argv) {
644645
serializationOpts.SerializeAllSIL = EmitSIB;
645646
serializationOpts.IsSIB = EmitSIB;
646647

647-
serialize(CI.getMainModule(), serializationOpts, SILMod.get());
648+
symbolgraphgen::SymbolGraphOptions symbolGraphOptions;
649+
650+
serialize(CI.getMainModule(), serializationOpts, symbolGraphOptions, SILMod.get());
648651
} else {
649652
const StringRef OutputFile = OutputFilename.size() ?
650653
StringRef(OutputFilename) : "-";

0 commit comments

Comments
 (0)