Skip to content

Commit 20123e0

Browse files
committed
Allow for emission of swift.extension symbols for extensions to external types in swiftSymbolGraphGen
This includes: - bumping the SWIFT_SYMBOLGRAPH_FORMAT_MINOR version - introduction of the "swift.extension" symbol and "extensionTo" relationship - adding support for ExtensionDecl to the Symbol class - adding a "typeKind" field to the symbol's extension mixin which indicates what kind of symbol was extended - intoduction of the -emit-extension-block-symbols flag, which enables the behavior outlined below - adaptions to SymbolGraphASTWalker that ensure a swift.extension symbol is emitted for each extension to a type that does not exist in the local symbol graph - adaptions to SymbolGraph and SymbolGraphASTWalker that ensure member and conformance relationships are correctly associated with the swift.extension symbol instead of the original type declaration's (extended nominal's) symbol where applicable - adaptions to SymbolGraphASTWalker that ensure swift.extension symbols are connected to their respective extended nominal's symbol using an extensionTo relationship Testing: - adds SymbolGraph tests that test behavior only relevant in -emit-extension-block-symbols mode - adapts some SymbolGraph tests to additionally test similar behavior for extensions to external types in -emit-extension-block-symbols mode - adapts some SymbolGraph tests to (additionally or exclusively) test the behavior with -emit-extension-block-symbols mode enabled Bugfixes: - fixes a bug where some conformsTo relationships implicated by the conformances declared on an extension to an external type were not emitted (see test/SymbolGraph/Relationships/ConformsTo/Indirect.swift) Further changes: - documents the strategy for naming and associating children declared in extensions to typealiases (see test/SymbolGraph/Relationships/MemberOf/Typealias.swift, test/SymbolGraph/Symbols/Names.swift)
1 parent 2242a3e commit 20123e0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+914
-264
lines changed

include/swift/Option/Options.td

+5
Original file line numberDiff line numberDiff line change
@@ -1351,6 +1351,11 @@ def pretty_print: Flag<["-"], "pretty-print">,
13511351
Flags<[SwiftAPIExtractOption, SwiftSymbolGraphExtractOption]>,
13521352
HelpText<"Pretty-print the output JSON">;
13531353

1354+
def emit_extension_block_symbols: Flag<["-"], "emit-extension-block-symbols">,
1355+
Flags<[SwiftSymbolGraphExtractOption, FrontendOption,
1356+
NoInteractiveOption, SupplementaryOutput, HelpHidden]>,
1357+
HelpText<"Emit 'swift.extension' symbols for extensions to external types instead of directly associating members and conformances with the extended nominal when generating symbol graphs">;
1358+
13541359
// swift-symbolgraph-extract-only options
13551360
def output_dir : Separate<["-"], "output-dir">,
13561361
Flags<[NoDriverOption, SwiftSymbolGraphExtractOption, SwiftAPIDigesterOption,

include/swift/SymbolGraphGen/SymbolGraphOptions.h

+5
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ struct SymbolGraphOptions {
4848

4949
/// Whether to include documentation for clang nodes or not.
5050
bool IncludeClangDocs = false;
51+
52+
/// Whether to emit "swift.extension" symbols for extensions to external types
53+
/// along with "extensionTo" relationships instead of directly associating
54+
/// members and conformances with the extended nominal.
55+
bool EmitExtensionBlockSymbols = false;
5156
};
5257

5358
} // end namespace symbolgraphgen

lib/Driver/ToolChains.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,7 @@ ToolChain::constructInvocation(const CompileJobAction &job,
616616
context.Args.AddLastArg(Arguments, options::OPT_emit_symbol_graph_dir);
617617
}
618618
context.Args.AddLastArg(Arguments, options::OPT_include_spi_symbols);
619+
context.Args.AddLastArg(Arguments, options::OPT_emit_extension_block_symbols);
619620
context.Args.AddLastArg(Arguments, options::OPT_symbol_graph_minimum_access_level);
620621

621622
return II;
@@ -1112,6 +1113,7 @@ ToolChain::constructInvocation(const MergeModuleJobAction &job,
11121113
context.Args.AddLastArg(Arguments, options::OPT_emit_symbol_graph);
11131114
context.Args.AddLastArg(Arguments, options::OPT_emit_symbol_graph_dir);
11141115
context.Args.AddLastArg(Arguments, options::OPT_include_spi_symbols);
1116+
context.Args.AddLastArg(Arguments, options::OPT_emit_extension_block_symbols);
11151117
context.Args.AddLastArg(Arguments, options::OPT_symbol_graph_minimum_access_level);
11161118

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

lib/DriverTool/swift_symbolgraph_extract_main.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ int swift_symbolgraph_extract_main(ArrayRef<const char *> Args,
172172
ParsedArgs.hasArg(OPT_skip_inherited_docs),
173173
ParsedArgs.hasArg(OPT_include_spi_symbols),
174174
/*IncludeClangDocs=*/false,
175+
ParsedArgs.hasArg(OPT_emit_extension_block_symbols),
175176
};
176177

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

lib/Frontend/CompilerInvocation.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -1284,6 +1284,8 @@ static void ParseSymbolGraphArgs(symbolgraphgen::SymbolGraphOptions &Opts,
12841284

12851285
Opts.SkipInheritedDocs = Args.hasArg(OPT_skip_inherited_docs);
12861286
Opts.IncludeSPISymbols = Args.hasArg(OPT_include_spi_symbols);
1287+
Opts.EmitExtensionBlockSymbols =
1288+
Args.hasArg(OPT_emit_extension_block_symbols);
12871289

12881290
if (auto *A = Args.getLastArg(OPT_symbol_graph_minimum_access_level)) {
12891291
Opts.MinimumAccessLevel =

lib/SymbolGraphGen/Edge.h

+14-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,20 @@ struct RelationshipKind {
104104
static inline RelationshipKind OptionalRequirementOf() {
105105
return RelationshipKind { "optionalRequirementOf" };
106106
}
107-
107+
108+
/**
109+
A symbol A extends a symbol B with members or conformances.
110+
111+
This relationship describes the connection between extension blocks
112+
(swift.extension symbols) and the type they extend.
113+
114+
The implied inverse of this relationship is a symbol B that is extended
115+
by an extension block symbol A.
116+
*/
117+
static inline RelationshipKind ExtensionTo() {
118+
return RelationshipKind{"extensionTo"};
119+
}
120+
108121
bool operator==(const RelationshipKind &Other) const {
109122
return Name == Other.Name;
110123
}

lib/SymbolGraphGen/FormatVersion.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#define SWIFT_SYMBOLGRAPHGEN_FORMATVERSION_H
1515

1616
#define SWIFT_SYMBOLGRAPH_FORMAT_MAJOR 0
17-
#define SWIFT_SYMBOLGRAPH_FORMAT_MINOR 5
18-
#define SWIFT_SYMBOLGRAPH_FORMAT_PATCH 3
17+
#define SWIFT_SYMBOLGRAPH_FORMAT_MINOR 6
18+
#define SWIFT_SYMBOLGRAPH_FORMAT_PATCH 0
1919

2020
#endif // SWIFT_SYMBOLGRAPHGEN_FORMATVERSION_H

lib/SymbolGraphGen/JSON.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
// Adds Symbol Graph JSON serialization to other types.
1313
//===----------------------------------------------------------------------===//
1414

15+
#include "JSON.h"
16+
#include "Symbol.h"
1517
#include "swift/AST/ASTContext.h"
1618
#include "swift/AST/Decl.h"
1719
#include "swift/AST/FileUnit.h"
@@ -21,7 +23,6 @@
2123
#include "swift/AST/USRGeneration.h"
2224
#include "swift/ClangImporter/ClangModule.h"
2325
#include "swift/Serialization/SerializedModuleLoader.h"
24-
#include "JSON.h"
2526

2627
void swift::symbolgraphgen::serialize(const llvm::VersionTuple &VT,
2728
llvm::json::OStream &OS) {
@@ -69,6 +70,8 @@ void swift::symbolgraphgen::serialize(const ExtensionDecl *Extension,
6970
if (const auto *ExtendedModule = ExtendedNominal->getModuleContext()) {
7071
OS.attribute("extendedModule", ExtendedModule->getNameStr());
7172
}
73+
74+
OS.attribute("typeKind", Symbol::getKind(ExtendedNominal).first);
7275
}
7376

7477
SmallVector<Requirement, 4> FilteredRequirements;

0 commit comments

Comments
 (0)