Skip to content

Commit 6078dda

Browse files
kperryuaCharles Hu
authored andcommitted
rdar://152532669 (Work around inefficient compiler-synthesized Codable conformance of enums)
1 parent 2d2e249 commit 6078dda

File tree

11 files changed

+94
-0
lines changed

11 files changed

+94
-0
lines changed

Sources/FoundationEssentials/AttributedString/FoundationAttributes.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,11 @@ extension AttributeScopes.FoundationAttributes {
520520
case spelledOutValue
521521
case unit(Unit)
522522
case actualByteCount
523+
524+
private typealias ValueCodingKeys = EmptyCodingKeys
525+
private typealias SpelledOutValueCodingKeys = EmptyCodingKeys
526+
private typealias UnitCodingKeys = DefaultAssociatedValueCodingKeys1
527+
private typealias ActualByteCountCodingKeys = EmptyCodingKeys
523528
}
524529

525530
public enum Unit: Codable, Sendable {
@@ -532,6 +537,16 @@ extension AttributeScopes.FoundationAttributes {
532537
case eb
533538
case zb
534539
case yb
540+
541+
private typealias ByteCodingKeys = EmptyCodingKeys
542+
private typealias KbCodingKeys = EmptyCodingKeys
543+
private typealias MbCodingKeys = EmptyCodingKeys
544+
private typealias GbCodingKeys = EmptyCodingKeys
545+
private typealias TbCodingKeys = EmptyCodingKeys
546+
private typealias PbCodingKeys = EmptyCodingKeys
547+
private typealias EbCodingKeys = EmptyCodingKeys
548+
private typealias ZbCodingKeys = EmptyCodingKeys
549+
private typealias YbCodingKeys = EmptyCodingKeys
535550
}
536551
}
537552

@@ -583,6 +598,11 @@ extension AttributeScopes.FoundationAttributes {
583598
case int(Int64)
584599
case double(Double)
585600
case decimal(Decimal)
601+
602+
private typealias UintCodingKeys = DefaultAssociatedValueCodingKeys1
603+
private typealias IntCodingKeys = DefaultAssociatedValueCodingKeys1
604+
private typealias DoubleCodingKeys = DefaultAssociatedValueCodingKeys1
605+
private typealias DecimalCodingKeys = DefaultAssociatedValueCodingKeys1
586606
}
587607
}
588608

@@ -941,5 +961,8 @@ extension AttributedString {
941961
/// - Note: In vertical scripts, this equivalent to a bottom-to-top
942962
/// writing direction.
943963
case rightToLeft
964+
965+
private typealias LeftToRightCodingKeys = EmptyCodingKeys
966+
private typealias RightToLeftCodingKeys = EmptyCodingKeys
944967
}
945968
}

Sources/FoundationEssentials/Calendar/Calendar.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,34 @@ public struct Calendar : Hashable, Equatable, Sendable {
9494

9595
@available(FoundationPreview 6.2, *)
9696
case vietnamese
97+
98+
private typealias GregorianCodingKeys = EmptyCodingKeys
99+
private typealias ChineseCodingKeys = EmptyCodingKeys
100+
private typealias BuddhistCodingKeys = EmptyCodingKeys
101+
private typealias CopticCodingKeys = EmptyCodingKeys
102+
private typealias EthiopicAmeteMihretCodingKeys = EmptyCodingKeys
103+
private typealias EthiopicAmeteAlemCodingKeys = EmptyCodingKeys
104+
private typealias HebrewCodingKeys = EmptyCodingKeys
105+
private typealias Iso8601CodingKeys = EmptyCodingKeys
106+
private typealias IndianCodingKeys = EmptyCodingKeys
107+
private typealias IslamicCodingKeys = EmptyCodingKeys
108+
private typealias IslamicCivilCodingKeys = EmptyCodingKeys
109+
private typealias JapaneseCodingKeys = EmptyCodingKeys
110+
private typealias PersianCodingKeys = EmptyCodingKeys
111+
private typealias RepublicOfChinaCodingKeys = EmptyCodingKeys
112+
private typealias IslamicTabularCodingKeys = EmptyCodingKeys
113+
private typealias IslamicUmmAlQuraCodingKeys = EmptyCodingKeys
114+
private typealias BanglaCodingKeys = EmptyCodingKeys
115+
private typealias GujaratiCodingKeys = EmptyCodingKeys
116+
private typealias KannadaCodingKeys = EmptyCodingKeys
117+
private typealias MalayalamCodingKeys = EmptyCodingKeys
118+
private typealias MarathiCodingKeys = EmptyCodingKeys
119+
private typealias OdiaCodingKeys = EmptyCodingKeys
120+
private typealias TamilCodingKeys = EmptyCodingKeys
121+
private typealias TeluguCodingKeys = EmptyCodingKeys
122+
private typealias VikramCodingKeys = EmptyCodingKeys
123+
private typealias DangiCodingKeys = EmptyCodingKeys
124+
private typealias VietnameseCodingKeys = EmptyCodingKeys
97125

98126
package static let cldrKeywordKey = "ca"
99127
package static let legacyKeywordKey = ICULegacyKey("calendar")

Sources/FoundationEssentials/CodableUtilities.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,3 +687,14 @@ extension BufferView where Element == UInt8 {
687687
}
688688
}
689689

