Skip to content

Commit 6ee5774

Browse files
authored
Merge pull request #25349 from slavapestov/synthesized-hashValue-abi-break
Sema: Go back to synthesizing hashValue on _StoredBridgedNSError conformers
2 parents 4a85892 + 712927c commit 6ee5774

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

lib/Sema/DerivedConformanceEquatableHashable.cpp

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

11261126
// return _hashValue(for: self)
11271127
auto *hashFunc = C.getHashValueForDecl();
1128-
auto hashExpr = new (C) DeclRefExpr(hashFunc, DeclNameLoc(),
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(),
11291142
/*implicit*/ true);
1143+
1144+
Type intType = C.getIntDecl()->getDeclaredType();
1145+
hashExpr->setType(FunctionType::get(AnyFunctionType::Param(selfType),
1146+
intType));
1147+
11301148
auto selfDecl = hashValueDecl->getImplicitSelfDecl();
11311149
auto selfRef = new (C) DeclRefExpr(selfDecl, DeclNameLoc(),
11321150
/*implicit*/ true);
1133-
auto callExpr = CallExpr::createImplicit(C, hashExpr,
1134-
{ selfRef }, { C.Id_for });
1151+
selfRef->setType(selfType);
1152+
1153+
auto callExpr = CallExpr::createImplicit(C, hashExpr, { selfRef }, { });
1154+
callExpr->setType(intType);
1155+
callExpr->setThrows(false);
1156+
11351157
auto returnStmt = new (C) ReturnStmt(SourceLoc(), callExpr);
11361158

11371159
auto body = BraceStmt::create(C, SourceLoc(), {returnStmt}, SourceLoc(),
11381160
/*implicit*/ true);
11391161
hashValueDecl->setBody(body);
1162+
hashValueDecl->setBodyTypeCheckedIfPresent();
11401163
}
11411164

11421165
/// Derive a 'hashValue' implementation.

stdlib/public/Darwin/Foundation/NSError.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -489,10 +489,6 @@ 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-
}
496492
}
497493

498494
/// Describes the code of an error.

0 commit comments

Comments
 (0)