@@ -509,59 +509,62 @@ SILIsolationInfo SILIsolationInfo::get(SILInstruction *inst) {
509
509
510
510
// Treat function ref as either actor isolated or sendable.
511
511
if (auto *fri = dyn_cast<FunctionRefInst>(inst)) {
512
- auto isolation = fri->getReferencedFunction ()->getActorIsolation ();
512
+ if (auto optIsolation = fri->getReferencedFunction ()->getActorIsolation ()) {
513
+ auto isolation = *optIsolation;
513
514
514
- // First check if we are actor isolated at the AST level... if we are, then
515
- // create the relevant actor isolated.
516
- if (isolation.isActorIsolated ()) {
517
- if (isolation.isGlobalActor ()) {
518
- return SILIsolationInfo::getGlobalActorIsolated (
519
- fri, isolation.getGlobalActor ());
520
- }
515
+ // First check if we are actor isolated at the AST level... if we are,
516
+ // then create the relevant actor isolated.
517
+ if (isolation.isActorIsolated ()) {
518
+ if (isolation.isGlobalActor ()) {
519
+ return SILIsolationInfo::getGlobalActorIsolated (
520
+ fri, isolation.getGlobalActor ());
521
+ }
521
522
522
- // TODO: We need to be able to support flow sensitive actor instances like
523
- // we do for partial apply. Until we do so, just store SILValue() for
524
- // this. This could cause a problem if we can construct a function ref and
525
- // invoke it with two different actor instances of the same type and pass
526
- // in the same parameters to both. We should error and we would not with
527
- // this impl since we could not distinguish the two.
528
- if (isolation.getKind () == ActorIsolation::ActorInstance) {
529
- return SILIsolationInfo::getFlowSensitiveActorIsolated (fri, isolation);
530
- }
523
+ // TODO: We need to be able to support flow sensitive actor instances
524
+ // like we do for partial apply. Until we do so, just store SILValue()
525
+ // for this. This could cause a problem if we can construct a function
526
+ // ref and invoke it with two different actor instances of the same type
527
+ // and pass in the same parameters to both. We should error and we would
528
+ // not with this impl since we could not distinguish the two.
529
+ if (isolation.getKind () == ActorIsolation::ActorInstance) {
530
+ return SILIsolationInfo::getFlowSensitiveActorIsolated (fri,
531
+ isolation);
532
+ }
531
533
532
- assert (isolation.getKind () != ActorIsolation::Erased &&
533
- " Implement this!" );
534
- }
534
+ assert (isolation.getKind () != ActorIsolation::Erased &&
535
+ " Implement this!" );
536
+ }
535
537
536
- // Then check if we have something that is nonisolated unsafe.
537
- if (isolation.isNonisolatedUnsafe ()) {
538
- // First check if our function_ref is a method of a global actor isolated
539
- // type. In such a case, we create a global actor isolated
540
- // nonisolated(unsafe) so that if we assign the value to another variable,
541
- // the variable still says that it is the appropriate global actor
542
- // isolated thing.
543
- //
544
- // E.x.:
545
- //
546
- // @MainActor
547
- // struct X { nonisolated(unsafe) var x: NonSendableThing { ... } }
548
- //
549
- // We want X.x to be safe to use... but to have that 'z' in the following
550
- // is considered MainActor isolated.
551
- //
552
- // let z = X.x
553
- //
554
- auto *func = fri->getReferencedFunction ();
555
- auto funcType = func->getLoweredFunctionType ();
556
- if (funcType->hasSelfParam ()) {
557
- auto selfParam = funcType->getSelfInstanceType (
558
- fri->getModule (), func->getTypeExpansionContext ());
559
- if (auto *nomDecl = selfParam->getNominalOrBoundGenericNominal ()) {
560
- auto isolation = swift::getActorIsolation (nomDecl);
561
- if (isolation.isGlobalActor ()) {
562
- return SILIsolationInfo::getGlobalActorIsolated (
563
- fri, isolation.getGlobalActor ())
564
- .withUnsafeNonIsolated (true );
538
+ // Then check if we have something that is nonisolated unsafe.
539
+ if (isolation.isNonisolatedUnsafe ()) {
540
+ // First check if our function_ref is a method of a global actor
541
+ // isolated type. In such a case, we create a global actor isolated
542
+ // nonisolated(unsafe) so that if we assign the value to another
543
+ // variable, the variable still says that it is the appropriate global
544
+ // actor isolated thing.
545
+ //
546
+ // E.x.:
547
+ //
548
+ // @MainActor
549
+ // struct X { nonisolated(unsafe) var x: NonSendableThing { ... } }
550
+ //
551
+ // We want X.x to be safe to use... but to have that 'z' in the
552
+ // following is considered MainActor isolated.
553
+ //
554
+ // let z = X.x
555
+ //
556
+ auto *func = fri->getReferencedFunction ();
557
+ auto funcType = func->getLoweredFunctionType ();
558
+ if (funcType->hasSelfParam ()) {
559
+ auto selfParam = funcType->getSelfInstanceType (
560
+ fri->getModule (), func->getTypeExpansionContext ());
561
+ if (auto *nomDecl = selfParam->getNominalOrBoundGenericNominal ()) {
562
+ auto nomDeclIsolation = swift::getActorIsolation (nomDecl);
563
+ if (nomDeclIsolation.isGlobalActor ()) {
564
+ return SILIsolationInfo::getGlobalActorIsolated (
565
+ fri, nomDeclIsolation.getGlobalActor ())
566
+ .withUnsafeNonIsolated (true );
567
+ }
565
568
}
566
569
}
567
570
}
@@ -868,8 +871,11 @@ SILIsolationInfo SILIsolationInfo::get(SILArgument *arg) {
868
871
// code. In the case of a non-actor, we can only have an allocator that is
869
872
// global actor isolated, so we will never hit this code path.
870
873
if (declRef.kind == SILDeclRef::Kind::Allocator) {
871
- if (fArg ->getFunction ()->getActorIsolation ().isActorInstanceIsolated ()) {
872
- return SILIsolationInfo::getDisconnected (false /* nonisolated(unsafe)*/ );
874
+ if (auto isolation = fArg ->getFunction ()->getActorIsolation ()) {
875
+ if (isolation->isActorInstanceIsolated ()) {
876
+ return SILIsolationInfo::getDisconnected (
877
+ false /* nonisolated(unsafe)*/ );
878
+ }
873
879
}
874
880
}
875
881
@@ -878,13 +884,13 @@ SILIsolationInfo SILIsolationInfo::get(SILArgument *arg) {
878
884
// we need to pass in a "fake" ActorInstance that users know is a sentinel
879
885
// for the self value.
880
886
if (auto functionIsolation = fArg ->getFunction ()->getActorIsolation ()) {
881
- if (functionIsolation. isActorInstanceIsolated () && declRef.getDecl ()) {
887
+ if (functionIsolation-> isActorInstanceIsolated () && declRef.getDecl ()) {
882
888
if (auto *accessor =
883
889
dyn_cast_or_null<AccessorDecl>(declRef.getFuncDecl ())) {
884
890
if (accessor->isInitAccessor ()) {
885
891
return SILIsolationInfo::getActorInstanceIsolated (
886
892
fArg , ActorInstance::getForActorAccessorInit (),
887
- functionIsolation. getActor ());
893
+ functionIsolation-> getActor ());
888
894
}
889
895
}
890
896
}
@@ -894,15 +900,15 @@ SILIsolationInfo SILIsolationInfo::get(SILArgument *arg) {
894
900
// Otherwise, if we do not have an isolated argument and are not in an
895
901
// allocator, then we might be isolated via global isolation.
896
902
if (auto functionIsolation = fArg ->getFunction ()->getActorIsolation ()) {
897
- if (functionIsolation. isActorIsolated ()) {
898
- if (functionIsolation. isGlobalActor ()) {
903
+ if (functionIsolation-> isActorIsolated ()) {
904
+ if (functionIsolation-> isGlobalActor ()) {
899
905
return SILIsolationInfo::getGlobalActorIsolated (
900
- fArg , functionIsolation. getGlobalActor ());
906
+ fArg , functionIsolation-> getGlobalActor ());
901
907
}
902
908
903
909
return SILIsolationInfo::getActorInstanceIsolated (
904
910
fArg , ActorInstance::getForActorAccessorInit (),
905
- functionIsolation. getActor ());
911
+ functionIsolation-> getActor ());
906
912
}
907
913
}
908
914
0 commit comments