Skip to content

Commit 87de3d2

Browse files
authored
Merge branch 'swiftlang:main' into implementation/progress-reporter
2 parents b13718f + 2df5199 commit 87de3d2

File tree

14 files changed

+573
-555
lines changed

14 files changed

+573
-555
lines changed

Benchmarks/Benchmarks/Internationalization/BenchmarkLocale.swift

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,20 @@
1313
import Benchmark
1414
import func Benchmark.blackHole
1515

16-
#if FOUNDATION_FRAMEWORK // This test uses CFString
16+
#if os(macOS) && USE_PACKAGE
17+
import FoundationEssentials
18+
import FoundationInternationalization
19+
#else
1720
import Foundation
21+
#endif
1822

1923
let benchmarks = {
2024
Benchmark.defaultConfiguration.maxIterations = 1_000
2125
Benchmark.defaultConfiguration.maxDuration = .seconds(3)
2226
Benchmark.defaultConfiguration.scalingFactor = .kilo
23-
Benchmark.defaultConfiguration.metrics = [.cpuTotal, .wallClock, .mallocCountTotal, .throughput]
27+
Benchmark.defaultConfiguration.metrics = [.cpuTotal, .wallClock, .throughput, .peakMemoryResident, .peakMemoryResidentDelta]
2428

29+
#if FOUNDATION_FRAMEWORK
2530
let string1 = "aaA" as CFString
2631
let string2 = "AAà" as CFString
2732
let range1 = CFRange(location: 0, length: CFStringGetLength(string1))
@@ -34,5 +39,22 @@ let benchmarks = {
3439
CFStringCompareWithOptionsAndLocale(string1, string2, range1, .init(rawValue: 0), nsLocale)
3540
}
3641
}
37-
}
3842
#endif
43+
44+
let identifiers = Locale.availableIdentifiers
45+
let allComponents = identifiers.map { Locale.Components(identifier: $0) }
46+
Benchmark("LocaleInitFromComponents") { benchmark in
47+
for components in allComponents {
48+
let locale = Locale(components: components)
49+
let components2 = Locale.Components(locale: locale)
50+
let locale2 = Locale(components: components2) // cache hit
51+
}
52+
}
53+
54+
Benchmark("LocaleComponentsInitIdentifer") { benchmark in
55+
for identifier in identifiers {
56+
let components = Locale.Components(identifier: identifier)
57+
}
58+
}
59+
}
60+

