Sema: Avoid adding nonisolated twice to synthesized Hashable methods.

https://github.com/apple/swift/pull/42041 introduced a centralized mechanism for adding the `nonisolated` attribute to synthesized decls but did not clean up the existing code that was already doing so for `Hashable` conformances.

Resolves rdar://102106591
This commit is contained in:
Allan Shortlidge
2022-11-08 14:54:05 -08:00
parent 0592979c34
commit 7782f862c0
4 changed files with 31 additions and 15 deletions

View File

@@ -554,15 +554,13 @@ deriveHashable_hashInto(
/*Throws=*/false,
/*GenericParams=*/nullptr, params, returnType, parentDC);
hashDecl->setBodySynthesizer(bodySynthesizer);
addNonIsolatedToSynthesized(derived.Nominal, hashDecl);
hashDecl->copyFormalAccessFrom(derived.Nominal,
/*sourceIsParentContext=*/true);
// The derived hash(into:) for an actor must be non-isolated.
if (derived.Nominal->isActor() ||
getActorIsolation(derived.Nominal) == ActorIsolation::GlobalActor) {
hashDecl->getAttrs().add(new (C) NonisolatedAttr(/*IsImplicit*/true));
}
if (!addNonIsolatedToSynthesized(derived.Nominal, hashDecl) &&
derived.Nominal->isActor())
hashDecl->getAttrs().add(new (C) NonisolatedAttr(/*IsImplicit*/ true));
derived.addMembersToConformanceContext({hashDecl});
@@ -891,7 +889,6 @@ static ValueDecl *deriveHashable_hashValue(DerivedConformance &derived) {
SourceLoc(), C.Id_hashValue, parentDC);
hashValueDecl->setInterfaceType(intType);
hashValueDecl->setSynthesized();
addNonIsolatedToSynthesized(derived.Nominal, hashValueDecl);
ParameterList *params = ParameterList::createEmpty(C);
@@ -918,10 +915,9 @@ static ValueDecl *deriveHashable_hashValue(DerivedConformance &derived) {
/*sourceIsParentContext*/ true);
// The derived hashValue of an actor must be nonisolated.
if (derived.Nominal->isActor() ||
getActorIsolation(derived.Nominal) == ActorIsolation::GlobalActor) {
hashValueDecl->getAttrs().add(new (C) NonisolatedAttr(/*IsImplicit*/true));
}
if (!addNonIsolatedToSynthesized(derived.Nominal, hashValueDecl) &&
derived.Nominal->isActor())
hashValueDecl->getAttrs().add(new (C) NonisolatedAttr(/*IsImplicit*/ true));
Pattern *hashValuePat = NamedPattern::createImplicit(C, hashValueDecl);
hashValuePat->setType(intType);