Skip to content

Commit 077d828

Browse files
committed
Improve ABI-only rethrowing map shims based on code review
Replace the hackish use of `@_disfavoredOverload` with the more principled use of `@_silgen_name` for the entrypoint we are maintaining, then rename these functions in source to `__rethrows_map` to indicate what they're for. While here, make them `throws` instead of `rethrows`. The ABI is the same, and `throws` allows us do avoid to do/catch tricks with rethrows functions.
1 parent 24a1828 commit 077d828

File tree

3 files changed

+42
-60
lines changed

3 files changed

+42
-60
lines changed

stdlib/public/core/Collection.swift

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,18 +1214,15 @@ extension Collection {
12141214
return Array(result)
12151215
}
12161216

1217-
// ABI-only entrypoint
1217+
// ABI-only entrypoint for the rethrows version of map, which has been
1218+
// superseded by the typed-throws version. Expressed as "throws", which is
1219+
// ABI-compatible with "rethrows".
12181220
@usableFromInline
1219-
@_disfavoredOverload
1220-
func map<T>(
1221+
@_silgen_name("$sSlsE3mapySayqd__Gqd__7ElementQzKXEKlF")
1222+
func __rethrows_map<T>(
12211223
_ transform: (Element) throws -> T
1222-
) rethrows -> [T] {
1223-
do {
1224-
return try map(transform)
1225-
} catch {
1226-
try _rethrowsViaClosure { throw error }
1227-
Builtin.unreachable()
1228-
}
1224+
) throws -> [T] {
1225+
try map(transform)
12291226
}
12301227

12311228
/// Returns a subsequence containing all but the given number of initial

stdlib/public/core/ExistentialCollection.swift

Lines changed: 28 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,18 +1334,15 @@ extension AnySequence {
13341334
}
13351335
}
13361336

1337-
// ABI-only entrypoint
1337+
// ABI-only entrypoint for the rethrows version of map, which has been
1338+
// superseded by the typed-throws version. Expressed as "throws", which is
1339+
// ABI-compatible with "rethrows".
13381340
@usableFromInline
1339-
@_disfavoredOverload
1340-
func map<T>(
1341+
@_silgen_name("$ss11AnySequenceV3mapySayqd__Gqd__xKXEKlF")
1342+
func __rethrows_map<T>(
13411343
_ transform: (Element) throws -> T
1342-
) rethrows -> [T] {
1343-
do {
1344-
return try map(transform)
1345-
} catch {
1346-
try _rethrowsViaClosure { throw error }
1347-
Builtin.unreachable()
1348-
}
1344+
) throws -> [T] {
1345+
try map(transform)
13491346
}
13501347

13511348
@inlinable
@@ -1440,18 +1437,15 @@ extension AnyCollection {
14401437
}
14411438
}
14421439

1443-
// ABI-only entrypoint
1440+
// ABI-only entrypoint for the rethrows version of map, which has been
1441+
// superseded by the typed-throws version. Expressed as "throws", which is
1442+
// ABI-compatible with "rethrows".
14441443
@usableFromInline
1445-
@_disfavoredOverload
1446-
func map<T>(
1444+
@_silgen_name("$ss13AnyCollectionV3mapySayqd__Gqd__xKXEKlF")
1445+
func __rethrows_map<T>(
14471446
_ transform: (Element) throws -> T
1448-
) rethrows -> [T] {
1449-
do {
1450-
return try map(transform)
1451-
} catch {
1452-
try _rethrowsViaClosure { throw error }
1453-
Builtin.unreachable()
1454-
}
1447+
) throws -> [T] {
1448+
try map(transform)
14551449
}
14561450

14571451
@inlinable
@@ -1552,18 +1546,15 @@ extension AnyBidirectionalCollection {
15521546
}
15531547
}
15541548

1555-
// ABI-only entrypoint
1549+
// ABI-only entrypoint for the rethrows version of map, which has been
1550+
// superseded by the typed-throws version. Expressed as "throws", which is
1551+
// ABI-compatible with "rethrows".
15561552
@usableFromInline
1557-
@_disfavoredOverload
1558-
func map<T>(
1553+
@_silgen_name("$ss26AnyBidirectionalCollectionV3mapySayqd__Gqd__xKXEKlF")
1554+
func __rethrows_map<T>(
15591555
_ transform: (Element) throws -> T
1560-
) rethrows -> [T] {
1561-
do {
1562-
return try map(transform)
1563-
} catch {
1564-
try _rethrowsViaClosure { throw error }
1565-
Builtin.unreachable()
1566-
}
1556+
) throws -> [T] {
1557+
try map(transform)
15671558
}
15681559

15691560
@inlinable
@@ -1666,18 +1657,15 @@ extension AnyRandomAccessCollection {
16661657
}
16671658
}
16681659

1669-
// ABI-only entrypoint
1660+
// ABI-only entrypoint for the rethrows version of map, which has been
1661+
// superseded by the typed-throws version. Expressed as "throws", which is
1662+
// ABI-compatible with "rethrows".
16701663
@usableFromInline
1671-
@_disfavoredOverload
1672-
func map<T>(
1664+
@_silgen_name("$ss25AnyRandomAccessCollectionV3mapySayqd__Gqd__xKXEKlF")
1665+
func __rethrows_map<T>(
16731666
_ transform: (Element) throws -> T
1674-
) rethrows -> [T] {
1675-
do {
1676-
return try map(transform)
1677-
} catch {
1678-
try _rethrowsViaClosure { throw error }
1679-
Builtin.unreachable()
1680-
}
1667+
) throws -> [T] {
1668+
try map(transform)
16811669
}
16821670

16831671
@inlinable

stdlib/public/core/Sequence.swift

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -691,18 +691,15 @@ extension Sequence {
691691
return Array(result)
692692
}
693693

694-
// ABI-only entrypoint
694+
// ABI-only entrypoint for the rethrows version of map, which has been
695+
// superseded by the typed-throws version. Expressed as "throws", which is
696+
// ABI-compatible with "rethrows".
695697
@usableFromInline
696-
@_disfavoredOverload
697-
func map<T>(
698+
@_silgen_name("$sSTsE3mapySayqd__Gqd__7ElementQzKXEKlF")
699+
func __rethrows_map<T>(
698700
_ transform: (Element) throws -> T
699-
) rethrows -> [T] {
700-
do {
701-
return try map(transform)
702-
} catch {
703-
try _rethrowsViaClosure { throw error }
704-
Builtin.unreachable()
705-
}
701+
) throws -> [T] {
702+
try map(transform)
706703
}
707704

708705
/// Returns an array containing, in order, the elements of the sequence

0 commit comments

Comments
 (0)