Skip to content

[5.5] [SymbolGraph][Driver] add symbol-graph flag to include SPI symbols #37641

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/swift/Frontend/FrontendOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,9 @@ class FrontendOptions {
/// which are inherited through classes or default implementations.
bool SkipInheritedDocs = false;

/// Whether to include symbols with SPI information in the symbol graph.
bool IncludeSPISymbolsInSymbolGraph = false;

private:
static bool canActionEmitDependencies(ActionType);
static bool canActionEmitReferenceDependencies(ActionType);
Expand Down
5 changes: 5 additions & 0 deletions include/swift/Option/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -1230,4 +1230,9 @@ def skip_inherited_docs : Flag<["-"], "skip-inherited-docs">,
HelpText<"Skip emitting doc comments for members inherited through classes or "
"default implementations">;

def include_spi_symbols : Flag<["-"], "include-spi-symbols">,
Flags<[SwiftSymbolGraphExtractOption, FrontendOption,
NoInteractiveOption, SupplementaryOutput, HelpHidden]>,
HelpText<"Add symbols with SPI information to the symbol graph">;

include "FrontendOptions.td"
1 change: 1 addition & 0 deletions include/swift/Serialization/SerializationOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ namespace swift {
const char *SourceInfoOutputPath = nullptr;
std::string SymbolGraphOutputDir;
bool SkipSymbolGraphInheritedDocs = true;
bool IncludeSPISymbolsInSymbolGraph = false;

StringRef GroupInfoPath;
StringRef ImportedHeader;
Expand Down
3 changes: 3 additions & 0 deletions include/swift/SymbolGraphGen/SymbolGraphOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ struct SymbolGraphOptions {

/// Whether to skip docs for symbols with compound, "SYNTHESIZED" USRs.
bool SkipInheritedDocs;

/// Whether to emit symbols with SPI information.
bool IncludeSPISymbols;
};

} // end namespace symbolgraphgen
Expand Down
2 changes: 2 additions & 0 deletions lib/Driver/ToolChains.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,7 @@ ToolChain::constructInvocation(const CompileJobAction &job,
if (context.OI.CompilerMode == OutputInfo::Mode::SingleCompile) {
context.Args.AddLastArg(Arguments, options::OPT_emit_symbol_graph);
context.Args.AddLastArg(Arguments, options::OPT_emit_symbol_graph_dir);
context.Args.AddLastArg(Arguments, options::OPT_include_spi_symbols);
}

return II;
Expand Down Expand Up @@ -1071,6 +1072,7 @@ ToolChain::constructInvocation(const MergeModuleJobAction &job,

context.Args.AddLastArg(Arguments, options::OPT_emit_symbol_graph);
context.Args.AddLastArg(Arguments, options::OPT_emit_symbol_graph_dir);
context.Args.AddLastArg(Arguments, options::OPT_include_spi_symbols);

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

Expand Down
1 change: 1 addition & 0 deletions lib/Frontend/ArgsToFrontendOptionsConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ bool ArgsToFrontendOptionsConverter::convert(
}

Opts.SkipInheritedDocs = Args.hasArg(OPT_skip_inherited_docs);
Opts.IncludeSPISymbolsInSymbolGraph = Args.hasArg(OPT_include_spi_symbols);

return false;
}
Expand Down
1 change: 1 addition & 0 deletions lib/Frontend/Frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ SerializationOptions CompilerInvocation::computeSerializationOptions(
serializationOpts.SymbolGraphOutputDir = OutputDir.str().str();
}
serializationOpts.SkipSymbolGraphInheritedDocs = opts.SkipInheritedDocs;
serializationOpts.IncludeSPISymbolsInSymbolGraph = opts.IncludeSPISymbolsInSymbolGraph;

if (!getIRGenOptions().ForceLoadSymbolName.empty())
serializationOpts.AutolinkForceLoad = true;
Expand Down
1 change: 1 addition & 0 deletions lib/Serialization/Serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5641,6 +5641,7 @@ void swift::serialize(ModuleOrSourceFile DC,
/*EmitSynthesizedMembers*/true,
/*PrintMessages*/false,
/*EmitInheritedDocs*/options.SkipSymbolGraphInheritedDocs,
/*IncludeSPISymbols*/options.IncludeSPISymbolsInSymbolGraph,
};
symbolgraphgen::emitSymbolGraphForModule(M, SGOpts);
}
Expand Down
6 changes: 6 additions & 0 deletions lib/SymbolGraphGen/Symbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,11 @@ void Symbol::serializeAvailabilityMixin(llvm::json::OStream &OS) const {
});
}