690+
// Non-RawRepresentable Codable enum cases with the same number and labels of associated values all share equivalent CodingKeys, but the compiler-synthesized implementation generates a new type for each case.
691+
// Each of these types has their own set of `metadata instantiation cache for protocol conformance descriptor` symbols for each of 5 protocol conformances which consumes DATA space.
692+
// Instead of using the synthesized CodingKey types, you can make a `private typealias <CaseName>CodingKeys = <one of these types>` inside the Codable enum to reduce the amount of redundant DATA.
693+
package enum EmptyCodingKeys: CodingKey { }
694+
package enum DefaultAssociatedValueCodingKeys1: String, CodingKey {
695+
case _0
696+
}
697+
package enum DefaultAssociatedValueCodingKeys2: String, CodingKey {
698+
case _0
699+
case _1
700+
}

Sources/FoundationEssentials/Predicate/Expressions/Arithmetic.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
extension PredicateExpressions {
1515
public enum ArithmeticOperator: Codable, Sendable {
1616
case add, subtract, multiply
17+
18+
private typealias AddCodingKeys = EmptyCodingKeys
19+
private typealias SubtractCodingKeys = EmptyCodingKeys
20+
private typealias MultiplyCodingKeys = EmptyCodingKeys
1721
}
1822

1923
public struct Arithmetic<

Sources/FoundationEssentials/Predicate/Expressions/Comparison.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
extension PredicateExpressions {
1515
public enum ComparisonOperator: Codable, Sendable {
1616
case lessThan, lessThanOrEqual, greaterThan, greaterThanOrEqual
17+
18+
private typealias LessThanCodingKeys = EmptyCodingKeys
19+
private typealias LessThanOrEqualCodingKeys = EmptyCodingKeys
20+
private typealias GreaterThanCodingKeys = EmptyCodingKeys
21+
private typealias GreaterThanOrEqualCodingKeys = EmptyCodingKeys
1722
}
1823

1924
public struct Comparison<

Sources/FoundationInternationalization/Formatting/Date/Date+RelativeFormatStyle.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ extension Date {
150150
enum ComponentAdjustmentStrategy : Codable, Hashable {
151151
case alignedWithComponentBoundary
152152
case rounded
153+
154+
private typealias AlignedWithComponentBoundaryCodingKeys = EmptyCodingKeys
155+
private typealias RoundedCodingKeys = EmptyCodingKeys
153156
}
154157

155158
var componentAdjustmentStrategy: ComponentAdjustmentStrategy {

Sources/FoundationInternationalization/Formatting/Date/DateFormatStyle.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,11 @@ extension Date {
297297
enum InnerStyle: Codable, Hashable {
298298
case formatStyle(Date.FormatStyle)
299299
case verbatimFormatStyle(VerbatimFormatStyle)
300+
301+
private typealias FormatStyleCodingKeys = DefaultAssociatedValueCodingKeys1
302+
private typealias VerbatimFormatStyleCodingKeys = DefaultAssociatedValueCodingKeys1
300303
}
304+
301305
var innerStyle: InnerStyle
302306

303307
init(style: InnerStyle) {

Sources/FoundationInternationalization/Formatting/Number/Decimal+FormatStyle.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,10 @@ extension Decimal.FormatStyle {
267267
case decimal(Decimal.FormatStyle)
268268
case currency(Decimal.FormatStyle.Currency)
269269
case percent(Decimal.FormatStyle.Percent)
270+
271+
private typealias DecimalCodingKeys = DefaultAssociatedValueCodingKeys1
272+
private typealias CurrencyCodingKeys = DefaultAssociatedValueCodingKeys1
273+
private typealias PercentCodingKeys = DefaultAssociatedValueCodingKeys1
270274
}
271275

272276
var style: Style

Sources/FoundationInternationalization/Formatting/Number/FloatingPointFormatStyle.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,10 @@ extension FloatingPointFormatStyle {
344344
case floatingPoint(FloatingPointFormatStyle)
345345
case currency(FloatingPointFormatStyle.Currency)
346346
case percent(FloatingPointFormatStyle.Percent)
347+
348+
private typealias FloatingPointCodingKeys = DefaultAssociatedValueCodingKeys1
349+
private typealias CurrencyCodingKeys = DefaultAssociatedValueCodingKeys1
350+
private typealias PercentCodingKeys = DefaultAssociatedValueCodingKeys1
347351

348352
var formatter: ICUNumberFormatterBase? {
349353
switch self {

Sources/FoundationInternationalization/Formatting/Number/ICULegacyNumberFormatter.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ internal final class ICULegacyNumberFormatter : @unchecked Sendable {
125125
case percent(NumberFormatStyleConfiguration.Collection)
126126
case currency(CurrencyFormatStyleConfiguration.Collection, currencyCode: String)
127127
case descriptive(DescriptiveNumberFormatConfiguration.Collection)
128+
129+
private typealias NumberCodingKeys = DefaultAssociatedValueCodingKeys1
130+
private typealias PercentCodingKeys = DefaultAssociatedValueCodingKeys1
131+
private typealias DescriptiveCodingKeys = DefaultAssociatedValueCodingKeys1
128132
}
129133

130134
private struct Signature : Hashable {

0 commit comments

Comments
 (0)