Skip to content

swift-api-extract: extract decls with @_spi_available attributes as SPI #61590

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/TBDGen/TBDGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1354,6 +1354,10 @@ void swift::writeTBDFile(ModuleDecl *M, llvm::raw_ostream &os,
}

class APIGenRecorder final : public APIRecorder {
bool isSPI(const ValueDecl* VD) {
assert(VD);
return VD->isSPI() || VD->isAvailableAsSPI();
}
public:
APIGenRecorder(apigen::API &api, ModuleDecl *module)
: api(api), module(module) {
Expand All @@ -1373,13 +1377,13 @@ class APIGenRecorder final : public APIRecorder {
auto ref = source.getSILDeclRef();
if (ref.hasDecl()) {
availability = getAvailability(ref.getDecl());
if (ref.getDecl()->isSPI())
if (isSPI(ref.getDecl()))
access = apigen::APIAccess::Private;
}
} else if (source.kind == SymbolSource::Kind::IR) {
auto ref = source.getIRLinkEntity();
if (ref.hasDecl()) {
if (ref.getDecl()->isSPI())
if (isSPI(ref.getDecl()))
access = apigen::APIAccess::Private;
}
}
Expand Down
18 changes: 18 additions & 0 deletions test/APIJSON/spi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ public class MyClass2 : NSObject {
@_spi(Experimental) @objc public func spiMethod() {}
}

@_spi_available(macOS 10.10, tvOS 14.0, *)
@available(iOS 8.0, *)
public func spiAvailableFunc() {}

// CHECK: {
// CHECK-NEXT: "target":
// CHECK-NEXT: "globals": [
Expand Down Expand Up @@ -63,6 +67,13 @@ public class MyClass2 : NSObject {
// CHECK-NEXT: "linkage": "exported"
// CHECK-NEXT: },
// CHECK-NEXT: {
// CHECK-NEXT: "name": "_$s8MyModule16spiAvailableFuncyyF",
// CHECK-NEXT: "access": "public",
// CHECK-NEXT: "file": "/@input/MyModule.swiftinterface",
// CHECK-NEXT: "linkage": "exported",
// CHECK-NEXT: "unavailable": true
// CHECK-NEXT: },
// CHECK-NEXT: {
// CHECK-NEXT: "name": "_OBJC_CLASS_$__TtC8MyModule8MyClass2",
// CHECK-NEXT: "access": "public",
// CHECK-NEXT: "file": "/@input/MyModule.swiftinterface",
Expand Down Expand Up @@ -225,6 +236,13 @@ public class MyClass2 : NSObject {
// CHECK-SPI-NEXT: "file": "/@input/MyModule.swiftmodule",
// CHECK-SPI-NEXT: "linkage": "exported"
// CHECK-SPI-NEXT: },
// CHECK-SPI-NEXT: {
// CHECK-SPI-NEXT: "name": "_$s8MyModule16spiAvailableFuncyyF",
// CHECK-SPI-NEXT: "access": "private",
// CHECK-SPI-NEXT: "file": "/@input/MyModule.swiftmodule",
// CHECK-SPI-NEXT: "linkage": "exported",
// CHECK-SPI-NEXT: "introduced": "10.10"
// CHECK-SPI-NEXT: },
// CHECK-SPI-NEXT: {
// CHECK-SPI-NEXT: "name": "_OBJC_CLASS_$__TtC8MyModule7MyClass",
// CHECK-SPI-NEXT: "access": "private",
Expand Down