void Symbol::serializeSPIMixin(llvm::json::OStream &OS) const {
if (VD->isSPI())
OS.attribute("spi", true);
}

void Symbol::serialize(llvm::json::OStream &OS) const {
OS.object([&](){
serializeKind(OS);
Expand All @@ -487,6 +492,7 @@ void Symbol::serialize(llvm::json::OStream &OS) const {
serializeAccessLevelMixin(OS);
serializeAvailabilityMixin(OS);
serializeLocationMixin(OS);
serializeSPIMixin(OS);
});
}

Expand Down
2 changes: 2 additions & 0 deletions lib/SymbolGraphGen/Symbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ class Symbol {

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

void serializeSPIMixin(llvm::json::OStream &OS) const;

public:
Symbol(SymbolGraph *Graph, const ValueDecl *VD,
const NominalTypeDecl *SynthesizedBaseTypeDecl,
Expand Down
2 changes: 1 addition & 1 deletion lib/SymbolGraphGen/SymbolGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ bool SymbolGraph::isImplicitlyPrivate(const Decl *D,

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

Expand Down
25 changes: 25 additions & 0 deletions test/SymbolGraph/Symbols/Mixins/SPI.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// RUN: %empty-directory(%t)
// RUN: %target-build-swift %s -module-name SPI -emit-module -emit-module-path %t/
// RUN: %target-swift-symbolgraph-extract -module-name SPI -I %t -pretty-print -output-dir %t -include-spi-symbols
// RUN: %FileCheck %s --input-file %t/SPI.symbols.json --check-prefix SPI

// RUN: %target-swift-symbolgraph-extract -module-name SPI -I %t -pretty-print -output-dir %t
// RUN: %FileCheck %s --input-file %t/SPI.symbols.json --check-prefix NOSPI

// RUN: %empty-directory(%t)
// 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
// RUN: %FileCheck %s --input-file %t/SPI.symbols.json --check-prefix SPI-COMPILE

// RUN: %empty-directory(%t)
// RUN: %target-build-swift %s -module-name SPI -emit-module -emit-module-path %t/SPI.swiftmodule -emit-symbol-graph -emit-symbol-graph-dir %t/
// RUN: %FileCheck %s --input-file %t/SPI.symbols.json --check-prefix NOSPI-COMPILE

@_spi(SPI) public struct SomeStruct {}

// SPI: "precise": "s:3SPI10SomeStructV"
// SPI: "spi": true

// NOSPI-NOT: "precise": "s:3SPI10SomeStructV"

// SPI-COMPILE: s:3SPI10SomeStructV
// NOSPI-COMPILE-NOT: s:3SPI10SomeStructV
1 change: 1 addition & 0 deletions tools/SourceKit/lib/SwiftLang/SwiftSourceDocInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,7 @@ fillSymbolInfo(CursorSymbolInfo &Symbol, const DeclInfo &DInfo,
/*EmitSynthesizedMembers*/ false,
/*PrintMessages*/ false,
/*SkipInheritedDocs*/ false,
/*IncludeSPISymbols*/ true,
};

symbolgraphgen::printSymbolGraphForDecl(DInfo.VD, DInfo.BaseType,
Expand Down
1 change: 1 addition & 0 deletions tools/driver/swift_symbolgraph_extract_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ int swift_symbolgraph_extract_main(ArrayRef<const char *> Args,
!ParsedArgs.hasArg(OPT_skip_synthesized_members),
ParsedArgs.hasArg(OPT_v),
ParsedArgs.hasArg(OPT_skip_inherited_docs),
ParsedArgs.hasArg(OPT_include_spi_symbols),
};

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