Skip to content

Commit f10a481

Browse files
committed
[Sema] NFC: Add a variant of addNonIsolatedToSynthesized that checks for @preconcurrency conformances
If derived conformance is marked as `@preconcurrency` instead of marking synthesized members as `nonisolated` the compiler should insert dynamic checks.
1 parent fba8095 commit f10a481

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/Sema/CodeSynthesis.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "TypeCheckObjC.h"
2222
#include "TypeCheckType.h"
2323
#include "TypeChecker.h"
24+
#include "DerivedConformances.h"
2425
#include "swift/AST/ASTMangler.h"
2526
#include "swift/AST/ASTPrinter.h"
2627
#include "swift/AST/AvailabilityInference.h"
@@ -1728,6 +1729,15 @@ bool swift::hasLetStoredPropertyWithInitialValue(NominalTypeDecl *nominal) {
17281729
});
17291730
}
17301731

1732+
bool swift::addNonIsolatedToSynthesized(DerivedConformance &derived,
1733+
ValueDecl *value) {
1734+
if (auto *conformance = derived.Conformance) {
1735+
if (conformance && conformance->isPreconcurrency())
1736+
return false;
1737+
}
1738+
return addNonIsolatedToSynthesized(derived.Nominal, value);
1739+
}
1740+
17311741
bool swift::addNonIsolatedToSynthesized(NominalTypeDecl *nominal,
17321742
ValueDecl *value) {
17331743
if (!getActorIsolation(nominal).isActorIsolated())

lib/Sema/CodeSynthesis.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class ParamDecl;
4141
class Type;
4242
class ValueDecl;
4343
class VarDecl;
44+
class DerivedConformance;
4445

4546
enum class SelfAccessorKind {
4647
/// We're building a derived accessor on top of whatever this
@@ -85,6 +86,11 @@ ValueDecl *getProtocolRequirement(ProtocolDecl *protocol, Identifier name);
8586
// with an initial value.
8687
bool hasLetStoredPropertyWithInitialValue(NominalTypeDecl *nominal);
8788

89+
/// Add 'nonisolated' to the synthesized declaration for a derived
90+
/// conformance when needed. Returns true if an attribute was added.
91+
bool addNonIsolatedToSynthesized(DerivedConformance &conformance,
92+
ValueDecl *value);
93+
8894
/// Add 'nonisolated' to the synthesized declaration when needed. Returns true
8995
/// if an attribute was added.
9096
bool addNonIsolatedToSynthesized(NominalTypeDecl *nominal, ValueDecl *value);

0 commit comments

Comments
 (0)