Skip to content

Commit faaf2e4

Browse files
committed
Perception 2.0
1 parent 198ec7e commit faaf2e4

5 files changed

Lines changed: 44 additions & 23 deletions

File tree

Package.resolved

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ let package = Package(
2222
.package(url: "https://github.com/pointfreeco/swift-custom-dump", from: "1.0.0"),
2323
.package(url: "https://github.com/pointfreeco/swift-dependencies", from: "1.5.1"),
2424
.package(url: "https://github.com/pointfreeco/swift-identified-collections", from: "1.0.0"),
25-
.package(url: "https://github.com/pointfreeco/swift-perception", from: "1.4.1"),
25+
.package(url: "https://github.com/pointfreeco/swift-perception", branch: "swift-6-2"),
2626
.package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "1.4.3"),
2727
.package(url: "https://github.com/swiftlang/swift-docc-plugin", from: "1.0.0"),
2828
],

Package@swift-6.0.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ let package = Package(
2222
.package(url: "https://github.com/pointfreeco/swift-custom-dump", from: "1.0.0"),
2323
.package(url: "https://github.com/pointfreeco/swift-dependencies", from: "1.5.1"),
2424
.package(url: "https://github.com/pointfreeco/swift-identified-collections", from: "1.0.0"),
25-
.package(url: "https://github.com/pointfreeco/swift-perception", from: "1.4.1"),
25+
.package(url: "https://github.com/pointfreeco/swift-perception", branch: "swift-6-2"),
2626
.package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "1.4.3"),
2727
.package(url: "https://github.com/swiftlang/swift-docc-plugin", from: "1.0.0"),
2828
],

Sources/Sharing/Shared.swift

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -412,27 +412,38 @@ extension Shared: CustomStringConvertible {
412412

413413
extension Shared: Equatable where Value: Equatable {
414414
public static func == (lhs: Self, rhs: Self) -> Bool {
415-
func openLhs<T: MutableReference<Value>>(_ lhsReference: T) -> Bool {
416-
// NB: iOS <16 does not support casting this existential, so we must open it explicitly
417-
func openRhs<S: MutableReference<Value>>(_ rhsReference: S) -> Bool {
418-
lhsReference == rhsReference as? T
415+
// TODO: Explore 'isTesting ? (check snapshot against value) : lhs.reference == rhs.reference
416+
func isEqual() -> Bool {
417+
func openLhs<T: MutableReference<Value>>(_ lhsReference: T) -> Bool {
418+
// NB: iOS <16 does not support casting this existential, so we must open it explicitly
419+
func openRhs<S: MutableReference<Value>>(_ rhsReference: S) -> Bool {
420+
lhsReference == rhsReference as? T
421+
}
422+
return openRhs(rhs.reference)
423+
}
424+
@Dependency(\.snapshots) var snapshots
425+
if snapshots.isAsserting, openLhs(lhs.reference) {
426+
snapshots.untrack(lhs.reference)
427+
return lhs.wrappedValue == rhs.reference.wrappedValue
428+
} else {
429+
return lhs.wrappedValue == rhs.wrappedValue
419430
}
420-
return openRhs(rhs.reference)
421-
}
422-
@Dependency(\.snapshots) var snapshots
423-
if snapshots.isAsserting, openLhs(lhs.reference) {
424-
snapshots.untrack(lhs.reference)
425-
return lhs.wrappedValue == rhs.reference.wrappedValue
426-
} else {
427-
return lhs.wrappedValue == rhs.wrappedValue
428431
}
429-
// TODO: Explore 'isTesting ? (check snapshot against value) : lhs.reference == rhs.reference
432+
#if DEBUG
433+
return _PerceptionLocals.$skipPerceptionChecking.withValue(true, operation: isEqual)
434+
#else
435+
return isEqual()
436+
#endif
430437
}
431438
}
432439

433440
extension Shared: Identifiable where Value: Identifiable {
434441
public var id: Value.ID {
435-
wrappedValue.id
442+
#if DEBUG
443+
_PerceptionLocals.$skipPerceptionChecking.withValue(true) { wrappedValue.id }
444+
#else
445+
wrappedValue.id
446+
#endif
436447
}
437448
}
438449

Sources/Sharing/SharedReader.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,13 +301,23 @@ extension SharedReader: CustomStringConvertible {
301301

302302
extension SharedReader: Equatable where Value: Equatable {
303303
public static func == (lhs: Self, rhs: Self) -> Bool {
304-
lhs.wrappedValue == rhs.wrappedValue
304+
#if DEBUG
305+
_PerceptionLocals.$skipPerceptionChecking.withValue(true) {
306+
lhs.wrappedValue == rhs.wrappedValue
307+
}
308+
#else
309+
lhs.wrappedValue == rhs.wrappedValue
310+
#endif
305311
}
306312
}
307313

308314
extension SharedReader: Identifiable where Value: Identifiable {
309315
public var id: Value.ID {
310-
wrappedValue.id
316+
#if DEBUG
317+
_PerceptionLocals.$skipPerceptionChecking.withValue(true) { wrappedValue.id }
318+
#else
319+
wrappedValue.id
320+
#endif
311321
}
312322
}
313323

0 commit comments

Comments
 (0)