@@ -620,81 +620,14 @@ static Expr *constructDistributedUnownedSerialExecutor(ASTContext &ctx,
620
620
return nullptr ;
621
621
}
622
622
623
- // static Expr *constructOptionalSome(ASTContext &ctx,
624
- // Expr *arg) {
625
- // auto optionalDecl = ctx.getOptionalDecl();
626
- // if (!optionalDecl) return nullptr;
627
- //
628
- // for (auto member: optionalDecl->getAllMembers()) {
629
- // auto ctor = dyn_cast<ConstructorDecl>(member);
630
- // if (!ctor) continue;
631
- //
632
- // // Find the init(_:) which initialized as `some`
633
- // auto params = ctor->getParameters();
634
- // if (params->size() != 1 ||
635
- // params->get(0)->getArgumentName() != Identifier())
636
- // continue;
637
- //
638
- // ctor->dump();
639
- //
640
- //
641
- // // Type optionalType = optionalDecl->getDeclaredInterfaceType();
642
- // // fprintf(stderr, "[%s:%d](%s) optionalDecl\n", __FILE_NAME__, __LINE__, __FUNCTION__);
643
- // // optionalType.dump();
644
- //
645
- // Type optionalType = BoundGenericEnumType::get(optionalDecl, Type(), {arg->getType()});
646
- // fprintf(stderr, "[%s:%d](%s) better optionalType\n", __FILE_NAME__, __LINE__, __FUNCTION__);
647
- // optionalType->dump();
648
- //
649
- // Type ctorType = ctor->getInterfaceType();
650
- // fprintf(stderr, "[%s:%d](%s) ctor type\n", __FILE_NAME__, __LINE__, __FUNCTION__);
651
- // ctorType->dump();
652
- //
653
- // // We have the right initializer. Build a reference to it of type:
654
- // // (Optional.Type)
655
- // // -> (T) -> T
656
- // auto initRef = new (ctx) DeclRefExpr(ctor, DeclNameLoc(), /*implicit*/true,
657
- // AccessSemantics::Ordinary,
658
- // ctorType);
659
- //
660
- // // Apply the initializer to the metatype, building an expression of type:
661
- // // (Builtin.Executor) -> Optional<UnownedSerialExecutor>
662
- // // auto metatypeRef = TypeExpr::createImplicit(optionalType, ctx);
663
- // auto metatypeRef = TypeExpr::createImplicit(optionalType, ctx);
664
- // GenericIdentTypeRepr::create(ctx, DeclNameLoc(optionalDecl->getNameLoc()),
665
- // DeclNameRef(optionalDecl->getBaseName()),
666
- // {arg->getType()}, SourceRange());
667
- // //
668
- // // auto ctorAppliedType = new (ctx) TypeRepr(
669
- // // GenericIdentTypeRepr::create(ctx, DeclNameLoc(), )
670
- // // );
671
- //
672
- // // TypeExpr::createForSpecializedDecl(optionalType.get, {arg->getType()}, SourceRange(), ctx);
673
- // // Type ctorAppliedType = ctorType->getAs<FunctionType>()->getResult();
674
- // auto selfApply = ConstructorRefCallExpr::create(ctx, initRef, metatypeRef
675
- // // ,
676
- // // ctorAppliedType
677
- // );
678
- // selfApply->setImplicit(true);
679
- // selfApply->setThrows(false);
680
- //
681
- // // Call the constructor, building an expression of type
682
- // // Optional<T>.
683
- // auto *argList = ArgumentList::forImplicitUnlabeled(ctx, {arg});
684
- // auto call = CallExpr::createImplicit(ctx, selfApply, argList);
685
- // call->setType(optionalType);
686
- // call->setThrows(false);
687
- // return call;
688
- // }
689
- //
690
- // assert(false);
691
- // }
692
-
693
623
static std::pair<BraceStmt *, bool >
694
- deriveBodyDistributedActor_unownedExecutor (AbstractFunctionDecl *getter, void *) {
695
- // var unownedExecutor : UnownedSerialExecutor? {
624
+ deriveBodyDistributedActor_localUnownedExecutor (AbstractFunctionDecl *getter, void *) {
625
+ // var localUnownedExecutor : UnownedSerialExecutor? {
696
626
// get {
697
- // return Builtin.buildDefaultActorExecutorRef(self)
627
+ // guard __isLocalActor(self) else {
628
+ // return nil
629
+ // }
630
+ // return Optional(Builtin.buildDefaultActorExecutorRef(self))
698
631
// }
699
632
// }
700
633
ASTContext &ctx = getter->getASTContext ();
@@ -751,16 +684,11 @@ deriveBodyDistributedActor_unownedExecutor(AbstractFunctionDecl *getter, void *)
751
684
752
685
auto body = BraceStmt::create (
753
686
ctx, SourceLoc (), { returnNilIfRemoteStmt, ret }, SourceLoc (), /* implicit=*/ true );
754
-
755
- fprintf (stderr, " [%s:%d](%s) ================================================================================================\n " , __FILE_NAME__, __LINE__, __FUNCTION__);
756
- body->dump ();
757
- fprintf (stderr, " [%s:%d](%s) ================================================================================================\n " , __FILE_NAME__, __LINE__, __FUNCTION__);
758
-
759
687
return { body, /* isTypeChecked=*/ true };
760
688
}
761
689
762
- // / Derive the declaration of DistributedActor's unownedExecutor property.
763
- static ValueDecl *deriveDistributedActor_unownedExecutor (DerivedConformance &derived) {
690
+ // / Derive the declaration of DistributedActor's localUnownedExecutor property.
691
+ static ValueDecl *deriveDistributedActor_localUnownedExecutor (DerivedConformance &derived) {
764
692
ASTContext &ctx = derived.Context ;
765
693
766
694
// Retrieve the types and declarations we'll need to form this operation.
@@ -774,7 +702,7 @@ static ValueDecl *deriveDistributedActor_unownedExecutor(DerivedConformance &der
774
702
Type optionalExecutorType = executorType->wrapInOptionalType ();
775
703
776
704
if (auto classDecl = dyn_cast<ClassDecl>(derived.Nominal )) {
777
- if (auto existing = classDecl->getUnownedExecutorProperty ()) {
705
+ if (auto existing = classDecl->getLocalUnownedExecutorProperty ()) {
778
706
if (existing->getInterfaceType ()->isEqual (optionalExecutorType)) {
779
707
return const_cast <VarDecl *>(existing);
780
708
} else {
@@ -785,7 +713,7 @@ static ValueDecl *deriveDistributedActor_unownedExecutor(DerivedConformance &der
785
713
}
786
714
787
715
auto propertyPair = derived.declareDerivedProperty (
788
- DerivedConformance::SynthesizedIntroducer::Var, ctx.Id_unownedExecutor ,
716
+ DerivedConformance::SynthesizedIntroducer::Var, ctx.Id_localUnownedExecutor ,
789
717
optionalExecutorType, optionalExecutorType,
790
718
/* static*/ false , /* final*/ false );
791
719
auto property = propertyPair.first ;
@@ -811,7 +739,7 @@ static ValueDecl *deriveDistributedActor_unownedExecutor(DerivedConformance &der
811
739
812
740
auto getter =
813
741
derived.addGetterToReadOnlyDerivedProperty (property, optionalExecutorType);
814
- getter->setBodySynthesizer (deriveBodyDistributedActor_unownedExecutor );
742
+ getter->setBodySynthesizer (deriveBodyDistributedActor_localUnownedExecutor );
815
743
816
744
// IMPORTANT: MUST BE AFTER [id, actorSystem].
817
745
if (auto id = derived.Nominal ->getDistributedActorIDProperty ()) {
@@ -854,24 +782,24 @@ static void assertRequiredSynthesizedPropertyOrder(DerivedConformance &derived,
854
782
if (auto id = Nominal->getDistributedActorIDProperty ()) {
855
783
if (auto system = Nominal->getDistributedActorSystemProperty ()) {
856
784
if (auto classDecl = dyn_cast<ClassDecl>(derived.Nominal )) {
857
- if (auto unownedExecutor = classDecl->getUnownedExecutorProperty ()) {
858
- int idIdx, actorSystemIdx, unownedExecutorIdx = 0 ;
785
+ if (auto localUnownedExecutor = classDecl->getLocalUnownedExecutorProperty ()) {
786
+ int idIdx, actorSystemIdx, localUnownedExecutorIdx = 0 ;
859
787
int idx = 0 ;
860
788
for (auto member: Nominal->getMembers ()) {
861
789
if (auto binding = dyn_cast<PatternBindingDecl>(member)) {
862
790
if (binding->getSingleVar ()->getName () == Context.Id_id ) {
863
791
idIdx = idx;
864
792
} else if (binding->getSingleVar ()->getName () == Context.Id_actorSystem ) {
865
793
actorSystemIdx = idx;
866
- } else if (binding->getSingleVar ()->getName () == Context.Id_unownedExecutor ) {
867
- unownedExecutorIdx = idx;
794
+ } else if (binding->getSingleVar ()->getName () == Context.Id_localUnownedExecutor ) {
795
+ localUnownedExecutorIdx = idx;
868
796
}
869
797
idx += 1 ;
870
798
}
871
799
}
872
- if (idIdx + actorSystemIdx + unownedExecutorIdx >= 0 + 1 + 2 ) {
800
+ if (idIdx + actorSystemIdx + localUnownedExecutorIdx >= 0 + 1 + 2 ) {
873
801
// we have found all the necessary fields, let's assert their order
874
- assert (idIdx < actorSystemIdx < unownedExecutorIdx && " order of fields MUST be exact." );
802
+ assert (idIdx < actorSystemIdx < localUnownedExecutorIdx && " order of fields MUST be exact." );
875
803
}
876
804
}
877
805
}
@@ -893,8 +821,8 @@ ValueDecl *DerivedConformance::deriveDistributedActor(ValueDecl *requirement) {
893
821
derivedValue = deriveDistributedActor_id (*this );
894
822
} else if (var->getName () == Context.Id_actorSystem ) {
895
823
derivedValue = deriveDistributedActor_actorSystem (*this );
896
- } else if (var->getName () == Context.Id_unownedExecutor ) {
897
- derivedValue = deriveDistributedActor_unownedExecutor (*this );
824
+ } else if (var->getName () == Context.Id_localUnownedExecutor ) {
825
+ derivedValue = deriveDistributedActor_localUnownedExecutor (*this );
898
826
}
899
827
900
828
assertRequiredSynthesizedPropertyOrder (*this , derivedValue);
0 commit comments