Skip to content

Commit 70dbf82

Browse files
committed
build: convert CIndexStoreDB to @_implementationOnly
Prevent the `CIndexStoreDB` import from leaking into clients by using `@_implementationOnly`. A couple of internal types need to be type-erased to make this possible. The typealiases are for `void *`, so they can be easily replaced with `UnsafeMutableRawPointer`.
1 parent 4dfc125 commit 70dbf82

File tree

7 files changed

+15
-8
lines changed

7 files changed

+15
-8
lines changed

Sources/IndexStoreDB/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ add_library(IndexStoreDB
1515
Symbol.swift)
1616
set_target_properties(IndexStoreDB PROPERTIES
1717
Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift
18-
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_BINARY_DIR}/swift)
18+
INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_BINARY_DIR}/swift")
1919
target_link_libraries(IndexStoreDB PRIVATE
2020
Foundation
2121
CIndexStoreDB)

Sources/IndexStoreDB/IndexStoreDB.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
@_implementationOnly
1314
import CIndexStoreDB
1415

1516
// For `strdup`
@@ -25,7 +26,7 @@ import Darwin.POSIX
2526
public final class IndexStoreDB {
2627

2728
let delegate: IndexDelegate?
28-
let impl: indexstoredb_index_t
29+
let impl: UnsafeMutableRawPointer // indexstoredb_index_t
2930

3031
/// Create or open an IndexStoreDB at the givin `databasePath`.
3132
///
@@ -51,7 +52,7 @@ public final class IndexStoreDB {
5152
) throws {
5253
self.delegate = delegate
5354

54-
let libProviderFunc = { (cpath: UnsafePointer<Int8>) -> indexstoredb_indexstore_library_t? in
55+
let libProviderFunc: indexstore_library_provider_t = { (cpath: UnsafePointer<Int8>) -> indexstoredb_indexstore_library_t? in
5556
return library?.library
5657
}
5758

@@ -294,7 +295,7 @@ public protocol IndexStoreLibraryProvider {
294295
}
295296

296297
public class IndexStoreLibrary {
297-
let library: indexstoredb_indexstore_library_t
298+
let library: UnsafeMutableRawPointer // indexstoredb_indexstore_library_t
298299

299300
public init(dylibPath: String) throws {
300301
var error: indexstoredb_error_t? = nil

Sources/IndexStoreDB/IndexStoreDBError.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
@_implementationOnly
1314
import CIndexStoreDB
15+
1416
import protocol Foundation.LocalizedError
1517

1618
public enum IndexStoreDBError: Error {

Sources/IndexStoreDB/Symbol.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
@_implementationOnly
1314
import CIndexStoreDB
1415

1516
public enum IndexSymbolKind: Hashable {

Sources/IndexStoreDB/SymbolLocation.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
@_implementationOnly
1314
import CIndexStoreDB
1415

1516
public struct SymbolLocation: Equatable {
@@ -44,7 +45,7 @@ extension SymbolLocation: CustomStringConvertible {
4445
// MARK: CIndexStoreDB conversions
4546

4647
extension SymbolLocation {
47-
public init(_ loc: indexstoredb_symbol_location_t) {
48+
internal init(_ loc: indexstoredb_symbol_location_t) {
4849
path = String(cString: indexstoredb_symbol_location_path(loc))
4950
moduleName = String(cString: indexstoredb_symbol_location_module_name(loc))
5051
isSystem = indexstoredb_symbol_location_is_system(loc)

Sources/IndexStoreDB/SymbolOccurrence.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
@_implementationOnly
1314
import CIndexStoreDB
1415

1516
public struct SymbolOccurrence: Equatable {
@@ -60,7 +61,7 @@ public struct SymbolRelation: Equatable {
6061
extension SymbolOccurrence {
6162

6263
/// Note: `value` is expected to be passed +1.
63-
init(_ value: indexstoredb_symbol_occurrence_t) {
64+
internal init(_ value: indexstoredb_symbol_occurrence_t) {
6465
var relations: [SymbolRelation] = []
6566
indexstoredb_symbol_occurrence_relations(value) { relation in
6667
relations.append(SymbolRelation(relation))
@@ -76,7 +77,7 @@ extension SymbolOccurrence {
7677
}
7778

7879
extension SymbolRelation {
79-
public init(_ value: indexstoredb_symbol_relation_t) {
80+
internal init(_ value: indexstoredb_symbol_relation_t) {
8081
self.init(
8182
symbol: Symbol(indexstoredb_symbol_relation_get_symbol(value)),
8283
roles: SymbolRole(rawValue: indexstoredb_symbol_relation_get_roles(value)))

Sources/IndexStoreDB/SymbolRole.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
@_implementationOnly
1314
import CIndexStoreDB
1415

1516
public struct SymbolRole: OptionSet, Hashable {
@@ -51,7 +52,7 @@ public struct SymbolRole: OptionSet, Hashable {
5152
self.rawValue = rawValue
5253
}
5354

54-
public init(rawValue: indexstoredb_symbol_role_t) {
55+
internal init(rawValue: indexstoredb_symbol_role_t) {
5556
self.rawValue = UInt64(rawValue.rawValue)
5657
}
5758
}

0 commit comments

Comments
 (0)