@@ -1889,13 +1889,10 @@ static ManagedValue emitBuiltinInjectEnumTag(SILGenFunction &SGF, SILLocation lo
1889
1889
return ManagedValue::forObjectRValueWithoutOwnership (bi);
1890
1890
}
1891
1891
1892
- static ExtensionDecl *distributedActorAsAnyActorExt = nullptr ;
1893
-
1894
1892
// / Find the extension on DistributedActor that defines __actorUnownedExecutor.
1895
1893
static ExtensionDecl *findDistributedActorAsActorExtension (
1896
1894
ProtocolDecl *distributedActorProto, ModuleDecl *module ) {
1897
1895
ASTContext &ctx = distributedActorProto->getASTContext ();
1898
- #if true
1899
1896
auto name = ctx.getIdentifier (" __actorUnownedExecutor" );
1900
1897
auto results = distributedActorProto->lookupDirect (
1901
1898
name, SourceLoc (),
@@ -1907,53 +1904,73 @@ static ExtensionDecl *findDistributedActorAsActorExtension(
1907
1904
}
1908
1905
1909
1906
return nullptr ;
1910
- #else
1911
- if (!distributedActorAsAnyActorExt) {
1912
- auto ext = ExtensionDecl::create (
1913
- ctx, SourceLoc (), nullptr , { }, module , nullptr );
1914
- ctx.evaluator .cacheOutput (ExtendedTypeRequest{ext},
1915
- distributedActorProto->getDeclaredInterfaceType ());
1916
- ctx.evaluator .cacheOutput (ExtendedNominalRequest{ext},
1917
- distributedActorProto);
1918
-
1919
- distributedActorAsAnyActorExt = ext;
1907
+ }
1908
+
1909
+ ProtocolConformanceRef
1910
+ SILGenModule::getDistributedActorAsActorConformance (SubstitutionMap subs) {
1911
+ ASTContext &ctx = M.getASTContext ();
1912
+ auto actorProto = ctx.getProtocol (KnownProtocolKind::Actor);
1913
+ Type distributedActorType = subs.getReplacementTypes ()[0 ];
1914
+
1915
+ if (!distributedActorAsActorConformance) {
1916
+ auto distributedActorProto = ctx.getProtocol (KnownProtocolKind::DistributedActor);
1917
+ if (!distributedActorProto)
1918
+ return ProtocolConformanceRef ();
1919
+
1920
+ auto ext = findDistributedActorAsActorExtension (
1921
+ distributedActorProto, M.getSwiftModule ());
1922
+ if (!ext)
1923
+ return ProtocolConformanceRef ();
1924
+
1925
+ // Conformance of DistributedActor to Actor.
1926
+ auto genericParam = subs.getGenericSignature ().getGenericParams ()[0 ];
1927
+ distributedActorAsActorConformance = ctx.getNormalConformance (
1928
+ Type (genericParam), actorProto, SourceLoc (), ext,
1929
+ ProtocolConformanceState::Incomplete, /* isUnchecked=*/ false ,
1930
+ /* isPreconcurrency=*/ false );
1931
+ }
1932
+
1933
+ return ProtocolConformanceRef (
1934
+ actorProto,
1935
+ ctx.getSpecializedConformance (distributedActorType,
1936
+ distributedActorAsActorConformance,
1937
+ subs));
1938
+ }
1939
+
1940
+ void SILGenModule::noteMemberRefExpr (MemberRefExpr *e) {
1941
+ VarDecl *var = cast<VarDecl>(e->getMember ().getDecl ());
1942
+
1943
+ // If the member is the special `asLocalActor` operation on
1944
+ // distributed actors, make sure we have the conformance needed
1945
+ // for a builtin.
1946
+ ASTContext &ctx = var->getASTContext ();
1947
+ if (var->getName () == ctx.Id_asLocalActor &&
1948
+ var->getDeclContext ()->getSelfProtocolDecl () &&
1949
+ var->getDeclContext ()->getSelfProtocolDecl ()
1950
+ ->isSpecificProtocol (KnownProtocolKind::DistributedActor)) {
1951
+ auto conformance =
1952
+ getDistributedActorAsActorConformance (
1953
+ e->getMember ().getSubstitutions ());
1954
+ useConformance (conformance);
1920
1955
}
1921
1956
1922
- return distributedActorAsAnyActorExt;
1923
- #endif
1924
1957
}
1925
1958
1926
1959
static ManagedValue emitBuiltinDistributedActorAsAnyActor (
1927
1960
SILGenFunction &SGF, SILLocation loc, SubstitutionMap subs,
1928
1961
ArrayRef<ManagedValue> args, SGFContext C) {
1929
1962
auto &ctx = SGF.getASTContext ();
1930
1963
auto distributedActor = args[0 ];
1931
-
1932
- auto builtinDecl = cast<FuncDecl>(getBuiltinValueDecl (
1933
- ctx, ctx.getIdentifier (" distributedActorAsAnyActor" )));
1934
- auto genericSignature = builtinDecl->getGenericSignature ();
1935
- auto genericParam = genericSignature.getGenericParams ()[0 ];
1936
-
1937
- auto distributedActorProto = ctx.getProtocol (KnownProtocolKind::DistributedActor);
1938
- auto ext = findDistributedActorAsActorExtension (
1939
- distributedActorProto, SGF.getModule ().getSwiftModule ());
1940
-
1941
- // Conformance of DistributedActor to Actor.
1942
- auto actorProto = ctx.getProtocol (KnownProtocolKind::Actor);
1943
- CanType distributedActorType = distributedActor.getType ().getASTType ();
1944
- RootProtocolConformance *daAsActorConformance = ctx.getNormalConformance (
1945
- Type (genericParam), actorProto, SourceLoc (), ext,
1946
- ProtocolConformanceState::Incomplete, /* isUnchecked=*/ false ,
1947
- /* isPreconcurrency=*/ false );
1948
- ProtocolConformanceRef conformance (
1949
- actorProto,
1950
- ctx.getSpecializedConformance (distributedActorType, daAsActorConformance,
1951
- subs));
1952
- ProtocolConformanceRef conformances[1 ] = { conformance };
1964
+ ProtocolConformanceRef conformances[1 ] = {
1965
+ SGF.SGM .getDistributedActorAsActorConformance (subs)
1966
+ };
1953
1967
1954
1968
// Erase the distributed actor instance into an `any Actor` existential with
1955
1969
// the special conformance.
1970
+ CanType distributedActorType =
1971
+ subs.getReplacementTypes ()[0 ]->getCanonicalType ();
1956
1972
auto &distributedActorTL = SGF.getTypeLowering (distributedActorType);
1973
+ auto actorProto = ctx.getProtocol (KnownProtocolKind::Actor);
1957
1974
auto &anyActorTL = SGF.getTypeLowering (actorProto->getDeclaredExistentialType ());
1958
1975
return SGF.emitExistentialErasure (
1959
1976
loc, distributedActorType, distributedActorTL, anyActorTL,
0 commit comments