Skip to content

Commit a67adee

Browse files
committed
QueryEngine: make some of the private API more public
This extends the visibility of some of the private implementation to the package level to allow use for testing without `@testable` imports.
1 parent a1d4cd7 commit a67adee

File tree

2 files changed

+31
-31
lines changed

2 files changed

+31
-31
lines changed

Sources/QueryEngine/Query.swift

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -26,42 +26,42 @@ extension CachingQuery {
2626
// SwiftPM has to be built with Swift 5.8 on CI and also needs to support CMake for bootstrapping on Windows.
2727
// This means we can't implement persistable hashing with macros (unavailable in Swift 5.8 and additional effort to
2828
// set up with CMake when Swift 5.9 is available for all CI jobs) and have to stick to `Encodable` for now.
29-
final class HashEncoder<Hash: HashFunction>: Encoder {
29+
package final class HashEncoder<Hash: HashFunction>: Encoder {
3030
enum Error: Swift.Error {
3131
case noCacheKeyConformance(Encodable.Type)
3232
}
3333

34-
var codingPath: [any CodingKey]
34+
package var codingPath: [any CodingKey]
3535

36-
var userInfo: [CodingUserInfoKey: Any]
36+
package var userInfo: [CodingUserInfoKey: Any]
3737

38-
func container<Key>(keyedBy type: Key.Type) -> KeyedEncodingContainer<Key> where Key: CodingKey {
38+
package func container<Key>(keyedBy type: Key.Type) -> KeyedEncodingContainer<Key> where Key: CodingKey {
3939
.init(KeyedContainer(encoder: self))
4040
}
4141

42-
func unkeyedContainer() -> any UnkeyedEncodingContainer {
42+
package func unkeyedContainer() -> any UnkeyedEncodingContainer {
4343
self
4444
}
4545

46-
func singleValueContainer() -> any SingleValueEncodingContainer {
46+
package func singleValueContainer() -> any SingleValueEncodingContainer {
4747
self
4848
}
4949

50-
init() {
50+
package init() {
5151
self.hashFunction = Hash()
5252
self.codingPath = []
5353
self.userInfo = [:]
5454
}
5555

5656
fileprivate var hashFunction = Hash()
5757

58-
func finalize() -> Hash.Digest {
58+
package func finalize() -> Hash.Digest {
5959
self.hashFunction.finalize()
6060
}
6161
}
6262

6363
extension HashEncoder: SingleValueEncodingContainer {
64-
func encodeNil() throws {
64+
package func encodeNil() throws {
6565
// FIXME: this doesn't encode the name of the underlying optional type,
6666
// but `Encoder` protocol is limited and can't provide this for us.
6767
var str = "nil"
@@ -70,63 +70,63 @@ extension HashEncoder: SingleValueEncodingContainer {
7070
}
7171
}
7272

73-
func encode(_ value: Bool) throws {
73+
package func encode(_ value: Bool) throws {
7474
value.hash(with: &self.hashFunction)
7575
}
7676

77-
func encode(_ value: String) throws {
77+
package func encode(_ value: String) throws {
7878
value.hash(with: &self.hashFunction)
7979
}
8080

81-
func encode(_ value: Double) throws {
81+
package func encode(_ value: Double) throws {
8282
value.hash(with: &self.hashFunction)
8383
}
8484

85-
func encode(_ value: Float) throws {
85+
package func encode(_ value: Float) throws {
8686
value.hash(with: &self.hashFunction)
8787
}
8888

89-
func encode(_ value: Int) throws {
89+
package func encode(_ value: Int) throws {
9090
value.hash(with: &self.hashFunction)
9191
}
9292

93-
func encode(_ value: Int8) throws {
93+
package func encode(_ value: Int8) throws {
9494
value.hash(with: &self.hashFunction)
9595
}
9696

97-
func encode(_ value: Int16) throws {
97+
package func encode(_ value: Int16) throws {
9898
value.hash(with: &self.hashFunction)
9999
}
100100

101-
func encode(_ value: Int32) throws {
101+
package func encode(_ value: Int32) throws {
102102
value.hash(with: &self.hashFunction)
103103
}
104104

105-
func encode(_ value: Int64) throws {
105+
package func encode(_ value: Int64) throws {
106106
value.hash(with: &self.hashFunction)
107107
}
108108

109-
func encode(_ value: UInt) throws {
109+
package func encode(_ value: UInt) throws {
110110
value.hash(with: &self.hashFunction)
111111
}
112112

113-
func encode(_ value: UInt8) throws {
113+
package func encode(_ value: UInt8) throws {
114114
value.hash(with: &self.hashFunction)
115115
}
116116

117-
func encode(_ value: UInt16) throws {
117+
package func encode(_ value: UInt16) throws {
118118
value.hash(with: &self.hashFunction)
119119
}
120120

121-
func encode(_ value: UInt32) throws {
121+
package func encode(_ value: UInt32) throws {
122122
value.hash(with: &self.hashFunction)
123123
}
124124

125-
func encode(_ value: UInt64) throws {
125+
package func encode(_ value: UInt64) throws {
126126
value.hash(with: &self.hashFunction)
127127
}
128128

129-
func encode<T>(_ value: T) throws where T: Encodable {
129+
package func encode<T>(_ value: T) throws where T: Encodable {
130130
if let leaf = value as? LeafCacheKey {
131131
leaf.hash(with: &self.hashFunction)
132132
return
@@ -142,20 +142,20 @@ extension HashEncoder: SingleValueEncodingContainer {
142142
}
143143

144144
extension HashEncoder: UnkeyedEncodingContainer {
145-
var count: Int {
145+
package var count: Int {
146146
0
147147
}
148148

149-
func nestedContainer<NestedKey>(keyedBy keyType: NestedKey.Type) -> KeyedEncodingContainer<NestedKey>
149+
package func nestedContainer<NestedKey>(keyedBy keyType: NestedKey.Type) -> KeyedEncodingContainer<NestedKey>
150150
where NestedKey: CodingKey {
151151
KeyedEncodingContainer(KeyedContainer(encoder: self))
152152
}
153153

154-
func nestedUnkeyedContainer() -> any UnkeyedEncodingContainer {
154+
package func nestedUnkeyedContainer() -> any UnkeyedEncodingContainer {
155155
self
156156
}
157157

158-
func superEncoder() -> any Encoder {
158+
package func superEncoder() -> any Encoder {
159159
fatalError()
160160
}
161161
}

Sources/QueryEngine/QueryEngine.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ package func withQueryEngine(
3636
/// Cacheable computations engine. Currently the engine makes an assumption that computations produce same results for
3737
/// the same query values and write results to a single file path.
3838
package actor QueryEngine {
39-
private(set) var cacheHits = 0
40-
private(set) var cacheMisses = 0
39+
package private(set) var cacheHits = 0
40+
package private(set) var cacheMisses = 0
4141

4242
package let fileSystem: any AsyncFileSystem
4343
package let httpClient = HTTPClient()
@@ -51,7 +51,7 @@ package actor QueryEngine {
5151
/// - Parameter fileSystem: Implementation of a file system this engine should use.
5252
/// - Parameter cacheLocation: Location of cache storage used by the engine.
5353
/// - Parameter logger: Logger to use during queries execution.
54-
init(
54+
package init(
5555
_ fileSystem: any AsyncFileSystem,
5656
_ observabilityScope: ObservabilityScope,
5757
cacheLocation: SQLite.Location

0 commit comments

Comments
 (0)