Skip to content

Commit 559c06b

Browse files
committed
Use the package access level instead of @testable imports
`@testable` imports have a number of build-time drawbacks, including: - Building the package in `release` configuration and then running tests requires the entire package to be rebuilt because SwiftPM needs to pass `--enable-testing` to the compiler invocations. - The usage of `@testable` means that swift-foundation cannot be included in the unified (aka. multiroot) build of all the other packages in Swift CI, which means that it needs to re-build swift-syntax, unnecessarily increasing CI time. To fix this, make all `@testable` imports normal imports and mark the declarations that were previously accessed through `@testable` as `package`.
1 parent f751db3 commit 559c06b

File tree

100 files changed

+437
-385
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+437
-385
lines changed

Sources/FoundationEssentials/AttributedString/AttributedString+Guts.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#if FOUNDATION_FRAMEWORK
14-
@_spi(Unstable) internal import CollectionsInternal
14+
@_spi(Unstable) package import CollectionsInternal
1515
#elseif canImport(_RopeModule)
16-
internal import _RopeModule
16+
package import _RopeModule
1717
#elseif canImport(_FoundationCollections)
18-
internal import _FoundationCollections
18+
package import _FoundationCollections
1919
#endif
2020

2121
extension AttributedString {
22-
internal final class Guts : @unchecked Sendable {
22+
package final class Guts : @unchecked Sendable {
2323
typealias Index = AttributedString.Index
2424
typealias Runs = AttributedString.Runs
2525
typealias AttributeMergePolicy = AttributedString.AttributeMergePolicy
@@ -30,7 +30,7 @@ extension AttributedString {
3030
typealias _AttributeStorage = AttributedString._AttributeStorage
3131

3232
var version: Version
33-
var string: BigString
33+
package var string: BigString
3434
var runs: _InternalRuns
3535
var trackedRanges: [Range<BigString.Index>]
3636

Sources/FoundationEssentials/AttributedString/AttributedString.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ internal import _FoundationCollections
2121
@dynamicMemberLookup
2222
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
2323
public struct AttributedString : Sendable {
24-
internal var _guts: Guts
24+
package var _guts: Guts
2525

2626
internal init(_ guts: Guts) {
2727
_guts = guts

Sources/FoundationEssentials/Calendar/Calendar.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ public struct Calendar : Hashable, Equatable, Sendable {
403403
}
404404

405405
/// For use by `NSCoding` implementation in `NSCalendar` and `Codable` for `Calendar` only.
406-
internal init(identifier: Calendar.Identifier, locale: Locale, timeZone: TimeZone?, firstWeekday: Int?, minimumDaysInFirstWeek: Int?, gregorianStartDate: Date?) {
406+
package init(identifier: Calendar.Identifier, locale: Locale, timeZone: TimeZone?, firstWeekday: Int?, minimumDaysInFirstWeek: Int?, gregorianStartDate: Date?) {
407407
_calendar = CalendarCache.cache.fixed(identifier: identifier, locale: locale, timeZone: timeZone, firstWeekday: firstWeekday, minimumDaysInFirstWeek: minimumDaysInFirstWeek, gregorianStartDate: gregorianStartDate)
408408
}
409409

Sources/FoundationEssentials/Calendar/Calendar_Gregorian.swift

+30-30
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ extension Date {
3838
timeIntervalSinceReferenceDate / 86400 + Self.julianDayAtDateReference
3939
}
4040

41-
func julianDay() throws (GregorianCalendarError) -> Int {
41+
package func julianDay() throws (GregorianCalendarError) -> Int {
4242
let jd = (julianDate + 0.5).rounded(.down)
4343
guard jd <= Double(Self.maxJulianDay), jd >= Double(Self.minJulianDay) else {
4444
throw .overflow(nil, self, nil)
@@ -51,7 +51,7 @@ extension Date {
5151
self.init(julianDate: Double(julianDay))
5252
}
5353

54-
init(julianDate: Double) {
54+
package init(julianDate: Double) {
5555
let secondsSinceJulianReference = (julianDate - Self.julianDayAtDateReference) * 86400
5656
self.init(timeIntervalSinceReferenceDate: secondsSinceJulianReference)
5757
}
@@ -165,13 +165,13 @@ enum ResolvedDateComponents {
165165

166166

167167
/// Internal-use error for indicating unexpected situations when finding dates.
168-
enum GregorianCalendarError : Error {
168+
package enum GregorianCalendarError : Error {
169169
case overflow(Calendar.Component?, Date? /* failing start date */, Date? /* failing end date */)
170170
case notAdvancing(Date /* next */, Date /* previous */)
171171
}
172172

173173
/// This class is a placeholder and work-in-progress to provide an implementation of the Gregorian calendar.
174-
internal final class _CalendarGregorian: _CalendarProtocol, @unchecked Sendable {
174+
package final class _CalendarGregorian: _CalendarProtocol, @unchecked Sendable {
175175

176176
#if canImport(os)
177177
internal static let logger: Logger = {
@@ -191,7 +191,7 @@ internal final class _CalendarGregorian: _CalendarProtocol, @unchecked Sendable
191191

192192
let inf_ti : TimeInterval = 4398046511104.0
193193

194-
init(identifier: Calendar.Identifier, timeZone: TimeZone?, locale: Locale?, firstWeekday: Int?, minimumDaysInFirstWeek: Int?, gregorianStartDate: Date?) {
194+
package init(identifier: Calendar.Identifier, timeZone: TimeZone?, locale: Locale?, firstWeekday: Int?, minimumDaysInFirstWeek: Int?, gregorianStartDate: Date?) {
195195

196196
// ISO8601 has different default values for time zone, locale, firstWeekday, and minimumDaysInFirstWeek
197197
let defaultTimeZone: TimeZone
@@ -250,14 +250,14 @@ internal final class _CalendarGregorian: _CalendarProtocol, @unchecked Sendable
250250
self.identifier = identifier
251251
}
252252

253-
let identifier: Calendar.Identifier
253+
package let identifier: Calendar.Identifier
254254

255-
var locale: Locale?
255+
package var locale: Locale?
256256

257-
var timeZone: TimeZone
257+
package var timeZone: TimeZone
258258

259259
var _firstWeekday: Int?
260-
var firstWeekday: Int {
260+
package var firstWeekday: Int {
261261
set {
262262
precondition(newValue >= 1 && newValue <= 7, "Weekday should be in the range of 1...7")
263263
_firstWeekday = newValue
@@ -275,7 +275,7 @@ internal final class _CalendarGregorian: _CalendarProtocol, @unchecked Sendable
275275
}
276276

277277
var _minimumDaysInFirstWeek: Int?
278-
var minimumDaysInFirstWeek: Int {
278+
package var minimumDaysInFirstWeek: Int {
279279
set {
280280
if newValue < 1 {
281281
_minimumDaysInFirstWeek = 1
@@ -298,7 +298,7 @@ internal final class _CalendarGregorian: _CalendarProtocol, @unchecked Sendable
298298
}
299299
}
300300

301-
func copy(changingLocale: Locale?, changingTimeZone: TimeZone?, changingFirstWeekday: Int?, changingMinimumDaysInFirstWeek: Int?) -> _CalendarProtocol {
301+
package func copy(changingLocale: Locale?, changingTimeZone: TimeZone?, changingFirstWeekday: Int?, changingMinimumDaysInFirstWeek: Int?) -> _CalendarProtocol {
302302
let newTimeZone = changingTimeZone ?? self.timeZone
303303
let newLocale = changingLocale ?? self.locale
304304

@@ -323,7 +323,7 @@ internal final class _CalendarGregorian: _CalendarProtocol, @unchecked Sendable
323323
return _CalendarGregorian.init(identifier: identifier, timeZone: newTimeZone, locale: newLocale, firstWeekday: newFirstWeekday, minimumDaysInFirstWeek: newMinDays, gregorianStartDate: nil)
324324
}
325325

326-
func hash(into hasher: inout Hasher) {
326+
package func hash(into hasher: inout Hasher) {
327327
hasher.combine(identifier)
328328
hasher.combine(timeZone)
329329
hasher.combine(firstWeekday)
@@ -337,7 +337,7 @@ internal final class _CalendarGregorian: _CalendarProtocol, @unchecked Sendable
337337

338338
// Returns the range of a component in Gregorian Calendar.
339339
// When there are multiple possible upper bounds, the smallest one is returned.
340-
func minimumRange(of component: Calendar.Component) -> Range<Int>? {
340+
package func minimumRange(of component: Calendar.Component) -> Range<Int>? {
341341
switch component {
342342
case .era: 0..<2
343343
case .year: 1..<140743
@@ -362,7 +362,7 @@ internal final class _CalendarGregorian: _CalendarProtocol, @unchecked Sendable
362362

363363
// Returns the range of a component in Gregorian Calendar.
364364
// When there are multiple possible upper bounds, the largest one is returned.
365-
func maximumRange(of component: Calendar.Component) -> Range<Int>? {
365+
package func maximumRange(of component: Calendar.Component) -> Range<Int>? {
366366
switch component {
367367
case .era: return 0..<2
368368
case .year: return 1..<144684
@@ -497,7 +497,7 @@ internal final class _CalendarGregorian: _CalendarProtocol, @unchecked Sendable
497497
return ord1..<(ord2 + 1)
498498
}
499499

500-
func range(of smaller: Calendar.Component, in larger: Calendar.Component, for date: Date) -> Range<Int>? {
500+
package func range(of smaller: Calendar.Component, in larger: Calendar.Component, for date: Date) -> Range<Int>? {
501501
func isValidComponent(_ c: Calendar.Component) -> Bool {
502502
return !(c == .calendar || c == .timeZone || c == .weekdayOrdinal || c == .nanosecond)
503503
}
@@ -865,7 +865,7 @@ internal final class _CalendarGregorian: _CalendarProtocol, @unchecked Sendable
865865

866866
// FIXME: This is almost the same with Calendar_ICU's _locked_start(of:).
867867
// There is a chance of refactoring Calendar_ICU to use this one
868-
func start(of unit: Calendar.Component, at: Date) -> Date? {
868+
package func start(of unit: Calendar.Component, at: Date) -> Date? {
869869
let time = at.timeIntervalSinceReferenceDate
870870

871871
var effectiveUnit = unit
@@ -922,7 +922,7 @@ internal final class _CalendarGregorian: _CalendarProtocol, @unchecked Sendable
922922
return (work, daysAdded)
923923
}
924924

925-
func ordinality(of smaller: Calendar.Component, in larger: Calendar.Component, for date: Date) -> Int? {
925+
package func ordinality(of smaller: Calendar.Component, in larger: Calendar.Component, for date: Date) -> Int? {
926926
let result: Int?
927927
do {
928928
result = try _ordinality(of: smaller, in: larger, for: date)
@@ -1445,7 +1445,7 @@ internal final class _CalendarGregorian: _CalendarProtocol, @unchecked Sendable
14451445
// No return here to ensure we've covered all cases in switch statements above, even via `default`.
14461446
}
14471447

1448-
func dateInterval(of component: Calendar.Component, for date: Date) -> DateInterval? {
1448+
package func dateInterval(of component: Calendar.Component, for date: Date) -> DateInterval? {
14491449
let time = date.timeIntervalSinceReferenceDate
14501450
var effectiveUnit = component
14511451
switch effectiveUnit {
@@ -1582,7 +1582,7 @@ internal final class _CalendarGregorian: _CalendarProtocol, @unchecked Sendable
15821582
return TimeInterval(totalSecond)
15831583
}
15841584

1585-
func isDateInWeekend(_ date: Date) -> Bool {
1585+
package func isDateInWeekend(_ date: Date) -> Bool {
15861586
let weekendRange: WeekendRange
15871587
if let localeWeekendRange = locale?.weekendRange {
15881588
weekendRange = localeWeekendRange
@@ -1595,7 +1595,7 @@ internal final class _CalendarGregorian: _CalendarProtocol, @unchecked Sendable
15951595
}
15961596

15971597
// For testing purpose
1598-
internal func isDateInWeekend(_ date: Date, weekendRange: WeekendRange) -> Bool {
1598+
package func isDateInWeekend(_ date: Date, weekendRange: WeekendRange) -> Bool {
15991599

16001600
// First, compare the day of the week
16011601
let dayOfWeek = dateComponent(.weekday, from: date)
@@ -1660,7 +1660,7 @@ internal final class _CalendarGregorian: _CalendarProtocol, @unchecked Sendable
16601660
return true
16611661
}
16621662

1663-
func date(from components: DateComponents) -> Date? {
1663+
package func date(from components: DateComponents) -> Date? {
16641664
guard _CalendarGregorian.isComponentsInSupportedRange(components) else {
16651665

16661666
// One or more values exceeds supported date range
@@ -1682,7 +1682,7 @@ internal final class _CalendarGregorian: _CalendarProtocol, @unchecked Sendable
16821682
return relativeWeekday
16831683
}
16841684

1685-
func numberOfDaysInMonth(_ month: Int, year: Int) -> Int {
1685+
package func numberOfDaysInMonth(_ month: Int, year: Int) -> Int {
16861686
var month = month
16871687
var year = year
16881688
if month > 12 {
@@ -1978,7 +1978,7 @@ internal final class _CalendarGregorian: _CalendarProtocol, @unchecked Sendable
19781978
return weekNo
19791979
}
19801980

1981-
func dateComponents(_ components: Calendar.ComponentSet, from d: Date, in timeZone: TimeZone) -> DateComponents {
1981+
package func dateComponents(_ components: Calendar.ComponentSet, from d: Date, in timeZone: TimeZone) -> DateComponents {
19821982
let timezoneOffset = timeZone.secondsFromGMT(for: d)
19831983
let localDate = d + Double(timezoneOffset)
19841984

@@ -2132,11 +2132,11 @@ internal final class _CalendarGregorian: _CalendarProtocol, @unchecked Sendable
21322132
return dc
21332133
}
21342134

2135-
func dateComponents(_ components: Calendar.ComponentSet, from date: Date) -> DateComponents {
2135+
package func dateComponents(_ components: Calendar.ComponentSet, from date: Date) -> DateComponents {
21362136
dateComponents(components, from: date, in: timeZone)
21372137
}
21382138

2139-
func dateComponent(_ component: Calendar.Component, from date: Date) -> Int {
2139+
package func dateComponent(_ component: Calendar.Component, from date: Date) -> Int {
21402140
guard let value = dateComponents(.init(single: component), from: date, in: timeZone).value(for: component) else {
21412141
preconditionFailure("dateComponents(:from:in:) unexpectedly returns nil for requested component")
21422142
}
@@ -2227,7 +2227,7 @@ internal final class _CalendarGregorian: _CalendarProtocol, @unchecked Sendable
22272227
return nil
22282228
}
22292229

2230-
func add(_ field: Calendar.Component, to date: Date, amount: Int, inTimeZone timeZone: TimeZone) throws (GregorianCalendarError) -> Date {
2230+
package func add(_ field: Calendar.Component, to date: Date, amount: Int, inTimeZone timeZone: TimeZone) throws (GregorianCalendarError) -> Date {
22312231

22322232
guard amount != 0 else {
22332233
return date
@@ -2406,7 +2406,7 @@ internal final class _CalendarGregorian: _CalendarProtocol, @unchecked Sendable
24062406
return newValue
24072407
}
24082408

2409-
func addAndWrap(_ field: Calendar.Component, to date: Date, amount: Int, inTimeZone timeZone: TimeZone) throws (GregorianCalendarError) -> Date {
2409+
package func addAndWrap(_ field: Calendar.Component, to date: Date, amount: Int, inTimeZone timeZone: TimeZone) throws (GregorianCalendarError) -> Date {
24102410

24112411
guard amount != 0 else {
24122412
return date
@@ -2851,7 +2851,7 @@ internal final class _CalendarGregorian: _CalendarProtocol, @unchecked Sendable
28512851
return result
28522852
}
28532853

2854-
func date(byAdding components: DateComponents, to date: Date, wrappingComponents: Bool) -> Date? {
2854+
package func date(byAdding components: DateComponents, to date: Date, wrappingComponents: Bool) -> Date? {
28552855
do {
28562856
if wrappingComponents {
28572857
return try self.date(byAddingAndWrapping: components, to: date)
@@ -2866,7 +2866,7 @@ internal final class _CalendarGregorian: _CalendarProtocol, @unchecked Sendable
28662866
// MARK: Differences
28672867

28682868
// Calendar::fieldDifference
2869-
func difference(inComponent component: Calendar.Component, from start: Date, to end: Date) throws (GregorianCalendarError) -> (difference: Int, newStart: Date) {
2869+
package func difference(inComponent component: Calendar.Component, from start: Date, to end: Date) throws (GregorianCalendarError) -> (difference: Int, newStart: Date) {
28702870
guard end != start else {
28712871
return (0, start)
28722872
}
@@ -2944,7 +2944,7 @@ internal final class _CalendarGregorian: _CalendarProtocol, @unchecked Sendable
29442944
}
29452945

29462946

2947-
func dateComponents(_ components: Calendar.ComponentSet, from start: Date, to end: Date) -> DateComponents {
2947+
package func dateComponents(_ components: Calendar.ComponentSet, from start: Date, to end: Date) -> DateComponents {
29482948

29492949
var diffsInNano: Int
29502950
var curr: Date

Sources/FoundationEssentials/Decimal/Decimal+Conformances.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ extension Decimal : ExpressibleByIntegerLiteral {
444444

445445
@available(macOS 10.10, iOS 8.0, watchOS 2.0, tvOS 9.0, *)
446446
extension Decimal: Hashable {
447-
internal subscript(index: UInt32) -> UInt16 {
447+
package subscript(index: UInt32) -> UInt16 {
448448
get {
449449
switch index {
450450
case 0: return _mantissa.0

0 commit comments

Comments
 (0)