Skip to content

Make SwiftValue == support unconditional #73552

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions stdlib/public/runtime/SwiftValue.mm
Original file line number Diff line number Diff line change
Expand Up @@ -430,10 +430,10 @@ - (BOOL)isEqual:(id)other {
}
}

if (runtime::bincompat::useLegacySwiftObjCHashing()) {
// Legacy behavior only proxies isEqual: for Hashable, not Equatable
return NO;
}
// if (runtime::bincompat::useLegacySwiftObjCHashing()) {
// // Legacy behavior only proxies isEqual: for Hashable, not Equatable
// return NO;
// }

if (auto equatableConformance = selfHeader->getEquatableConformance()) {
if (auto selfEquatableBaseType = selfHeader->getEquatableBaseType()) {
Expand Down Expand Up @@ -464,10 +464,10 @@ - (NSUInteger)hash {
selfHeader->type, hashableConformance);
}

if (runtime::bincompat::useLegacySwiftObjCHashing()) {
// Legacy behavior doesn't honor Equatable conformance, only Hashable
return (NSUInteger)self;
}
// if (runtime::bincompat::useLegacySwiftObjCHashing()) {
// // Legacy behavior doesn't honor Equatable conformance, only Hashable
// return (NSUInteger)self;
// }

// If Swift type is Equatable but not Hashable,
// we have to return something here that is compatible
Expand Down
5 changes: 0 additions & 5 deletions test/stdlib/BridgeEquatableToObjC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,7 @@ BridgeEquatableToObjC.test("Bridge equatable struct") {
let objcResult = objcA.isEqual(objcB)

expectEqual(swiftResult, true)
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) || os(visionOS)
// Apple platforms use old semantics for now...
expectEqual(objcResult, false)
#else
expectEqual(objcResult, true)
#endif
}

BridgeEquatableToObjC.test("Bridge non-equatable struct") {
Expand Down
11 changes: 0 additions & 11 deletions test/stdlib/SwiftValueNSObject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,7 @@ func TestHashableEquals<T: Equatable>(_ e1: T, _ e2: T) {
// This has not always been true for Equatable value types
func TestEquatableEquals<T: Equatable>(_ e1: T, _ e2: T) {
if e1 == e2 {
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) || os(visionOS)
// Legacy: Swift Equatable is not used in ObjC
TestSwiftValueNSObjectNotEquals(e1 as AnyObject, e2 as AnyObject)
#else
TestSwiftValueNSObjectEquals(e1 as AnyObject, e2 as AnyObject)
#endif
} else {
TestSwiftValueNSObjectNotEquals(e1 as AnyObject, e2 as AnyObject)
}
Expand All @@ -114,14 +109,8 @@ func TestHashable<T: Hashable>(_ h: T)
// Test Obj-C hashValue for Swift types that are Equatable but not Hashable
func TestEquatableHash<T: Equatable>(_ e: T)
{
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(visionOS)
// Legacy behavior used the pointer value, which is
// incompatible with user-defined equality.
TestSwiftValueNSObjectDefaultHashValue(e as AnyObject)
#else
// New behavior uses a constant hash value in this case
TestSwiftValueNSObjectHashValue(e as AnyObject, 1)
#endif
}

func TestNonEquatableHash<T>(_ e: T)
Expand Down