Skip to content

Commit 1d189de

Browse files
Merge pull request #37641 from apple/QuietMisdreavus/5.5/spi-symbols
[5.5] [SymbolGraph][Driver] add symbol-graph flag to include SPI symbols
2 parents 221d81e + fd26b86 commit 1d189de

File tree

14 files changed

+53
-1
lines changed

14 files changed

+53
-1
lines changed

include/swift/Frontend/FrontendOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,9 @@ class FrontendOptions {
399399
/// which are inherited through classes or default implementations.
400400
bool SkipInheritedDocs = false;
401401

402+
/// Whether to include symbols with SPI information in the symbol graph.
403+
bool IncludeSPISymbolsInSymbolGraph = false;
404+
402405
private:
403406
static bool canActionEmitDependencies(ActionType);
404407
static bool canActionEmitReferenceDependencies(ActionType);

include/swift/Option/Options.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,4 +1230,9 @@ def skip_inherited_docs : Flag<["-"], "skip-inherited-docs">,
12301230
HelpText<"Skip emitting doc comments for members inherited through classes or "
12311231
"default implementations">;
12321232

1233+
def include_spi_symbols : Flag<["-"], "include-spi-symbols">,
1234+
Flags<[SwiftSymbolGraphExtractOption, FrontendOption,
1235+
NoInteractiveOption, SupplementaryOutput, HelpHidden]>,
1236+
HelpText<"Add symbols with SPI information to the symbol graph">;
1237+
12331238
include "FrontendOptions.td"

include/swift/Serialization/SerializationOptions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ namespace swift {
3232
const char *SourceInfoOutputPath = nullptr;
3333
std::string SymbolGraphOutputDir;
3434
bool SkipSymbolGraphInheritedDocs = true;
35+
bool IncludeSPISymbolsInSymbolGraph = false;
3536

3637
StringRef GroupInfoPath;
3738
StringRef ImportedHeader;

include/swift/SymbolGraphGen/SymbolGraphOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ struct SymbolGraphOptions {
4242

4343
/// Whether to skip docs for symbols with compound, "SYNTHESIZED" USRs.
4444
bool SkipInheritedDocs;
45+
46+
/// Whether to emit symbols with SPI information.
47+
bool IncludeSPISymbols;
4548
};
4649

4750
} // end namespace symbolgraphgen

lib/Driver/ToolChains.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,7 @@ ToolChain::constructInvocation(const CompileJobAction &job,
581581
if (context.OI.CompilerMode == OutputInfo::Mode::SingleCompile) {
582582
context.Args.AddLastArg(Arguments, options::OPT_emit_symbol_graph);
583583
context.Args.AddLastArg(Arguments, options::OPT_emit_symbol_graph_dir);
584+
context.Args.AddLastArg(Arguments, options::OPT_include_spi_symbols);
584585
}
585586

586587
return II;
@@ -1071,6 +1072,7 @@ ToolChain::constructInvocation(const MergeModuleJobAction &job,
10711072

10721073
context.Args.AddLastArg(Arguments, options::OPT_emit_symbol_graph);
10731074
context.Args.AddLastArg(Arguments, options::OPT_emit_symbol_graph_dir);
1075+
context.Args.AddLastArg(Arguments, options::OPT_include_spi_symbols);
10741076

10751077
context.Args.AddLastArg(Arguments, options::OPT_import_objc_header);
10761078

lib/Frontend/ArgsToFrontendOptionsConverter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ bool ArgsToFrontendOptionsConverter::convert(
250250
}
251251

252252
Opts.SkipInheritedDocs = Args.hasArg(OPT_skip_inherited_docs);
253+
Opts.IncludeSPISymbolsInSymbolGraph = Args.hasArg(OPT_include_spi_symbols);
253254

254255
return false;
255256
}

lib/Frontend/Frontend.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ SerializationOptions CompilerInvocation::computeSerializationOptions(
167167
serializationOpts.SymbolGraphOutputDir = OutputDir.str().str();
168168
}
169169
serializationOpts.SkipSymbolGraphInheritedDocs = opts.SkipInheritedDocs;
170+
serializationOpts.IncludeSPISymbolsInSymbolGraph = opts.IncludeSPISymbolsInSymbolGraph;
170171

171172
if (!getIRGenOptions().ForceLoadSymbolName.empty())
172173
serializationOpts.AutolinkForceLoad = true;

lib/Serialization/Serialization.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5653,6 +5653,7 @@ void swift::serialize(ModuleOrSourceFile DC,
56535653
/*EmitSynthesizedMembers*/true,
56545654
/*PrintMessages*/false,
56555655
/*EmitInheritedDocs*/options.SkipSymbolGraphInheritedDocs,
5656+
/*IncludeSPISymbols*/options.IncludeSPISymbolsInSymbolGraph,
56565657
};
56575658
symbolgraphgen::emitSymbolGraphForModule(M, SGOpts);
56585659
}

lib/SymbolGraphGen/Symbol.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,11 @@ void Symbol::serializeAvailabilityMixin(llvm::json::OStream &OS) const {
471471
});
472472
}
473473

