|
16 | 16 | #include "Scope.h" |
17 | 17 | #include "swift/AST/ASTContext.h" |
18 | 18 | #include "swift/AST/Availability.h" |
| 19 | +#include "swift/AST/DistributedDecl.h" |
19 | 20 | #include "swift/AST/ProtocolConformance.h" |
20 | 21 | #include "swift/Basic/Range.h" |
21 | 22 |
|
@@ -661,75 +662,29 @@ SILValue SILGenFunction::emitGetCurrentExecutor(SILLocation loc) { |
661 | 662 | return ExpectedExecutor; |
662 | 663 | } |
663 | 664 |
|
664 | | -/// Find the extension on DistributedActor that defines __actorUnownedExecutor. |
665 | | -static ExtensionDecl *findDistributedActorAsActorExtension( |
666 | | - ProtocolDecl *distributedActorProto, ModuleDecl *module) { |
667 | | - ASTContext &ctx = distributedActorProto->getASTContext(); |
668 | | - auto name = ctx.getIdentifier("__actorUnownedExecutor"); |
669 | | - auto results = distributedActorProto->lookupDirect( |
670 | | - name, SourceLoc(), |
671 | | - NominalTypeDecl::LookupDirectFlags::IncludeAttrImplements); |
672 | | - for (auto result : results) { |
673 | | - if (auto var = dyn_cast<VarDecl>(result)) { |
674 | | - return dyn_cast<ExtensionDecl>(var->getDeclContext()); |
675 | | - } |
676 | | - } |
677 | | - |
678 | | - return nullptr; |
679 | | -} |
680 | | - |
681 | | -ProtocolConformanceRef |
682 | | -SILGenModule::getDistributedActorAsActorConformance(SubstitutionMap subs) { |
683 | | - ASTContext &ctx = M.getASTContext(); |
684 | | - auto actorProto = ctx.getProtocol(KnownProtocolKind::Actor); |
685 | | - Type distributedActorType = subs.getReplacementTypes()[0]; |
686 | | - |
687 | | - if (!distributedActorAsActorConformance) { |
688 | | - auto distributedActorProto = ctx.getProtocol(KnownProtocolKind::DistributedActor); |
689 | | - if (!distributedActorProto) |
690 | | - return ProtocolConformanceRef(); |
691 | | - |
692 | | - auto ext = findDistributedActorAsActorExtension( |
693 | | - distributedActorProto, M.getSwiftModule()); |
694 | | - if (!ext) |
695 | | - return ProtocolConformanceRef(); |
696 | | - |
697 | | - // Conformance of DistributedActor to Actor. |
698 | | - auto genericParam = subs.getGenericSignature().getGenericParams()[0]; |
699 | | - distributedActorAsActorConformance = ctx.getNormalConformance( |
700 | | - Type(genericParam), actorProto, SourceLoc(), ext, |
701 | | - ProtocolConformanceState::Incomplete, /*isUnchecked=*/false, |
702 | | - /*isPreconcurrency=*/false); |
703 | | - } |
704 | | - |
705 | | - return ProtocolConformanceRef( |
706 | | - actorProto, |
707 | | - ctx.getSpecializedConformance(distributedActorType, |
708 | | - distributedActorAsActorConformance, |
709 | | - subs)); |
710 | | -} |
711 | | - |
712 | 665 | ManagedValue |
713 | 666 | SILGenFunction::emitDistributedActorAsAnyActor(SILLocation loc, |
714 | 667 | SubstitutionMap distributedActorSubs, |
715 | 668 | ManagedValue actorValue) { |
716 | | - ProtocolConformanceRef conformances[1] = { |
717 | | - SGM.getDistributedActorAsActorConformance(distributedActorSubs) |
718 | | - }; |
| 669 | + auto &ctx = SGM.getASTContext(); |
| 670 | + |
| 671 | + auto distributedActorAsActorConformance = |
| 672 | + getDistributedActorAsActorConformance(ctx); |
| 673 | + auto actorProto = ctx.getProtocol(KnownProtocolKind::Actor); |
| 674 | + auto distributedActorType = distributedActorSubs.getReplacementTypes()[0]; |
| 675 | + auto ref = ProtocolConformanceRef( |
| 676 | + actorProto, ctx.getSpecializedConformance( |
| 677 | + distributedActorType, distributedActorAsActorConformance, |
| 678 | + distributedActorSubs)); |
| 679 | + ProtocolConformanceRef conformances[1] = {ref}; |
719 | 680 |
|
720 | 681 | // Erase the distributed actor instance into an `any Actor` existential with |
721 | 682 | // the special conformance. |
722 | | - auto &ctx = SGM.getASTContext(); |
723 | | - CanType distributedActorType = |
724 | | - distributedActorSubs.getReplacementTypes()[0]->getCanonicalType(); |
725 | | - auto &distributedActorTL = getTypeLowering(distributedActorType); |
726 | | - auto actorProto = ctx.getProtocol(KnownProtocolKind::Actor); |
| 683 | + CanType distributedActorCanType = distributedActorType->getCanonicalType(); |
| 684 | + auto &distributedActorTL = getTypeLowering(distributedActorCanType); |
727 | 685 | auto &anyActorTL = getTypeLowering(actorProto->getDeclaredExistentialType()); |
728 | | - return emitExistentialErasure(loc, distributedActorType, |
729 | | - distributedActorTL, anyActorTL, |
730 | | - ctx.AllocateCopy(conformances), |
731 | | - SGFContext(), |
732 | | - [actorValue](SGFContext) { |
733 | | - return actorValue; |
734 | | - }); |
| 686 | + return emitExistentialErasure( |
| 687 | + loc, distributedActorCanType, distributedActorTL, anyActorTL, |
| 688 | + ctx.AllocateCopy(conformances), SGFContext(), |
| 689 | + [actorValue](SGFContext) { return actorValue; }); |
735 | 690 | } |
0 commit comments