Skip to content

Commit 41e7b7c

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 e0b8a92 commit 41e7b7c

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
@@ -1339,18 +1339,15 @@ extension AnySequence {
13391339
}
13401340
}
13411341

1342-
// ABI-only entrypoint
1342+
// ABI-only entrypoint for the rethrows version of map, which has been
1343+
// superseded by the typed-throws version. Expressed as "throws", which is
1344+
// ABI-compatible with "rethrows".
13431345
@usableFromInline
1344-
@_disfavoredOverload
1345-
func map<T>(
1346+
@_silgen_name("$ss11AnySequenceV3mapySayqd__Gqd__xKXEKlF")
1347+
func __rethrows_map<T>(
13461348
_ transform: (Element) throws -> T
1347-
) rethrows -> [T] {
1348-
do {
1349-
return try map(transform)
1350-
} catch {
1351-
try _rethrowsViaClosure { throw error }
1352-
Builtin.unreachable()
1353-
}
1349+
) throws -> [T] {
1350+
try map(transform)
13541351
}
13551352

13561353
@inlinable
@@ -1445,18 +1442,15 @@ extension AnyCollection {
14451442
}
14461443
}
14471444

1448-
// ABI-only entrypoint
1445+
// ABI-only entrypoint for the rethrows version of map, which has been
1446+
// superseded by the typed-throws version. Expressed as "throws", which is
1447+
// ABI-compatible with "rethrows".
14491448
@usableFromInline
1450-
@_disfavoredOverload
1451-
func map<T>(
1449+
@_silgen_name("$ss13AnyCollectionV3mapySayqd__Gqd__xKXEKlF")
1450+
func __rethrows_map<T>(
14521451
_ transform: (Element) throws -> T
1453-
) rethrows -> [T] {
1454-
do {
1455-
return try map(transform)
1456-
} catch {
1457-
try _rethrowsViaClosure { throw error }
1458-
Builtin.unreachable()
1459-
}
1452+
) throws -> [T] {
1453+
try map(transform)
14601454
}
14611455

14621456
@inlinable
@@ -1557,18 +1551,15 @@ extension AnyBidirectionalCollection {
15571551
}
15581552
}
15591553

1560-
// ABI-only entrypoint
1554+
// ABI-only entrypoint for the rethrows version of map, which has been
1555+
// superseded by the typed-throws version. Expressed as "throws", which is
1556+
// ABI-compatible with "rethrows".
15611557
@usableFromInline
1562-
@_disfavoredOverload
1563-
func map<T>(
1558+
@_silgen_name("$ss26AnyBidirectionalCollectionV3mapySayqd__Gqd__xKXEKlF")
1559+
func __rethrows_map<T>(
15641560
_ transform: (Element) throws -> T
1565-
) rethrows -> [T] {
1566-
do {
1567-
return try map(transform)
1568-
} catch {
1569-
try _rethrowsViaClosure { throw error }
1570-
Builtin.unreachable()
1571-
}
1561+
) throws -> [T] {
1562+
try map(transform)
15721563
}
15731564

15741565
@inlinable
@@ -1671,18 +1662,15 @@ extension AnyRandomAccessCollection {
16711662
}
16721663
}
16731664

1674-
// ABI-only entrypoint
1665+
// ABI-only entrypoint for the rethrows version of map, which has been
1666+
// superseded by the typed-throws version. Expressed as "throws", which is
1667+
// ABI-compatible with "rethrows".
16751668
@usableFromInline
1676-
@_disfavoredOverload
1677-
func map<T>(
1669+
@_silgen_name("$ss25AnyRandomAccessCollectionV3mapySayqd__Gqd__xKXEKlF")
1670+
func __rethrows_map<T>(
16781671
_ transform: (Element) throws -> T
1679-
) rethrows -> [T] {
1680-
do {
1681-
return try map(transform)
1682-
} catch {
1683-
try _rethrowsViaClosure { throw error }
1684-
Builtin.unreachable()
1685-
}
1672+
) throws -> [T] {
1673+
try map(transform)
16861674
}
16871675

16881676
@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)