Skip to content

Commit f9bfd81

Browse files
committed
Fix a merge conflict on main-next.
This PR fixes a conflict between #610 and #619. #610 added a string cache to `TypeInfo` using `ObjectIdentifier` instances as keys. #619 added support for move-only types to `TypeInfo`. Due to rdar://134276458, move-only types cannot be used with `ObjectIdentifier`. This PR uses `UInt` instead until that issue can be resolved in a future stdlib update.
1 parent bba4bdf commit f9bfd81

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

Sources/Testing/Parameterization/TypeInfo.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ public struct TypeInfo: Sendable {
7575

7676
extension TypeInfo {
7777
/// An in-memory cache of fully-qualified type name components.
78-
private static let _fullyQualifiedNameComponentsCache = Locked<[ObjectIdentifier: [String]]>()
78+
///
79+
/// - Bug: The key type of this cache should be `ObjectIdentifier`, but such
80+
/// values cannot be constructed from move-only types.
81+
/// ([134276458](rdar://134276458))
82+
private static let _fullyQualifiedNameComponentsCache = Locked<[UInt: [String]]>()
7983

8084
/// The complete name of this type, with the names of all referenced types
8185
/// fully-qualified by their module names when possible.
@@ -95,7 +99,8 @@ extension TypeInfo {
9599
public var fullyQualifiedNameComponents: [String] {
96100
switch _kind {
97101
case let .type(type):
98-
if let cachedResult = Self._fullyQualifiedNameComponentsCache.rawValue[ObjectIdentifier(type)] {
102+
let cacheKey = unsafeBitCast(type, to: UInt.self)
103+
if let cachedResult = Self._fullyQualifiedNameComponentsCache.rawValue[cacheKey] {
99104
return cachedResult
100105
}
101106

@@ -117,7 +122,7 @@ extension TypeInfo {
117122
result = result.filter { !$0.starts(with: "(unknown context at") }
118123

119124
Self._fullyQualifiedNameComponentsCache.withLock { fullyQualifiedNameComponentsCache in
120-
fullyQualifiedNameComponentsCache[ObjectIdentifier(type)] = result
125+
fullyQualifiedNameComponentsCache[cacheKey] = result
121126
}
122127

123128
return result
@@ -314,7 +319,7 @@ extension TypeInfo: Hashable {
314319
case let (.type(lhs), .type(rhs)):
315320
// == and ObjectIdentifier do not support move-only metatypes, so compare
316321
// the bits of the types directly. SEE: rdar://134276458
317-
return unsafeBitCast(lhs, to: UnsafeRawPointer.self) == unsafeBitCast(rhs, to: UnsafeRawPointer.self)
322+
return unsafeBitCast(lhs, to: UInt.self) == unsafeBitCast(rhs, to: UInt.self)
318323
default:
319324
return lhs.fullyQualifiedNameComponents == rhs.fullyQualifiedNameComponents
320325
}

0 commit comments

Comments
 (0)