Skip to content

Commit 85fabb2

Browse files
include comments on SPI symbols when they're in symbol graphs
1 parent 8822ccc commit 85fabb2

File tree

11 files changed

+63
-9
lines changed

11 files changed

+63
-9
lines changed

include/swift/AST/ASTContext.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "swift/Basic/LangOptions.h"
2929
#include "swift/Basic/Located.h"
3030
#include "swift/Basic/Malloc.h"
31+
#include "swift/SymbolGraphGen/SymbolGraphOptions.h"
3132
#include "clang/AST/DeclTemplate.h"
3233
#include "llvm/ADT/ArrayRef.h"
3334
#include "llvm/ADT/DenseMap.h"
@@ -231,6 +232,7 @@ class ASTContext final {
231232
ASTContext(LangOptions &langOpts, TypeCheckerOptions &typeckOpts,
232233
SearchPathOptions &SearchPathOpts,
233234
ClangImporterOptions &ClangImporterOpts,
235+
symbolgraphgen::SymbolGraphOptions &SymbolGraphOpts,
234236
SourceManager &SourceMgr,
235237
DiagnosticEngine &Diags);
236238

@@ -246,6 +248,7 @@ class ASTContext final {
246248
static ASTContext *get(LangOptions &langOpts, TypeCheckerOptions &typeckOpts,
247249
SearchPathOptions &SearchPathOpts,
248250
ClangImporterOptions &ClangImporterOpts,
251+
symbolgraphgen::SymbolGraphOptions &SymbolGraphOpts,
249252
SourceManager &SourceMgr, DiagnosticEngine &Diags);
250253
~ASTContext();
251254

@@ -267,6 +270,9 @@ class ASTContext final {
267270
/// The clang importer options used by this AST context.
268271
ClangImporterOptions &ClangImporterOpts;
269272

273+
/// The symbol graph generation options used by this AST context.
274+
symbolgraphgen::SymbolGraphOptions &SymbolGraphOpts;
275+
270276
/// The source manager object.
271277
SourceManager &SourceMgr;
272278

include/swift/Frontend/Frontend.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include "swift/Serialization/Validation.h"
4242
#include "swift/Subsystems.h"
4343
#include "swift/TBDGen/TBDGen.h"
44+
#include "swift/SymbolGraphGen/SymbolGraphOptions.h"
4445
#include "llvm/ADT/IntrusiveRefCntPtr.h"
4546
#include "llvm/ADT/SetVector.h"
4647
#include "llvm/Option/ArgList.h"
@@ -86,6 +87,7 @@ class CompilerInvocation {
8687
TypeCheckerOptions TypeCheckerOpts;
8788
FrontendOptions FrontendOpts;
8889
ClangImporterOptions ClangImporterOpts;
90+
symbolgraphgen::SymbolGraphOptions SymbolGraphOpts;
8991
SearchPathOptions SearchPathOpts;
9092
DiagnosticOptions DiagnosticOpts;
9193
MigratorOptions MigratorOpts;
@@ -257,6 +259,11 @@ class CompilerInvocation {
257259
return ClangImporterOpts;
258260
}
259261

262+
symbolgraphgen::SymbolGraphOptions &getSymbolGraphOptions() { return SymbolGraphOpts; }
263+
const symbolgraphgen::SymbolGraphOptions &getSymbolGraphOptions() const {
264+
return SymbolGraphOpts;
265+
}
266+
260267
SearchPathOptions &getSearchPathOptions() { return SearchPathOpts; }
261268
const SearchPathOptions &getSearchPathOptions() const {
262269
return SearchPathOpts;

lib/AST/ASTContext.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
#include "swift/Basic/StringExtras.h"
5454
#include "swift/Strings.h"
5555
#include "swift/Subsystems.h"
56+
#include "swift/SymbolGraphGen/SymbolGraphOptions.h"
5657
#include "swift/Syntax/References.h"
5758
#include "swift/Syntax/SyntaxArena.h"
5859
#include "clang/AST/Type.h"
@@ -579,6 +580,7 @@ ASTContext *ASTContext::get(LangOptions &langOpts,
579580
TypeCheckerOptions &typeckOpts,
580581
SearchPathOptions &SearchPathOpts,
581582
ClangImporterOptions &ClangImporterOpts,
583+
symbolgraphgen::SymbolGraphOptions &SymbolGraphOpts,
582584
SourceManager &SourceMgr,
583585
DiagnosticEngine &Diags) {
584586
// If more than two data structures are concatentated, then the aggregate
@@ -593,17 +595,19 @@ ASTContext *ASTContext::get(LangOptions &langOpts,
593595
new (impl) Implementation();
594596
return new (mem)
595597
ASTContext(langOpts, typeckOpts, SearchPathOpts, ClangImporterOpts,
596-
SourceMgr, Diags);
598+
SymbolGraphOpts, SourceMgr, Diags);
597599
}
598600

599601
ASTContext::ASTContext(LangOptions &langOpts, TypeCheckerOptions &typeckOpts,
600602
SearchPathOptions &SearchPathOpts,
601603
ClangImporterOptions &ClangImporterOpts,
604+
symbolgraphgen::SymbolGraphOptions &SymbolGraphOpts,
602605
SourceManager &SourceMgr, DiagnosticEngine &Diags)
603606
: LangOpts(langOpts),
604607
TypeCheckerOpts(typeckOpts),
605608
SearchPathOpts(SearchPathOpts),
606609
ClangImporterOpts(ClangImporterOpts),
610+
SymbolGraphOpts(SymbolGraphOpts),
607611
SourceMgr(SourceMgr), Diags(Diags),
608612
evaluator(Diags, langOpts),
609613
TheBuiltinModule(createBuiltinModule(*this)),

lib/Driver/ToolChains.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,8 +585,8 @@ ToolChain::constructInvocation(const CompileJobAction &job,
585585
if (context.OI.CompilerMode == OutputInfo::Mode::SingleCompile) {
586586
context.Args.AddLastArg(Arguments, options::OPT_emit_symbol_graph);
587587
context.Args.AddLastArg(Arguments, options::OPT_emit_symbol_graph_dir);
588-
context.Args.AddLastArg(Arguments, options::OPT_include_spi_symbols);
589588
}
589+
context.Args.AddLastArg(Arguments, options::OPT_include_spi_symbols);
590590

591591
return II;
592592
}

lib/Frontend/CompilerInvocation.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "swift/Option/Options.h"
1919
#include "swift/Option/SanitizerOptions.h"
2020
#include "swift/Strings.h"
21+
#include "swift/SymbolGraphGen/SymbolGraphOptions.h"
2122
#include "llvm/ADT/STLExtras.h"
2223
#include "llvm/ADT/Triple.h"
2324
#include "llvm/Option/Arg.h"
@@ -1019,6 +1020,28 @@ static bool ParseClangImporterArgs(ClangImporterOptions &Opts,
10191020
return false;
10201021
}
10211022

1023+
static void ParseSymbolGraphArgs(symbolgraphgen::SymbolGraphOptions &Opts,
1024+
ArgList &Args,
1025+
DiagnosticEngine &Diags,
1026+
LangOptions &LangOpts) {
1027+
using namespace options;
1028+
1029+
if (const Arg *A = Args.getLastArg(OPT_emit_symbol_graph_dir)) {
1030+
Opts.OutputDir = A->getValue();
1031+
}
1032+
1033+
Opts.Target = LangOpts.Target;
1034+
1035+
Opts.SkipInheritedDocs = Args.hasArg(OPT_skip_inherited_docs);
1036+
Opts.IncludeSPISymbols = Args.hasArg(OPT_include_spi_symbols);
1037+
1038+
// default values for generating symbol graphs during a build
1039+
Opts.MinimumAccessLevel = AccessLevel::Public;
1040+
Opts.PrettyPrint = false;
1041+
Opts.EmitSynthesizedMembers = true;
1042+
Opts.PrintMessages = false;
1043+
}
1044+
10221045
static bool ParseSearchPathArgs(SearchPathOptions &Opts,
10231046
ArgList &Args,
10241047
DiagnosticEngine &Diags,
@@ -1973,6 +1996,8 @@ bool CompilerInvocation::parseArgs(
19731996
return true;
19741997
}
19751998

1999+
ParseSymbolGraphArgs(SymbolGraphOpts, ParsedArgs, Diags, LangOpts);
2000+
19762001
if (ParseSearchPathArgs(SearchPathOpts, ParsedArgs, Diags,
19772002
workingDirectory)) {
19782003
return true;

lib/Frontend/Frontend.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ bool CompilerInstance::setUpASTContextIfNeeded() {
223223
Invocation.getLangOptions(), Invocation.getTypeCheckerOptions(),
224224
Invocation.getSearchPathOptions(),
225225
Invocation.getClangImporterOptions(),
226+
Invocation.getSymbolGraphOptions(),
226227
SourceMgr, Diagnostics));
227228
registerParseRequestFunctions(Context->evaluator);
228229
registerTypeCheckerRequestFunctions(Context->evaluator);

lib/IDE/CompletionInstance.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "swift/Parse/PersistentParserState.h"
3030
#include "swift/Serialization/SerializedModuleLoader.h"
3131
#include "swift/Subsystems.h"
32+
#include "swift/SymbolGraphGen/SymbolGraphOptions.h"
3233
#include "clang/AST/ASTContext.h"
3334
#include "llvm/ADT/Hashing.h"
3435
#include "llvm/Support/MemoryBuffer.h"
@@ -330,9 +331,10 @@ bool CompletionInstance::performCachedOperationIfPossible(
330331
SearchPathOptions searchPathOpts = CI.getASTContext().SearchPathOpts;
331332
DiagnosticEngine tmpDiags(tmpSM);
332333
ClangImporterOptions clangOpts;
334+
symbolgraphgen::SymbolGraphOptions symbolOpts;
333335
std::unique_ptr<ASTContext> tmpCtx(
334-
ASTContext::get(langOpts, typeckOpts, searchPathOpts, clangOpts, tmpSM,
335-
tmpDiags));
336+
ASTContext::get(langOpts, typeckOpts, searchPathOpts, clangOpts,
337+
symbolOpts, tmpSM, tmpDiags));
336338
registerParseRequestFunctions(tmpCtx->evaluator);
337339
registerIDERequestFunctions(tmpCtx->evaluator);
338340
registerTypeCheckerRequestFunctions(tmpCtx->evaluator);

lib/Parse/Parser.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "swift/Parse/ParseSILSupport.h"
3030
#include "swift/Parse/SyntaxParseActions.h"
3131
#include "swift/Parse/SyntaxParsingContext.h"
32+
#include "swift/SymbolGraphGen/SymbolGraphOptions.h"
3233
#include "swift/Syntax/RawSyntax.h"
3334
#include "swift/Syntax/TokenSyntax.h"
3435
#include "swift/SyntaxParse/SyntaxTreeCreator.h"
@@ -1219,6 +1220,7 @@ struct ParserUnit::Implementation {
12191220
TypeCheckerOptions TypeCheckerOpts;
12201221
SearchPathOptions SearchPathOpts;
12211222
ClangImporterOptions clangImporterOpts;
1223+
symbolgraphgen::SymbolGraphOptions symbolGraphOpts;
12221224
DiagnosticEngine Diags;
12231225
ASTContext &Ctx;
12241226
SourceFile *SF;
@@ -1231,7 +1233,7 @@ struct ParserUnit::Implementation {
12311233
: SPActions(std::move(spActions)), LangOpts(Opts),
12321234
TypeCheckerOpts(TyOpts), Diags(SM),
12331235
Ctx(*ASTContext::get(LangOpts, TypeCheckerOpts, SearchPathOpts,
1234-
clangImporterOpts, SM, Diags)) {
1236+
clangImporterOpts, symbolGraphOpts, SM, Diags)) {
12351237
auto parsingOpts = SourceFile::getDefaultParsingOptions(LangOpts);
12361238
parsingOpts |= ParsingFlags::DisableDelayedBodies;
12371239
parsingOpts |= ParsingFlags::DisablePoundIfEvaluation;

lib/Serialization/SerializeDoc.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,8 @@ static bool shouldIncludeDecl(Decl *D, bool ExcludeDoubleUnderscore) {
341341
return false;
342342
}
343343

344-
// Skip SPI decls.
345-
if (D->isSPI())
344+
// Skip SPI decls, unless we're generating a symbol graph with SPI information.
345+
if (D->isSPI() && !D->getASTContext().SymbolGraphOpts.IncludeSPISymbols)
346346
return false;
347347

348348
if (auto *ED = dyn_cast<ExtensionDecl>(D)) {

test/SymbolGraph/Symbols/Mixins/SPI.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %target-build-swift %s -module-name SPI -emit-module -emit-module-path %t/
2+
// RUN: %target-build-swift %s -module-name SPI -emit-module -emit-module-path %t/SPI.swiftmodule -include-spi-symbols
33
// RUN: %target-swift-symbolgraph-extract -module-name SPI -I %t -pretty-print -output-dir %t -include-spi-symbols
44
// RUN: %FileCheck %s --input-file %t/SPI.symbols.json --check-prefix SPI
5+
// RUN: %FileCheck %s --input-file %t/SPI.symbols.json --check-prefix SPIDOC
56

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

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

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

19+
/// This is some struct, there
1720
@_spi(SPI) public struct SomeStruct {}
1821

1922
// SPI: "precise": "s:3SPI10SomeStructV"
@@ -23,3 +26,5 @@
2326

2427
// SPI-COMPILE: s:3SPI10SomeStructV
2528
// NOSPI-COMPILE-NOT: s:3SPI10SomeStructV
29+
30+
// SPIDOC: This is some struct, there

tools/driver/modulewrap_main.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "swift/SIL/SILModule.h"
2727
#include "swift/SIL/TypeLowering.h"
2828
#include "swift/Subsystems.h"
29+
#include "swift/SymbolGraphGen/SymbolGraphOptions.h"
2930
#include "llvm/ADT/ArrayRef.h"
3031
#include "llvm/Bitstream/BitstreamReader.h"
3132
#include "llvm/Option/ArgList.h"
@@ -177,9 +178,10 @@ int modulewrap_main(ArrayRef<const char *> Args, const char *Argv0,
177178
TypeCheckerOptions TypeCheckOpts;
178179
LangOptions LangOpts;
179180
ClangImporterOptions ClangImporterOpts;
181+
symbolgraphgen::SymbolGraphOptions SymbolGraphOpts;
180182
LangOpts.Target = Invocation.getTargetTriple();
181183
ASTContext &ASTCtx = *ASTContext::get(LangOpts, TypeCheckOpts, SearchPathOpts,
182-
ClangImporterOpts, SrcMgr,
184+
ClangImporterOpts, SymbolGraphOpts, SrcMgr,
183185
Instance.getDiags());
184186
registerParseRequestFunctions(ASTCtx.evaluator);
185187
registerTypeCheckerRequestFunctions(ASTCtx.evaluator);

0 commit comments

Comments
 (0)