Skip to content

Commit 6f376c2

Browse files
committed
Fix SILGen's computation of default argument generator isolation
1 parent 4f6acbc commit 6f376c2

File tree

4 files changed

+24
-54
lines changed

4 files changed

+24
-54
lines changed

include/swift/SIL/SILDeclRef.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ namespace swift {
3838
enum class EffectsKind : uint8_t;
3939
class AbstractFunctionDecl;
4040
class AbstractClosureExpr;
41+
class ActorIsolation;
4142
class ValueDecl;
4243
class FuncDecl;
4344
class ClosureExpr;
@@ -498,6 +499,8 @@ struct SILDeclRef {
498499
return result;
499500
}
500501

502+
ActorIsolation getActorIsolation() const;
503+
501504
/// True if the decl ref references a thunk from a natively foreign
502505
/// declaration to Swift calling convention.
503506
bool isForeignToNativeThunk() const;

lib/SIL/IR/SILDeclRef.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1873,3 +1873,21 @@ bool SILDeclRef::isCalleeAllocatedCoroutine() const {
18731873

18741874
return getASTContext().SILOpts.CoroutineAccessorsUseYieldOnce2;
18751875
}
1876+
1877+
ActorIsolation SILDeclRef::getActorIsolation() const {
1878+
// Deallocating destructor is always nonisolated. Isolation of the deinit
1879+
// applies only to isolated deallocator and destroyer.
1880+
if (kind == SILDeclRef::Kind::Deallocator) {
1881+
return ActorIsolation::forNonisolated(false);
1882+
}
1883+
1884+
// Default argument generators use the isolation of the initializer,
1885+
// not the general isolation of the function.
1886+
if (isDefaultArgGenerator()) {
1887+
auto param = getParameterAt(getDecl(), defaultArgIndex);
1888+
assert(param);
1889+
return param->getInitializerIsolation();
1890+
}
1891+
1892+
return getActorIsolationOfContext(getInnermostDeclContext());
1893+
}

lib/SIL/IR/SILFunctionType.cpp

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2419,32 +2419,7 @@ swift::getSILFunctionTypeActorIsolation(CanAnyFunctionType substFnInterfaceType,
24192419
}
24202420

24212421
if (constant) {
2422-
// TODO: It should to be possible to `getActorIsolation` if
2423-
// reference is to a decl instead of trying to get isolation
2424-
// from the reference kind, the attributes, or the context.
2425-
2426-
if (constant->kind == SILDeclRef::Kind::Deallocator) {
2427-
return ActorIsolation::forNonisolated(false);
2428-
}
2429-
2430-
if (auto *decl = constant->getAbstractFunctionDecl()) {
2431-
if (auto *nonisolatedAttr =
2432-
decl->getAttrs().getAttribute<NonisolatedAttr>()) {
2433-
if (nonisolatedAttr->isNonSending())
2434-
return ActorIsolation::forCallerIsolationInheriting();
2435-
}
2436-
2437-
if (decl->getAttrs().hasAttribute<ConcurrentAttr>()) {
2438-
return ActorIsolation::forNonisolated(false /*unsafe*/);
2439-
}
2440-
}
2441-
2442-
if (auto *closure = constant->getAbstractClosureExpr()) {
2443-
if (auto isolation = closure->getActorIsolation())
2444-
return isolation;
2445-
}
2446-
2447-
return getActorIsolationOfContext(constant->getInnermostDeclContext());
2422+
return constant->getActorIsolation();
24482423
}
24492424

24502425
if (substFnInterfaceType->hasExtInfo() &&

lib/SILGen/SILGen.cpp

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -768,32 +768,6 @@ static bool isEmittedOnDemand(SILModule &M, SILDeclRef constant) {
768768
return false;
769769
}
770770

771-
static ActorIsolation getActorIsolationForFunction(SILFunction &fn) {
772-
if (auto constant = fn.getDeclRef()) {
773-
if (constant.kind == SILDeclRef::Kind::Deallocator) {
774-
// Deallocating destructor is always nonisolated. Isolation of the deinit
775-
// applies only to isolated deallocator and destroyer.
776-
return ActorIsolation::forNonisolated(false);
777-
}
778-
779-
// If we have a closure expr, check if our type is
780-
// nonisolated(nonsending). In that case, we use that instead.
781-
if (auto *closureExpr = constant.getAbstractClosureExpr()) {
782-
if (auto actorIsolation = closureExpr->getActorIsolation())
783-
return actorIsolation;
784-
}
785-
786-
// If we have actor isolation for our constant, put the isolation onto the
787-
// function. If the isolation is unspecified, we do not return it.
788-
if (auto isolation =
789-
getActorIsolationOfContext(constant.getInnermostDeclContext()))
790-
return isolation;
791-
}
792-
793-
// Otherwise, return for unspecified.
794-
return ActorIsolation::forUnspecified();
795-
}
796-
797771
SILFunction *SILGenModule::getFunction(SILDeclRef constant,
798772
ForDefinition_t forDefinition) {
799773
// If we already emitted the function, return it.
@@ -820,7 +794,7 @@ SILFunction *SILGenModule::getFunction(SILDeclRef constant,
820794
});
821795

822796
F->setDeclRef(constant);
823-
F->setActorIsolation(getActorIsolationForFunction(*F));
797+
F->setActorIsolation(constant.getActorIsolation());
824798

825799
assert(F && "SILFunction should have been defined");
826800

@@ -1316,7 +1290,7 @@ void SILGenModule::preEmitFunction(SILDeclRef constant, SILFunction *F,
13161290
F->setDeclRef(constant);
13171291

13181292
// Set our actor isolation.
1319-
F->setActorIsolation(getActorIsolationForFunction(*F));
1293+
F->setActorIsolation(constant.getActorIsolation());
13201294

13211295
LLVM_DEBUG(llvm::dbgs() << "lowering ";
13221296
F->printName(llvm::dbgs());

0 commit comments

Comments
 (0)