Skip to content

Commit 4987c3b

Browse files
authored
Merge pull request swiftlang#76122 from hamishknight/platform-2
[AST] Account for non-user modules in `isPrivateStdlibDecl`
2 parents 406b8bd + 1cb0f8f commit 4987c3b

File tree

18 files changed

+96
-64
lines changed

18 files changed

+96
-64
lines changed

include/swift/AST/Decl.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,8 +1303,10 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
13031303

13041304
bool hasUnderscoredNaming() const;
13051305

1306-
bool isPrivateStdlibDecl(bool treatNonBuiltinProtocolsAsPublic = true) const;
1307-
1306+
/// Whether this declaration is from a system module and should be considered
1307+
/// implicitly private.
1308+
bool isPrivateSystemDecl(bool treatNonBuiltinProtocolsAsPublic = true) const;
1309+
13081310
/// Check if this is a declaration defined at the top level of the Swift module
13091311
bool isStdlibDecl() const;
13101312

include/swift/AST/PrintOptions.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -272,12 +272,12 @@ struct PrintOptions {
272272

273273
bool SkipSwiftPrivateClangDecls = false;
274274

275-
/// Whether to skip internal stdlib declarations.
276-
bool SkipPrivateStdlibDecls = false;
275+
/// Whether to skip underscored declarations from system modules.
276+
bool SkipPrivateSystemDecls = false;
277277

278-
/// Whether to skip underscored stdlib protocols.
278+
/// Whether to skip underscored protocols from system modules.
279279
/// Protocols marked with @_show_in_interface are still printed.
280-
bool SkipUnderscoredStdlibProtocols = false;
280+
bool SkipUnderscoredSystemProtocols = false;
281281

282282
/// Whether to skip unsafe C++ class methods that were renamed
283283
/// (e.g. __fooUnsafe). See IsSafeUseOfCxxDecl.
@@ -679,8 +679,8 @@ struct PrintOptions {
679679
result.SkipUnavailable = true;
680680
result.SkipImplicit = true;
681681
result.SkipSwiftPrivateClangDecls = true;
682-
result.SkipPrivateStdlibDecls = true;
683-
result.SkipUnderscoredStdlibProtocols = true;
682+
result.SkipPrivateSystemDecls = true;
683+
result.SkipUnderscoredSystemProtocols = true;
684684
result.SkipUnsafeCXXMethods = true;
685685
result.SkipDeinit = true;
686686
result.EmptyLineBetweenDecls = true;
@@ -788,7 +788,7 @@ struct PrintOptions {
788788
PrintOptions::FunctionRepresentationMode::None;
789789
PO.PrintDocumentationComments = false;
790790
PO.ExcludeAttrList.push_back(DeclAttrKind::Available);
791-
PO.SkipPrivateStdlibDecls = true;
791+
PO.SkipPrivateSystemDecls = true;
792792
PO.SkipUnsafeCXXMethods = true;
793793
PO.ExplodeEnumCaseDecls = true;
794794
PO.ShouldQualifyNestedDeclarations = QualifyNestedDeclarations::TypesOnly;

include/swift/AST/Type.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,9 @@ class Type {
330330
/// subsystem.
331331
Type subst(InFlightSubstitution &subs) const;
332332

333-
bool isPrivateStdlibType(bool treatNonBuiltinProtocolsAsPublic = true) const;
333+
/// Whether this type is from a system module and should be considered
334+
/// implicitly private.
335+
bool isPrivateSystemType(bool treatNonBuiltinProtocolsAsPublic = true) const;
334336

335337
SWIFT_DEBUG_DUMP;
336338
void dump(raw_ostream &os, unsigned indent = 0) const;

include/swift/SymbolGraphGen/SymbolGraphOptions.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ struct SymbolGraphOptions {
6060
/// members and conformances with the extended nominal.
6161
bool EmitExtensionBlockSymbols = false;
6262

63-
/// Whether to print information for private symbols in the standard library.
63+
/// Whether to print information for private symbols in system modules.
6464
/// This should be left as `false` when printing a full-module symbol graph,
6565
/// but SourceKit should be able to load the information when pulling symbol
6666
/// information for individual queries.
67-
bool PrintPrivateStdlibSymbols = false;
67+
bool PrintPrivateSystemSymbols = false;
6868

6969
/// If this has a value specifies an explicit allow list of reexported module
7070
/// names that should be included symbol graph.

lib/APIDigester/ModuleAnalyzerNodes.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1772,7 +1772,7 @@ SDKContext::shouldIgnore(Decl *D, const Decl* Parent) const {
17721772
if (D->getAttrs().hasAttribute<AlwaysEmitIntoClientAttr>())
17731773
return true;
17741774
} else {
1775-
if (D->isPrivateStdlibDecl(false))
1775+
if (D->isPrivateSystemDecl(false))
17761776
return true;
17771777
}
17781778
if (AvailableAttr::isUnavailable(D))

lib/AST/ASTPrinter.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2174,8 +2174,8 @@ bool ShouldPrintChecker::shouldPrint(const Decl *D,
21742174
}
21752175
}
21762176

2177-
if (Options.SkipPrivateStdlibDecls &&
2178-
D->isPrivateStdlibDecl(!Options.SkipUnderscoredStdlibProtocols))
2177+
if (Options.SkipPrivateSystemDecls &&
2178+
D->isPrivateSystemDecl(!Options.SkipUnderscoredSystemProtocols))
21792179
return false;
21802180

21812181
auto &ctx = D->getASTContext();
@@ -3386,7 +3386,7 @@ void PrintAST::visitTypeAliasDecl(TypeAliasDecl *decl) {
33863386
Type Ty = decl->getUnderlyingType();
33873387

33883388
// If the underlying type is private, don't print it.
3389-
if (Options.SkipPrivateStdlibDecls && Ty && Ty.isPrivateStdlibType())
3389+
if (Options.SkipPrivateSystemDecls && Ty && Ty.isPrivateSystemType())
33903390
ShouldPrint = false;
33913391

33923392
if (ShouldPrint) {
@@ -7813,8 +7813,8 @@ swift::getInheritedForPrinting(
78137813
// protocol, see if any of its inherited protocols are public. Those
78147814
// protocols can affect the user-visible behavior of the declaration, and
78157815
// should be printed.
7816-
if (options.SkipPrivateStdlibDecls &&
7817-
proto->isPrivateStdlibDecl(!options.SkipUnderscoredStdlibProtocols)) {
7816+
if (options.SkipPrivateSystemDecls &&
7817+
proto->isPrivateSystemDecl(!options.SkipUnderscoredSystemProtocols)) {
78187818
auto inheritedProtocols = proto->getInheritedProtocols();
78197819
protocols.insert(inheritedProtocols.begin(), inheritedProtocols.end());
78207820
if (isUnchecked)

lib/AST/Decl.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,25 +1133,24 @@ bool Decl::hasUnderscoredNaming() const {
11331133
return false;
11341134
}
11351135

1136-
bool Decl::isPrivateStdlibDecl(bool treatNonBuiltinProtocolsAsPublic) const {
1136+
bool Decl::isPrivateSystemDecl(bool treatNonBuiltinProtocolsAsPublic) const {
11371137
const Decl *D = this;
11381138
if (auto ExtD = dyn_cast<ExtensionDecl>(D)) {
11391139
Type extTy = ExtD->getExtendedType();
1140-
return extTy.isPrivateStdlibType(treatNonBuiltinProtocolsAsPublic);
1140+
return extTy.isPrivateSystemType(treatNonBuiltinProtocolsAsPublic);
11411141
}
11421142

11431143
DeclContext *DC = D->getDeclContext()->getModuleScopeContext();
1144-
if (DC->getParentModule()->isBuiltinModule() ||
1145-
DC->getParentModule()->isSwiftShimsModule())
1144+
auto *M = DC->getParentModule();
1145+
if (M->isBuiltinModule() || M->isSwiftShimsModule())
11461146
return true;
1147-
if (!DC->getParentModule()->isSystemModule())
1147+
if (!M->isSystemModule() && !M->isNonUserModule())
11481148
return false;
11491149
auto FU = dyn_cast<FileUnit>(DC);
11501150
if (!FU)
11511151
return false;
1152-
// Check for Swift module and overlays.
1153-
if (!DC->getParentModule()->isStdlibModule() &&
1154-
FU->getKind() != FileUnitKind::SerializedAST)
1152+
// Check for stdlib and imported Swift modules.
1153+
if (!M->isStdlibModule() && FU->getKind() != FileUnitKind::SerializedAST)
11551154
return false;
11561155

11571156
if (isa<ProtocolDecl>(D)) {
@@ -4236,7 +4235,7 @@ bool ValueDecl::isInterfacePackageEffectivelyPublic() const {
42364235

42374236
bool ValueDecl::shouldHideFromEditor() const {
42384237
// Hide private stdlib declarations.
4239-
if (isPrivateStdlibDecl(/*treatNonBuiltinProtocolsAsPublic*/ false) ||
4238+
if (isPrivateSystemDecl(/*treatNonBuiltinProtocolsAsPublic*/ false) ||
42404239
// ShowInInterfaceAttr is for decls to show in interface as exception but
42414240
// they are not intended to be used directly.
42424241
getAttrs().hasAttribute<ShowInInterfaceAttr>())

lib/AST/Type.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4174,40 +4174,40 @@ TypeTraitResult TypeBase::canBeClass() {
41744174
return TypeTraitResult::IsNot;
41754175
}
41764176

4177-
bool Type::isPrivateStdlibType(bool treatNonBuiltinProtocolsAsPublic) const {
4177+
bool Type::isPrivateSystemType(bool treatNonBuiltinProtocolsAsPublic) const {
41784178
Type Ty = *this;
41794179
if (!Ty)
41804180
return false;
41814181

41824182
if (auto existential = dyn_cast<ExistentialType>(Ty.getPointer()))
4183-
return existential->getConstraintType()
4184-
.isPrivateStdlibType(treatNonBuiltinProtocolsAsPublic);
4183+
return existential->getConstraintType().isPrivateSystemType(
4184+
treatNonBuiltinProtocolsAsPublic);
41854185

41864186
// A 'public' typealias can have an 'internal' type.
41874187
if (auto *NAT = dyn_cast<TypeAliasType>(Ty.getPointer())) {
41884188
auto *AliasDecl = NAT->getDecl();
41894189
if (auto parent = NAT->getParent()) {
4190-
if (parent.isPrivateStdlibType(treatNonBuiltinProtocolsAsPublic))
4190+
if (parent.isPrivateSystemType(treatNonBuiltinProtocolsAsPublic))
41914191
return true;
41924192
}
41934193

4194-
if (AliasDecl->isPrivateStdlibDecl(treatNonBuiltinProtocolsAsPublic))
4194+
if (AliasDecl->isPrivateSystemDecl(treatNonBuiltinProtocolsAsPublic))
41954195
return true;
41964196

4197-
return Type(NAT->getSinglyDesugaredType()).isPrivateStdlibType(
4198-
treatNonBuiltinProtocolsAsPublic);
4197+
return Type(NAT->getSinglyDesugaredType())
4198+
.isPrivateSystemType(treatNonBuiltinProtocolsAsPublic);
41994199
}
42004200

42014201
if (auto Paren = dyn_cast<ParenType>(Ty.getPointer())) {
42024202
Type Underlying = Paren->getUnderlyingType();
4203-
return Underlying.isPrivateStdlibType(treatNonBuiltinProtocolsAsPublic);
4203+
return Underlying.isPrivateSystemType(treatNonBuiltinProtocolsAsPublic);
42044204
}
42054205

42064206
if (Type Unwrapped = Ty->getOptionalObjectType())
4207-
return Unwrapped.isPrivateStdlibType(treatNonBuiltinProtocolsAsPublic);
4207+
return Unwrapped.isPrivateSystemType(treatNonBuiltinProtocolsAsPublic);
42084208

42094209
if (auto TyD = Ty->getAnyNominal())
4210-
if (TyD->isPrivateStdlibDecl(treatNonBuiltinProtocolsAsPublic))
4210+
if (TyD->isPrivateSystemDecl(treatNonBuiltinProtocolsAsPublic))
42114211
return true;
42124212

42134213
return false;

lib/FrontendTool/FrontendTool.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@ static void dumpAPIIfNeeded(const CompilerInstance &Instance) {
916916
PO.PrintOriginalSourceText = true;
917917
PO.Indent = 2;
918918
PO.PrintAccess = false;
919-
PO.SkipUnderscoredStdlibProtocols = true;
919+
PO.SkipUnderscoredSystemProtocols = true;
920920
SF->print(TempOS, PO);
921921
if (TempOS.str().trim().empty())
922922
return false; // nothing to show.

lib/IDE/CommentConversion.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ visitDocComment(const DocComment *DC, TypeOrExtensionDecl SynthesizedTarget) {
381381
PO.VarInitializers = false;
382382
PO.ShouldQualifyNestedDeclarations =
383383
PrintOptions::QualifyNestedDeclarations::TypesOnly;
384-
PO.SkipUnderscoredStdlibProtocols = false;
384+
PO.SkipUnderscoredSystemProtocols = false;
385385
if (SynthesizedTarget)
386386
PO.initForSynthesizedExtension(SynthesizedTarget);
387387

0 commit comments

Comments
 (0)