Skip to content

Commit a01d427

Browse files
committed
ModuleInterface: Avoid printing @_spi enum case decls in public swiftinterfaces.
rdar://72873771
1 parent e1102cc commit a01d427

File tree

2 files changed

+43
-8
lines changed

2 files changed

+43
-8
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,21 @@ PrintOptions PrintOptions::printSwiftInterfaceFile(ModuleDecl *ModuleToPrint,
276276
return false;
277277
}
278278

279+
// Skip enum cases containing enum elements we wouldn't print.
280+
if (auto *ECD = dyn_cast<EnumCaseDecl>(D)) {
281+
auto elements = ECD->getElements();
282+
if (!elements.empty()) {
283+
// Enum elements are usually not printed, so we have to override the
284+
// print option controlling that. We only check the first element
285+
// because all the elements in a single case decl should have the same
286+
// characteristics.
287+
PrintOptions optionsCopy = options;
288+
optionsCopy.ExplodeEnumCaseDecls = true;
289+
if (!shouldPrint(elements[0], optionsCopy))
290+
return false;
291+
}
292+
}
293+
279294
return ShouldPrintChecker::shouldPrint(D, options);
280295
}
281296
};

test/SPI/private_swiftinterface.swift

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,6 @@
3434
// RUN: %target-swift-frontend -typecheck-module-from-interface -I %t %t/Main.swiftinterface
3535
// RUN: %target-swift-frontend -typecheck-module-from-interface -I %t %t/Main.private.swiftinterface -module-name Main
3636

37-
/// Serialize and deserialize this module, then print.
38-
// RUN: %target-swift-frontend -emit-module %s -emit-module-path %t/Merged-partial.swiftmodule -swift-version 5 -I %t -module-name Merged -enable-library-evolution
39-
// RUN: %target-swift-frontend -merge-modules %t/Merged-partial.swiftmodule -module-name Merged -emit-module -emit-module-path %t/Merged.swiftmodule -I %t -emit-module-interface-path %t/Merged.swiftinterface -emit-private-module-interface-path %t/Merged.private.swiftinterface -enable-library-evolution -swift-version 5 -I %t
40-
// RUN: %FileCheck -check-prefix=CHECK-PUBLIC %s < %t/Merged.swiftinterface
41-
// RUN: %FileCheck -check-prefix=CHECK-PRIVATE %s < %t/Merged.private.swiftinterface
42-
// RUN: %target-swift-frontend -typecheck-module-from-interface -I %t %t/Merged.swiftinterface
43-
// RUN: %target-swift-frontend -typecheck-module-from-interface -I %t %t/Merged.private.swiftinterface -module-name Merged
44-
4537
/// Both the public and private textual interfaces should have
4638
/// SPI information with `-library-level spi`.
4739
// RUN: %target-swift-frontend -typecheck %s -emit-module-interface-path %t/SPIModule.swiftinterface -emit-private-module-interface-path %t/SPIModule.private.swiftinterface -enable-library-evolution -swift-version 5 -I %t -module-name SPIModule -library-level spi
@@ -157,6 +149,34 @@ public struct PublicStruct {
157149
// CHECK-PUBLIC-NOT: spiWrappedDefault
158150
}
159151

152+
@_spi(S) public enum SPIEnum {
153+
// CHECK-PRIVATE: @_spi(S) public enum SPIEnum
154+
// CHECK-PUBLIC-NOT: SPIEnum
155+
156+
case spiEnumCase
157+
// CHECK-PRIVATE: case spiEnumCase
158+
// CHECK-PUBLIC-NOT: spiEnumCase
159+
}
160+
161+
public enum PublicEnum {
162+
case publicCase
163+
// CHECK-PUBLIC: case publicCase
164+
// CHECK-PRIVATE: case publicCase
165+
166+
@_spi(S) case spiCase
167+
// CHECK-PRIVATE: @_spi(S) case spiCase
168+
// CHECK-PUBLIC-NOT: spiCase
169+
170+
@_spi(S) case spiCaseA, spiCaseB
171+
// CHECK-PRIVATE: @_spi(S) case spiCaseA, spiCaseB
172+
// CHECK-PUBLIC-NOT: spiCaseA
173+
// CHECK-PUBLIC-NOT: spiCaseB
174+
175+
@_spi(S) case spiCaseWithPayload(_ c: SomeClass)
176+
// CHECK-PRIVATE: @_spi(S) case spiCaseWithPayload(_: {{.*}}.SomeClass)
177+
// CHECK-PUBLIC-NOT: spiCaseWithPayload
178+
}
179+
160180
@_spi(LocalSPI) public protocol SPIProto3 {
161181
// CHECK-PRIVATE: @_spi(LocalSPI) public protocol SPIProto3
162182
// CHECK-PUBLIC-NOT: SPIProto3

0 commit comments

Comments
 (0)