Skip to content

Commit e88c3ed

Browse files
tshortlimeg-gupta
authored andcommitted
TBDGen: Use isSPI() wrapper more consistently.
This ensures that different kinds of declarations with the `@_spi_available` attribute are handled consistently.
1 parent 78b5c0c commit e88c3ed

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

lib/IRGen/TBDGen.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -655,10 +655,11 @@ void swift::writeTBDFile(ModuleDecl *M, llvm::raw_ostream &os,
655655
}
656656

657657
class APIGenRecorder final : public APIRecorder {
658-
bool isSPI(const ValueDecl* VD) {
659-
assert(VD);
660-
return VD->isSPI() || VD->isAvailableAsSPI();
658+
static bool isSPI(const Decl *decl) {
659+
assert(decl);
660+
return decl->isSPI() || decl->isAvailableAsSPI();
661661
}
662+
662663
public:
663664
APIGenRecorder(apigen::API &api, ModuleDecl *module)
664665
: api(api), module(module) {
@@ -704,7 +705,7 @@ class APIGenRecorder final : public APIRecorder {
704705
if (method.getDecl()->getDescriptiveKind() ==
705706
DescriptiveDeclKind::ClassMethod)
706707
isInstanceMethod = false;
707-
if (method.getDecl()->isSPI())
708+
if (isSPI(method.getDecl()))
708709
access = apigen::APIAccess::Private;
709710
}
710711

@@ -770,7 +771,7 @@ class APIGenRecorder final : public APIRecorder {
770771
superCls = super->getObjCRuntimeName(buffer);
771772
apigen::APIAvailability availability = getAvailability(decl);
772773
apigen::APIAccess access =
773-
decl->isSPI() ? apigen::APIAccess::Private : apigen::APIAccess::Public;
774+
isSPI(decl) ? apigen::APIAccess::Private : apigen::APIAccess::Public;
774775
apigen::APILinkage linkage =
775776
decl->getFormalAccess() == AccessLevel::Public && decl->isObjC()
776777
? apigen::APILinkage::Exported
@@ -803,7 +804,7 @@ class APIGenRecorder final : public APIRecorder {
803804
buildCategoryName(decl, cls, nameBuffer);
804805
apigen::APIAvailability availability = getAvailability(decl);
805806
apigen::APIAccess access =
806-
decl->isSPI() ? apigen::APIAccess::Private : apigen::APIAccess::Public;
807+
isSPI(decl) ? apigen::APIAccess::Private : apigen::APIAccess::Public;
807808
apigen::APILinkage linkage =
808809
decl->getMaxAccessLevel() == AccessLevel::Public
809810
? apigen::APILinkage::Exported

test/APIJSON/spi.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ public func spiAvailableFunc() {}
318318
// CHECK-SPI-NEXT: },
319319
// CHECK-SPI-NEXT: {
320320
// CHECK-SPI-NEXT: "name": "spiAvailableMethod",
321-
// CHECK-SPI-NEXT: "access": "public",
321+
// CHECK-SPI-NEXT: "access": "private",
322322
// CHECK-SPI-NEXT: "file": "/@input/MyModule.swiftmodule",
323323
// CHECK-SPI-NEXT: "introduced": "10.10"
324324
// CHECK-SPI-NEXT: },

0 commit comments

Comments
 (0)