Skip to content

Commit f9324d8

Browse files
authored
Merge pull request #25361 from slavapestov/simpler-hash-value-abi-break-fix
Simpler fix for Foundation overlay ABI break
2 parents 81156b2 + 67fd1f2 commit f9324d8

File tree

2 files changed

+23
-26
lines changed

2 files changed

+23
-26
lines changed

lib/Sema/DerivedConformanceEquatableHashable.cpp

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,41 +1125,18 @@ deriveBodyHashable_hashValue(AbstractFunctionDecl *hashValueDecl, void *) {
11251125

11261126
// return _hashValue(for: self)
11271127
auto *hashFunc = C.getHashValueForDecl();
1128-
if (!hashFunc->hasInterfaceType())
1129-
C.getLazyResolver()->resolveDeclSignature(hashFunc);
1130-
1131-
auto selfType = hashValueDecl->mapTypeIntoContext(
1132-
parentDC->getSelfInterfaceType());
1133-
auto hashableProto = C.getProtocol(KnownProtocolKind::Hashable);
1134-
auto conformance = TypeChecker::conformsToProtocol(selfType, hashableProto,
1135-
parentDC, None);
1136-
auto subs = SubstitutionMap::get(hashFunc->getGenericSignature(),
1137-
ArrayRef<Type>(selfType),
1138-
ArrayRef<ProtocolConformanceRef>(*conformance));
1139-
ConcreteDeclRef hashRef(hashFunc, subs);
1140-
1141-
auto hashExpr = new (C) DeclRefExpr(hashRef, DeclNameLoc(),
1128+
auto hashExpr = new (C) DeclRefExpr(hashFunc, DeclNameLoc(),
11421129
/*implicit*/ true);
1143-
1144-
Type intType = C.getIntDecl()->getDeclaredType();
1145-
hashExpr->setType(FunctionType::get(AnyFunctionType::Param(selfType),
1146-
intType));
1147-
11481130
auto selfDecl = hashValueDecl->getImplicitSelfDecl();
11491131
auto selfRef = new (C) DeclRefExpr(selfDecl, DeclNameLoc(),
11501132
/*implicit*/ true);
1151-
selfRef->setType(selfType);
1152-
1153-
auto callExpr = CallExpr::createImplicit(C, hashExpr, { selfRef }, { });
1154-
callExpr->setType(intType);
1155-
callExpr->setThrows(false);
1156-
1133+
auto callExpr = CallExpr::createImplicit(C, hashExpr,
1134+
{ selfRef }, { C.Id_for });
11571135
auto returnStmt = new (C) ReturnStmt(SourceLoc(), callExpr);
11581136

11591137
auto body = BraceStmt::create(C, SourceLoc(), {returnStmt}, SourceLoc(),
11601138
/*implicit*/ true);
11611139
hashValueDecl->setBody(body);
1162-
hashValueDecl->setBodyTypeCheckedIfPresent();
11631140
}
11641141

11651142
/// Derive a 'hashValue' implementation.

stdlib/public/Darwin/Foundation/NSError.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,10 @@ extension _BridgedStoredNSError {
489489
public func hash(into hasher: inout Hasher) {
490490
hasher.combine(_nsError)
491491
}
492+
493+
@_alwaysEmitIntoClient public var hashValue: Int {
494+
return _nsError.hashValue
495+
}
492496
}
493497

494498
/// Describes the code of an error.
@@ -564,6 +568,10 @@ public struct CocoaError : _BridgedStoredNSError {
564568

565569
public static var errorDomain: String { return NSCocoaErrorDomain }
566570

571+
public var hashValue: Int {
572+
return _nsError.hashValue
573+
}
574+
567575
/// The error code itself.
568576
public struct Code : RawRepresentable, Hashable, _ErrorCodeProtocol {
569577
public typealias _ErrorType = CocoaError
@@ -1791,6 +1799,10 @@ public struct URLError : _BridgedStoredNSError {
17911799

17921800
public static var errorDomain: String { return NSURLErrorDomain }
17931801

1802+
public var hashValue: Int {
1803+
return _nsError.hashValue
1804+
}
1805+
17941806
/// The error code itself.
17951807
public struct Code : RawRepresentable, Hashable, _ErrorCodeProtocol {
17961808
public typealias _ErrorType = URLError
@@ -2447,6 +2459,10 @@ public struct POSIXError : _BridgedStoredNSError {
24472459

24482460
public static var errorDomain: String { return NSPOSIXErrorDomain }
24492461

2462+
public var hashValue: Int {
2463+
return _nsError.hashValue
2464+
}
2465+
24502466
public typealias Code = POSIXErrorCode
24512467
}
24522468

@@ -2933,6 +2949,10 @@ public struct MachError : _BridgedStoredNSError {
29332949

29342950
public static var errorDomain: String { return NSMachErrorDomain }
29352951

2952+
public var hashValue: Int {
2953+
return _nsError.hashValue
2954+
}
2955+
29362956
public typealias Code = MachErrorCode
29372957
}
29382958

0 commit comments

Comments
 (0)