Skip to content

Commit 0cc6ce9

Browse files
Merge pull request #38070 from apple/QuietMisdreavus/spi-comments
include comments on SPI symbols when they're in symbol graphs
2 parents 753474e + ff766fc commit 0cc6ce9

File tree

17 files changed

+77
-13
lines changed

17 files changed

+77
-13
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"
@@ -1020,6 +1021,28 @@ static bool ParseClangImporterArgs(ClangImporterOptions &Opts,
10201021
return false;
10211022
}
10221023

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

2010+
ParseSymbolGraphArgs(SymbolGraphOpts, ParsedArgs, Diags, LangOpts);
2011+
19872012
if (ParseSearchPathArgs(SearchPathOpts, ParsedArgs, Diags,
19882013
workingDirectory)) {
19892014
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);

unittests/AST/TestContext.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ static Decl *createOptionalType(ASTContext &ctx, SourceFile *fileForLookups,
3636

3737
TestContext::TestContext(ShouldDeclareOptionalTypes optionals)
3838
: Ctx(*ASTContext::get(LangOpts, TypeCheckerOpts, SearchPathOpts,
39-
ClangImporterOpts, SourceMgr, Diags)) {
39+
ClangImporterOpts, SymbolGraphOpts,
40+
SourceMgr, Diags)) {
4041
registerParseRequestFunctions(Ctx.evaluator);
4142
registerTypeCheckerRequestFunctions(Ctx.evaluator);
4243
auto stdlibID = Ctx.getIdentifier(STDLIB_NAME);

unittests/AST/TestContext.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "swift/AST/SourceFile.h"
1717
#include "swift/Basic/LangOptions.h"
1818
#include "swift/Basic/SourceManager.h"
19+
#include "swift/SymbolGraphGen/SymbolGraphOptions.h"
1920

2021
#include "llvm/Support/Host.h"
2122

@@ -32,6 +33,7 @@ class TestContextBase {
3233
TypeCheckerOptions TypeCheckerOpts;
3334
SearchPathOptions SearchPathOpts;
3435
ClangImporterOptions ClangImporterOpts;
36+
symbolgraphgen::SymbolGraphOptions SymbolGraphOpts;
3537
SourceManager SourceMgr;
3638
DiagnosticEngine Diags;
3739

unittests/ClangImporter/ClangImporterTests.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "swift/Basic/LangOptions.h"
77
#include "swift/Basic/SourceManager.h"
88
#include "swift/ClangImporter/ClangImporter.h"
9+
#include "swift/SymbolGraphGen/SymbolGraphOptions.h"
910
#include "llvm/Support/FileSystem.h"
1011
#include "llvm/Support/Path.h"
1112
#include "llvm/Support/raw_ostream.h"
@@ -72,11 +73,12 @@ TEST(ClangImporterTest, emitPCHInMemory) {
7273
swift::TypeCheckerOptions typeckOpts;
7374
INITIALIZE_LLVM();
7475
swift::SearchPathOptions searchPathOpts;
76+
swift::symbolgraphgen::SymbolGraphOptions symbolGraphOpts;
7577
swift::SourceManager sourceMgr;
7678
swift::DiagnosticEngine diags(sourceMgr);
7779
std::unique_ptr<ASTContext> context(
7880
ASTContext::get(langOpts, typeckOpts, searchPathOpts, options,
79-
sourceMgr, diags));
81+
symbolGraphOpts, sourceMgr, diags));
8082
auto importer = ClangImporter::create(*context);
8183

8284
std::string PCH = createFilename(cache, "bridging.h.pch");

unittests/FrontendTool/ModuleLoadingTests.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "swift/Frontend/ModuleInterfaceLoader.h"
1818
#include "swift/Frontend/PrintingDiagnosticConsumer.h"
1919
#include "swift/Serialization/Validation.h"
20+
#include "swift/SymbolGraphGen/SymbolGraphOptions.h"
2021
#include "llvm/ADT/SmallString.h"
2122
#include "llvm/Support/VirtualFileSystem.h"
2223

@@ -100,10 +101,11 @@ class ModuleInterfaceLoaderTest : public testing::Test {
100101
langOpts.Target = llvm::Triple(llvm::sys::getDefaultTargetTriple());
101102
SearchPathOptions searchPathOpts;
102103
ClangImporterOptions clangImpOpts;
104+
symbolgraphgen::SymbolGraphOptions symbolGraphOpts;
103105
SILOptions silOpts;
104106
auto ctx =
105107
ASTContext::get(langOpts, typeckOpts, searchPathOpts, clangImpOpts,
106-
sourceMgr, diags);
108+
symbolGraphOpts, sourceMgr, diags);
107109

108110
ctx->addModuleInterfaceChecker(
109111
std::make_unique<ModuleInterfaceCheckerImpl>(*ctx, cacheDir,

unittests/Sema/SemaFixture.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ using namespace swift::constraints::inference;
3030

3131
SemaTest::SemaTest()
3232
: Context(*ASTContext::get(LangOpts, TypeCheckerOpts, SearchPathOpts,
33-
ClangImporterOpts, SourceMgr, Diags)) {
33+
ClangImporterOpts, SymbolGraphOpts,
34+
SourceMgr, Diags)) {
3435
INITIALIZE_LLVM();
3536

3637
registerParseRequestFunctions(Context.evaluator);

unittests/Sema/SemaFixture.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "swift/Basic/Platform.h"
2121
#include "swift/Basic/SourceManager.h"
2222
#include "swift/Sema/ConstraintSystem.h"
23+
#include "swift/SymbolGraphGen/SymbolGraphOptions.h"
2324
#include "llvm/ADT/SmallString.h"
2425
#include "llvm/ADT/StringRef.h"
2526
#include "llvm/Support/Host.h"
@@ -39,6 +40,7 @@ class SemaTestBase : public ::testing::Test {
3940
TypeCheckerOptions TypeCheckerOpts;
4041
SearchPathOptions SearchPathOpts;
4142
ClangImporterOptions ClangImporterOpts;
43+
symbolgraphgen::SymbolGraphOptions SymbolGraphOpts;
4244
SourceManager SourceMgr;
4345
DiagnosticEngine Diags;
4446

0 commit comments

Comments
 (0)