Skip to content

Commit 40b084e

Browse files
Merge pull request #37640 from apple/QuietMisdreavus/spi-symbols
add symbol-graph flag to include SPI symbols
2 parents fc80a9a + d281722 commit 40b084e

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
@@ -425,6 +425,9 @@ class FrontendOptions {
425425
/// which are inherited through classes or default implementations.
426426
bool SkipInheritedDocs = false;
427427

428+
/// Whether to include symbols with SPI information in the symbol graph.
429+
bool IncludeSPISymbolsInSymbolGraph = false;
430+
428431
private:
429432
static bool canActionEmitDependencies(ActionType);
430433
static bool canActionEmitReferenceDependencies(ActionType);

include/swift/Option/Options.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,6 +1252,11 @@ def skip_inherited_docs : Flag<["-"], "skip-inherited-docs">,
12521252
HelpText<"Skip emitting doc comments for members inherited through classes or "
12531253
"default implementations">;
12541254

1255+
def include_spi_symbols : Flag<["-"], "include-spi-symbols">,
1256+
Flags<[SwiftSymbolGraphExtractOption, FrontendOption,
1257+
NoInteractiveOption, SupplementaryOutput, HelpHidden]>,
1258+
HelpText<"Add symbols with SPI information to the symbol graph">;
1259+
12551260
// swift-api-digester-only options
12561261
def dump_sdk: Flag<["-", "--"], "dump-sdk">,
12571262
Flags<[NoDriverOption, SwiftAPIDigesterOption]>,

include/swift/Serialization/SerializationOptions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ namespace swift {
3333
const char *SourceInfoOutputPath = nullptr;
3434
std::string SymbolGraphOutputDir;
3535
bool SkipSymbolGraphInheritedDocs = true;
36+
bool IncludeSPISymbolsInSymbolGraph = false;
3637
llvm::VersionTuple UserModuleVersion;
3738

3839
StringRef GroupInfoPath;

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
@@ -582,6 +582,7 @@ ToolChain::constructInvocation(const CompileJobAction &job,
582582
if (context.OI.CompilerMode == OutputInfo::Mode::SingleCompile) {
583583
context.Args.AddLastArg(Arguments, options::OPT_emit_symbol_graph);
584584
context.Args.AddLastArg(Arguments, options::OPT_emit_symbol_graph_dir);
585+
context.Args.AddLastArg(Arguments, options::OPT_include_spi_symbols);
585586
}
586587

587588
return II;
@@ -1072,6 +1073,7 @@ ToolChain::constructInvocation(const MergeModuleJobAction &job,
10721073

10731074
context.Args.AddLastArg(Arguments, options::OPT_emit_symbol_graph);
10741075
context.Args.AddLastArg(Arguments, options::OPT_emit_symbol_graph_dir);
1076+
context.Args.AddLastArg(Arguments, options::OPT_include_spi_symbols);
10751077

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

lib/Frontend/ArgsToFrontendOptionsConverter.cpp

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

274274
Opts.SkipInheritedDocs = Args.hasArg(OPT_skip_inherited_docs);
275+
Opts.IncludeSPISymbolsInSymbolGraph = Args.hasArg(OPT_include_spi_symbols);
275276

276277
Opts.Static = Args.hasArg(OPT_static);
277278

lib/Frontend/Frontend.cpp

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

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

lib/Serialization/Serialization.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5665,6 +5665,7 @@ void swift::serialize(ModuleOrSourceFile DC,
56655665
/*EmitSynthesizedMembers*/true,
56665666
/*PrintMessages*/false,
56675667
/*EmitInheritedDocs*/options.SkipSymbolGraphInheritedDocs,
5668+
/*IncludeSPISymbols*/options.IncludeSPISymbolsInSymbolGraph,
56685669
};
56695670
symbolgraphgen::emitSymbolGraphForModule(M, SGOpts);
56705671
}

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)