474+
void Symbol::serializeSPIMixin(llvm::json::OStream &OS) const {
475+
if (VD->isSPI())
476+
OS.attribute("spi", true);
477+
}
478+
474479
void Symbol::serialize(llvm::json::OStream &OS) const {
475480
OS.object([&](){
476481
serializeKind(OS);
@@ -487,6 +492,7 @@ void Symbol::serialize(llvm::json::OStream &OS) const {
487492
serializeAccessLevelMixin(OS);
488493
serializeAvailabilityMixin(OS);
489494
serializeLocationMixin(OS);
495+
serializeSPIMixin(OS);
490496
});
491497
}
492498

lib/SymbolGraphGen/Symbol.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ class Symbol {
7676

7777
void serializeAvailabilityMixin(llvm::json::OStream &OS) const;
7878

79+
void serializeSPIMixin(llvm::json::OStream &OS) const;
80+
7981
public:
8082
Symbol(SymbolGraph *Graph, const ValueDecl *VD,
8183
const NominalTypeDecl *SynthesizedBaseTypeDecl,

lib/SymbolGraphGen/SymbolGraph.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ bool SymbolGraph::isImplicitlyPrivate(const Decl *D,
630630

631631
// Don't include declarations with the @_spi attribute unless the
632632
// access control filter is internal or below.
633-
if (D->isSPI()) {
633+
if (D->isSPI() && !Walker.Options.IncludeSPISymbols) {
634634
return Walker.Options.MinimumAccessLevel > AccessLevel::Internal;
635635
}
636636

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-build-swift %s -module-name SPI -emit-module -emit-module-path %t/
3+
// RUN: %target-swift-symbolgraph-extract -module-name SPI -I %t -pretty-print -output-dir %t -include-spi-symbols
4+
// RUN: %FileCheck %s --input-file %t/SPI.symbols.json --check-prefix SPI
5+
6+
// RUN: %target-swift-symbolgraph-extract -module-name SPI -I %t -pretty-print -output-dir %t
7+
// RUN: %FileCheck %s --input-file %t/SPI.symbols.json --check-prefix NOSPI
8+
9+
// RUN: %empty-directory(%t)
10+
// RUN: %target-build-swift %s -module-name SPI -emit-module -emit-module-path %t/SPI.swiftmodule -emit-symbol-graph -emit-symbol-graph-dir %t/ -include-spi-symbols -v
11+
// RUN: %FileCheck %s --input-file %t/SPI.symbols.json --check-prefix SPI-COMPILE
12+
13+
// RUN: %empty-directory(%t)
14+
// RUN: %target-build-swift %s -module-name SPI -emit-module -emit-module-path %t/SPI.swiftmodule -emit-symbol-graph -emit-symbol-graph-dir %t/
15+
// RUN: %FileCheck %s --input-file %t/SPI.symbols.json --check-prefix NOSPI-COMPILE
16+
17+
@_spi(SPI) public struct SomeStruct {}
18+
19+
// SPI: "precise": "s:3SPI10SomeStructV"
20+
// SPI: "spi": true
21+
22+
// NOSPI-NOT: "precise": "s:3SPI10SomeStructV"
23+
24+
// SPI-COMPILE: s:3SPI10SomeStructV
25+
// NOSPI-COMPILE-NOT: s:3SPI10SomeStructV

tools/SourceKit/lib/SwiftLang/SwiftSourceDocInfo.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,7 @@ fillSymbolInfo(CursorSymbolInfo &Symbol, const DeclInfo &DInfo,
959959
/*EmitSynthesizedMembers*/ false,
960960
/*PrintMessages*/ false,
961961
/*SkipInheritedDocs*/ false,
962+
/*IncludeSPISymbols*/ true,
962963
};
963964

964965
symbolgraphgen::printSymbolGraphForDecl(DInfo.VD, DInfo.BaseType,

tools/driver/swift_symbolgraph_extract_main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ int swift_symbolgraph_extract_main(ArrayRef<const char *> Args,
168168
!ParsedArgs.hasArg(OPT_skip_synthesized_members),
169169
ParsedArgs.hasArg(OPT_v),
170170
ParsedArgs.hasArg(OPT_skip_inherited_docs),
171+
ParsedArgs.hasArg(OPT_include_spi_symbols),
171172
};
172173

173174
if (auto *A = ParsedArgs.getLastArg(OPT_minimum_access_level)) {

0 commit comments

Comments
 (0)