Skip to content

Commit 74496ea

Browse files
committed
Fix SILGen's computation of default argument generator isolation
1 parent 3088b85 commit 74496ea

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;
@@ -508,6 +509,8 @@ struct SILDeclRef {
508509
return result;
509510
}
510511

512+
ActorIsolation getActorIsolation() const;
513+
511514
/// True if the decl ref references a thunk from a natively foreign
512515
/// declaration to Swift calling convention.
513516
bool isForeignToNativeThunk() const;

lib/SIL/IR/SILDeclRef.cpp

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

19221922
return getASTContext().SILOpts.CoroutineAccessorsUseYieldOnce2;
19231923
}
1924+
1925+
ActorIsolation SILDeclRef::getActorIsolation() const {
1926+
// Deallocating destructor is always nonisolated. Isolation of the deinit
1927+
// applies only to isolated deallocator and destroyer.
1928+
if (kind == SILDeclRef::Kind::Deallocator) {
1929+
return ActorIsolation::forNonisolated(false);
1930+
}
1931+
1932+
// Default argument generators use the isolation of the initializer,
1933+
// not the general isolation of the function.
1934+
if (isDefaultArgGenerator()) {
1935+
auto param = getParameterAt(getDecl(), defaultArgIndex);
1936+
assert(param);
1937+
return param->getInitializerIsolation();
1938+
}
1939+
1940+
return getActorIsolationOfContext(getInnermostDeclContext());
1941+
}

lib/SIL/IR/SILFunctionType.cpp

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

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

24432418
if (substFnInterfaceType->hasExtInfo() &&

lib/SILGen/SILGen.cpp

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

804-
static ActorIsolation getActorIsolationForFunction(SILFunction &fn) {
805-
if (auto constant = fn.getDeclRef()) {
806-
if (constant.kind == SILDeclRef::Kind::Deallocator) {
807-
// Deallocating destructor is always nonisolated. Isolation of the deinit
808-
// applies only to isolated deallocator and destroyer.
809-
return ActorIsolation::forNonisolated(false);
810-
}
811-
812-
// If we have a closure expr, check if our type is
813-
// nonisolated(nonsending). In that case, we use that instead.
814-
if (auto *closureExpr = constant.getAbstractClosureExpr()) {
815-
if (auto actorIsolation = closureExpr->getActorIsolation())
816-
return actorIsolation;
817-
}
818-
819-
// If we have actor isolation for our constant, put the isolation onto the
820-
// function. If the isolation is unspecified, we do not return it.
821-
if (auto isolation =
822-
getActorIsolationOfContext(constant.getInnermostDeclContext()))
823-
return isolation;
824-
}
825-
826-
// Otherwise, return for unspecified.
827-
return ActorIsolation::forUnspecified();
828-
}
829-
830804
SILFunction *SILGenModule::getFunction(SILDeclRef constant,
831805
ForDefinition_t forDefinition) {
832806
// If we already emitted the function, return it.
@@ -853,7 +827,7 @@ SILFunction *SILGenModule::getFunction(SILDeclRef constant,
853827
});
854828

855829
F->setDeclRef(constant);
856-
F->setActorIsolation(getActorIsolationForFunction(*F));
830+
F->setActorIsolation(constant.getActorIsolation());
857831

858832
assert(F && "SILFunction should have been defined");
859833

@@ -1384,7 +1358,7 @@ void SILGenModule::preEmitFunction(SILDeclRef constant, SILFunction *F,
13841358
F->setDeclRef(constant);
13851359

13861360
// Set our actor isolation.
1387-
F->setActorIsolation(getActorIsolationForFunction(*F));
1361+
F->setActorIsolation(constant.getActorIsolation());
13881362

13891363
LLVM_DEBUG(llvm::dbgs() << "lowering ";
13901364
F->printName(llvm::dbgs());

0 commit comments

Comments
 (0)