Proposals/0007-swift-subprocess.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Status: **Accepted as 0.1**
77
* Bugs: [rdar://118127512](rdar://118127512), [apple/swift-foundation#309](https://github.com/apple/swift-foundation/issues/309)
88
* Review: [Pitch](https://forums.swift.org/t/pitch-swift-subprocess/69805/65), [1st review](https://forums.swift.org/t/review-sf-0007-introducing-swift-subprocess/70337), [2nd review](https://forums.swift.org/t/review-2nd-sf-0007-subprocess/76547), [3rd review](https://forums.swift.org/t/review-3rd-sf-0007-subprocess/78078/64)
9-
9+
* Implementation: https://github.com/swiftlang/swift-subprocess
1010

1111
## Revision History
1212

Proposals/0014-attributed-string-discontiguous-operations.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Review Manager: [Tina Liu](https://github.com/itingliu)
66
* Status: **Accepted**
77
* Review: ([Pitch](https://forums.swift.org/t/pitch-attributedstring-discontiguous-operations/76574))
8+
* Implementation: #1145
89

910
## Introduction
1011

Proposals/0017-expanded-calendar-support.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# Expanded calendar support
22

3-
* Proposal: SF-017
3+
* Proposal: SF-0017
44
* Authors: [Dragan Besevic]([email protected])
55
* Review Manager: Tina Liu
6+
* Implementation: https://github.com/swiftlang/swift-foundation/pull/1171
67
* Status: **Accepted**
78

89

Proposals/0021-ISO8601ComponentsStyle.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
* Proposal: SF-0021
44
* Author(s): Tony Parker <[email protected]>
5-
* Status: **Review: March 19, 2025...March 26, 2025**
5+
* Status: **Accepted**
66
* Intended Release: _Swift 6.2_
7+
* Implementation: https://github.com/swiftlang/swift-foundation/pull/1209
78
* Review: ([pitch](https://forums.swift.org/t/pitch-iso8601-components-format-style/77990))
89
*_Related issues_*
910

Proposals/0023-progress-reporter.md

Lines changed: 489 additions & 509 deletions
Large diffs are not rendered by default.

Proposals/0024-CurrentBundle.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Proposal: [SF-0024](0024-filename.md)
55
* Authors:[Matt Seaman](https://github.com/matthewseaman), [Andreas Neusuess](https://github.com/Tantalum73)
66
* Review Manager: [Tina L](https://github.com/itingliu)
7+
* Implementation: https://github.com/swiftlang/swift-foundation/pull/1274
78
* Status: **Accepted**
89

910

Proposals/0025-markdown-list-delimiters.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Authors: [Jeremy Schonfeld](https://github.com/jmschonfeld)
55
* Review Manager: TBD
66
* Status: **Pitch**
7+
* Implementation: https://github.com/swiftlang/swift-foundation/pull/1272
78
* Review: ([pitch](https://forums.swift.org/t/pitch-markdown-list-delimiters/79174))
89

910
## Revision history

Proposals/0026-preferredLocales.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
* Proposal: [SF-0026](0026-preferredLocales.md)
44
* Authors: [करन मिश्र · Karan Miśra](https://github.com/karan-misra)
55
* Review Manager: TBD
6-
* Status: **Awaiting review**
6+
* Status: **Accepted**
7+
* Implementation: https://github.com/swiftlang/swift-foundation/pull/1315
78
* Review: ([pitch](https://forums.swift.org/t/pitch-introduce-locale-preferredlocales/79900))
89

910
## Introduction

Sources/FoundationEssentials/Data/Data.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2205,6 +2205,9 @@ public struct Data : Equatable, Hashable, RandomAccessCollection, MutableCollect
22052205

22062206
#if compiler(>=6.2) && $LifetimeDependence
22072207
@available(FoundationSpan 6.2, *)
2208+
#if FOUNDATION_FRAMEWORK
2209+
@_disfavoredOverload
2210+
#endif // FOUNDATION_FRAMEWORK
22082211
public var bytes: RawSpan {
22092212
@lifetime(borrow self)
22102213
borrowing get {

Sources/FoundationEssentials/Locale/Locale+Components.swift

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,42 @@ extension Locale {
8585
public init(languageCode: Locale.LanguageCode? = nil, script: Locale.Script? = nil, languageRegion: Locale.Region? = nil) {
8686
self.languageComponents = Language.Components(languageCode: languageCode, script: script, region: languageRegion)
8787
}
88+
89+
// Returns an ICU-style identifier like "de_DE@calendar=gregorian"
90+
// Must include every component stored by a `Locale.Components`, and be kept in sync with `init(identifier:)`.
91+
package var icuIdentifier: String {
92+
93+
var keywords = [(ICULegacyKey, String)]()
94+
if let id = calendar?.cldrIdentifier { keywords.append((Calendar.Identifier.legacyKeywordKey, id)) }
95+
if let id = collation?._normalizedIdentifier { keywords.append((Locale.Collation.legacyKeywordKey, id)) }
96+
if let id = currency?._normalizedIdentifier { keywords.append((Locale.Currency.legacyKeywordKey, id)) }
97+
if let id = numberingSystem?._normalizedIdentifier { keywords.append((Locale.NumberingSystem.legacyKeywordKey, id)) }
98+
if let id = firstDayOfWeek?.rawValue { keywords.append((Locale.Weekday.legacyKeywordKey, id)) }
99+
if let id = hourCycle?.rawValue { keywords.append((Locale.HourCycle.legacyKeywordKey, id)) }
100+
if let id = measurementSystem?._normalizedIdentifier { keywords.append((Locale.MeasurementSystem.legacyKeywordKey, id)) }
101+
// No need for redundant region keyword
102+
if let region = region, region != languageComponents.region {
103+
// rg keyword value is actually a subdivision code
104+
keywords.append((Locale.Region.legacyKeywordKey, Locale.Subdivision.subdivision(for: region)._normalizedIdentifier))
105+
}
106+
if let id = subdivision?._normalizedIdentifier { keywords.append((Locale.Subdivision.legacyKeywordKey, id)) }
107+
if let id = timeZone?.identifier { keywords.append((TimeZone.legacyKeywordKey, id)) }
108+
if let id = variant?._normalizedIdentifier { keywords.append((Locale.Variant.legacyKeywordKey, id)) }
109+
110+
var locID = languageComponents.identifier
111+
let keywordCounts = keywords.count
112+
if keywordCounts > 0 {
113+
locID.append("@")
114+
}
115+
116+
for (i, (key, val)) in keywords.enumerated() {
117+
locID.append("\(key.key)=\(val)")
118+
if i != keywordCounts - 1 {
119+
locID.append(";")
120+
}
121+
}
122+
return locID
123+
}
88124
}
89125
}
90126

Sources/FoundationEssentials/Locale/Locale_Cache.swift

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ struct LocaleCache : Sendable, ~Copyable {
4545
}
4646

4747
private var cachedFixedLocales: [String : any _LocaleProtocol] = [:]
48-
private var cachedFixedComponentsLocales: [Locale.Components : any _LocaleProtocol] = [:]
48+
private var cachedFixedComponentsLocales: [String /*ICU identifier*/: any _LocaleProtocol] = [:]
4949

5050
#if FOUNDATION_FRAMEWORK
5151
private var cachedFixedIdentifierToNSLocales: [String : _NSSwiftLocale] = [:]
@@ -99,17 +99,14 @@ struct LocaleCache : Sendable, ~Copyable {
9999

100100
#endif // FOUNDATION_FRAMEWORK
101101

102-
func fixedComponents(_ comps: Locale.Components) -> (any _LocaleProtocol)? {
103-
cachedFixedComponentsLocales[comps]
104-
}
105-
106102
mutating func fixedComponentsWithCache(_ comps: Locale.Components) -> any _LocaleProtocol {
107-
if let l = fixedComponents(comps) {
103+
let identifier = comps.icuIdentifier
104+
if let l = cachedFixedComponentsLocales[identifier] {
108105
return l
109106
} else {
110107
let new = _localeICUClass().init(components: comps)
111108

112-
cachedFixedComponentsLocales[comps] = new
109+
cachedFixedComponentsLocales[identifier] = new
113110
return new
114111
}
115112
}

Sources/FoundationInternationalization/Locale/Locale+Components_ICU.swift

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,34 +22,7 @@ internal import _FoundationICU
2222

2323
@available(macOS 13, iOS 16, tvOS 16, watchOS 9, *)
2424
extension Locale.Components {
25-
// Returns an ICU-style identifier like "de_DE@calendar=gregorian"
26-
internal var icuIdentifier: String {
27-
var keywords: [ICULegacyKey: String] = [:]
28-
if let id = calendar?.cldrIdentifier { keywords[Calendar.Identifier.legacyKeywordKey] = id }
29-
if let id = collation?._normalizedIdentifier { keywords[Locale.Collation.legacyKeywordKey] = id }
30-
if let id = currency?._normalizedIdentifier { keywords[Locale.Currency.legacyKeywordKey] = id }
31-
if let id = numberingSystem?._normalizedIdentifier { keywords[Locale.NumberingSystem.legacyKeywordKey] = id }
32-
if let id = firstDayOfWeek?.rawValue { keywords[Locale.Weekday.legacyKeywordKey] = id }
33-
if let id = hourCycle?.rawValue { keywords[Locale.HourCycle.legacyKeywordKey] = id }
34-
if let id = measurementSystem?._normalizedIdentifier { keywords[Locale.MeasurementSystem.legacyKeywordKey] = id }
35-
// No need for redundant region keyword
36-
if let region = region, region != languageComponents.region {
37-
// rg keyword value is actually a subdivision code
38-
keywords[Locale.Region.legacyKeywordKey] = Locale.Subdivision.subdivision(for: region)._normalizedIdentifier
39-
}
40-
if let id = subdivision?._normalizedIdentifier { keywords[Locale.Subdivision.legacyKeywordKey] = id }
41-
if let id = timeZone?.identifier { keywords[TimeZone.legacyKeywordKey] = id }
42-
if let id = variant?._normalizedIdentifier { keywords[Locale.Variant.legacyKeywordKey] = id }
43-
44-
var locID = languageComponents.identifier
45-
for (key, val) in keywords {
46-
// This uses legacy key-value pairs, like "collation=phonebook" instead of "-cu-phonebk", so be sure that the above values are `legacyKeywordKey`
47-
// See Locale.Components.legacyKey(forKey:) for more info on performance costs
48-
locID = Locale.identifierWithKeywordValue(locID, key: key, value: val)
49-
}
50-
return locID
51-
}
52-
25+
5326
/// - Parameter identifier: Unicode language identifier such as "en-u-nu-thai-ca-buddhist-kk-true"
5427
public init(identifier: String) {
5528
let languageComponents = Locale.Language.Components(identifier: identifier)

Sources/_FoundationCShims/include/_CStdlib.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,6 @@
101101
#include <stdlib.h>
102102
#endif
103103

104-
#if __has_include(<stdnoreturn.h>)
105-
#include <stdnoreturn.h>
106-
#endif
107-
108104
#if __has_include(<string.h>)
109105
#include <string.h>
110106
#endif
@@ -164,5 +160,10 @@
164160

165161
#endif
166162

163+
// Must be last to avoid conflicts with other headers on Windows.
164+
#if __has_include(<stdnoreturn.h>)
165+
#include <stdnoreturn.h>
166+
#endif
167+
167168
#endif // FOUNDATION_CSTDLIB
168169

0 commit comments

Comments
 (0)