Skip to content

Commit b3c3662

Browse files
committed
[ModuleInterface] Don't print SPI attributes on unsupported decls
When emitting the private swiftinterface, the compiler prints the attribute explicitly even when it is deduced from the context. This can lead to unparsable private swiftinterface files. As a narrow fix, check if the decl type is supported before printing the attribute. rdar://64039069
1 parent 8dd08e7 commit b3c3662

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,9 @@ void PrintAST::printAttributes(const Decl *D) {
991991
}
992992

993993
// SPI groups
994-
if (Options.PrintSPIs) {
994+
if (Options.PrintSPIs &&
995+
DeclAttribute::canAttributeAppearOnDeclKind(
996+
DAK_SPIAccessControl, D->getKind())) {
995997
interleave(D->getSPIGroups(),
996998
[&](Identifier spiName) {
997999
Printer.printAttrName("_spi", true);

test/SPI/private_swiftinterface.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,20 @@ private class PrivateClassLocal {}
8888
// CHECK-PUBLIC-NOT: extensionSPIMethod
8989
}
9090

91+
@_spi(LocalSPI) public protocol SPIProto3 {
92+
// CHECK-PRIVATE: @_spi(LocalSPI) public protocol SPIProto3
93+
// CHECK-PUBLIC-NOT: SPIProto3
94+
95+
associatedtype AssociatedType
96+
// CHECK-PRIVATE: associatedtype AssociatedType
97+
// CHECK-PRIVATE-NOT: @_spi(LocalSPI) associatedtype AssociatedType
98+
// CHECK-PUBLIC-NOT: AssociatedType
99+
100+
func implicitSPIMethod()
101+
// CHECK-PRIVATE: @_spi(LocalSPI) func implicitSPIMethod()
102+
// CHECK-PUBLIC-NOT: implicitSPIMethod
103+
}
104+
91105
// Test the dummy conformance printed to replace private types used in
92106
// conditional conformances. rdar://problem/63352700
93107

0 commit comments

Comments
 (0)