Skip to content

Commit 55bbee8

Browse files
committed
[AST] NFC: Move distributed actor methods from ASTContext into swift namespace
1 parent 4290991 commit 55bbee8

File tree

7 files changed

+240
-220
lines changed

7 files changed

+240
-220
lines changed

include/swift/AST/ASTContext.h

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -726,68 +726,6 @@ class ASTContext final {
726726
// Retrieve the declaration of Swift._stdlib_isOSVersionAtLeast.
727727
FuncDecl *getIsOSVersionAtLeastDecl() const;
728728

729-
/// Retrieve the declaration of DistributedActorSystem.remoteCall(Void)(...).
730-
///
731-
/// \param actorOrSystem distributed actor or actor system to get the
732-
/// remoteCall function for. Since the method we're looking for is an ad-hoc
733-
/// requirement, a specific type MUST be passed here as it is not possible
734-
/// to obtain the decl from just the `DistributedActorSystem` protocol type.
735-
/// \param isVoidReturn true if the call will be returning `Void`.
736-
AbstractFunctionDecl *getRemoteCallOnDistributedActorSystem(
737-
NominalTypeDecl *actorOrSystem,
738-
bool isVoidReturn) const;
739-
740-
/// Retrieve the declaration of DistributedActorSystem.make().
741-
///
742-
/// \param thunk the function from which we'll be invoking things on the obtained
743-
/// actor system; This way we'll always get the right type, taking care of any
744-
/// where clauses etc.
745-
FuncDecl *getMakeInvocationEncoderOnDistributedActorSystem(
746-
AbstractFunctionDecl *thunk) const;
747-
748-
// Retrieve the declaration of
749-
// DistributedInvocationEncoder.recordGenericSubstitution(_:).
750-
//
751-
// \param nominal optionally provide a 'NominalTypeDecl' from which the
752-
// function decl shall be extracted. This is useful to avoid witness calls
753-
// through the protocol which is looked up when nominal is null.
754-
FuncDecl *getRecordGenericSubstitutionOnDistributedInvocationEncoder(
755-
NominalTypeDecl *nominal) const;
756-
757-
// Retrieve the declaration of DistributedTargetInvocationEncoder.recordArgument(_:).
758-
//
759-
// \param nominal optionally provide a 'NominalTypeDecl' from which the
760-
// function decl shall be extracted. This is useful to avoid witness calls
761-
// through the protocol which is looked up when nominal is null.
762-
AbstractFunctionDecl *getRecordArgumentOnDistributedInvocationEncoder(
763-
NominalTypeDecl *nominal) const;
764-
765-
// Retrieve the declaration of DistributedTargetInvocationEncoder.recordReturnType(_:).
766-
AbstractFunctionDecl *getRecordReturnTypeOnDistributedInvocationEncoder(
767-
NominalTypeDecl *nominal) const;
768-
769-
// Retrieve the declaration of DistributedTargetInvocationEncoder.recordErrorType(_:).
770-
AbstractFunctionDecl *getRecordErrorTypeOnDistributedInvocationEncoder(
771-
NominalTypeDecl *nominal) const;
772-
773-
// Retrieve the declaration of
774-
// DistributedTargetInvocationDecoder.getDecodeNextArgumentOnDistributedInvocationDecoder(_:).
775-
AbstractFunctionDecl *getDecodeNextArgumentOnDistributedInvocationDecoder(
776-
NominalTypeDecl *nominal) const;
777-
778-
// Retrieve the declaration of
779-
// getOnReturnOnDistributedTargetInvocationResultHandler.onReturn(_:).
780-
AbstractFunctionDecl *getOnReturnOnDistributedTargetInvocationResultHandler(
781-
NominalTypeDecl *nominal) const;
782-
783-
// Retrieve the declaration of DistributedInvocationEncoder.doneRecording().
784-
//
785-
// \param nominal optionally provide a 'NominalTypeDecl' from which the
786-
// function decl shall be extracted. This is useful to avoid witness calls
787-
// through the protocol which is looked up when nominal is null.
788-
FuncDecl *getDoneRecordingOnDistributedInvocationEncoder(
789-
NominalTypeDecl *nominal) const;
790-
791729
/// Look for the declaration with the given name within the
792730
/// passed in module.
793731
void lookupInModule(ModuleDecl *M, StringRef name,
@@ -1527,17 +1465,6 @@ class ASTContext final {
15271465
/// alternative specified via the -entry-point-function-name frontend flag.
15281466
std::string getEntryPointFunctionName() const;
15291467

1530-
Type getAssociatedTypeOfDistributedSystemOfActor(NominalTypeDecl *actor,
1531-
Identifier member);
1532-
1533-
/// Find the concrete invocation decoder associated with the given actor.
1534-
NominalTypeDecl *
1535-
getDistributedActorInvocationDecoder(NominalTypeDecl *);
1536-
1537-
/// Find `decodeNextArgument<T>(type: T.Type) -> T` method associated with
1538-
/// invocation decoder of the given distributed actor.
1539-
FuncDecl *getDistributedActorArgumentDecodingMethod(NominalTypeDecl *);
1540-
15411468
/// The special Builtin.TheTupleType, which parents tuple extensions and
15421469
/// conformances.
15431470
BuiltinTupleDecl *getBuiltinTupleDecl();

include/swift/AST/DistributedDecl.h

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ class DeclContext;
3131
class FuncDecl;
3232
class NominalTypeDecl;
3333

34+
Type getAssociatedTypeOfDistributedSystemOfActor(NominalTypeDecl *actor,
35+
Identifier member);
36+
37+
/// Find the concrete invocation decoder associated with the given actor.
38+
NominalTypeDecl *getDistributedActorInvocationDecoder(NominalTypeDecl *);
39+
40+
/// Find `decodeNextArgument<T>(type: T.Type) -> T` method associated with
41+
/// invocation decoder of the given distributed actor.
42+
FuncDecl *getDistributedActorArgumentDecodingMethod(NominalTypeDecl *);
43+
3444
/// Determine the concrete type of 'ActorSystem' as seen from the member.
3545
/// E.g. when in a protocol, and trying to determine what the actor system was
3646
/// constrained to.
@@ -115,6 +125,70 @@ getDistributedSerializationRequirements(
115125
ProtocolDecl *protocol,
116126
llvm::SmallPtrSetImpl<ProtocolDecl *> &requirementProtos);
117127

128+
/// Retrieve the declaration of DistributedActorSystem.remoteCall(Void)(...).
129+
///
130+
/// \param actorOrSystem distributed actor or actor system to get the
131+
/// remoteCall function for. Since the method we're looking for is an ad-hoc
132+
/// requirement, a specific type MUST be passed here as it is not possible
133+
/// to obtain the decl from just the `DistributedActorSystem` protocol type.
134+
/// \param isVoidReturn true if the call will be returning `Void`.
135+
AbstractFunctionDecl *
136+
getRemoteCallOnDistributedActorSystem(NominalTypeDecl *actorOrSystem,
137+
bool isVoidReturn);
138+
139+
/// Retrieve the declaration of DistributedActorSystem.make().
140+
///
141+
/// \param thunk the function from which we'll be invoking things on the
142+
/// obtained actor system; This way we'll always get the right type, taking care
143+
/// of any where clauses etc.
144+
FuncDecl *
145+
getMakeInvocationEncoderOnDistributedActorSystem(AbstractFunctionDecl *thunk);
146+
147+
// Retrieve the declaration of
148+
// DistributedInvocationEncoder.recordGenericSubstitution(_:).
149+
//
150+
// \param nominal optionally provide a 'NominalTypeDecl' from which the
151+
// function decl shall be extracted. This is useful to avoid witness calls
152+
// through the protocol which is looked up when nominal is null.
153+
FuncDecl *getRecordGenericSubstitutionOnDistributedInvocationEncoder(
154+
NominalTypeDecl *nominal);
155+
156+
// Retrieve the declaration of
157+
// DistributedTargetInvocationEncoder.recordArgument(_:).
158+
//
159+
// \param nominal optionally provide a 'NominalTypeDecl' from which the
160+
// function decl shall be extracted. This is useful to avoid witness calls
161+
// through the protocol which is looked up when nominal is null.
162+
AbstractFunctionDecl *
163+
getRecordArgumentOnDistributedInvocationEncoder(NominalTypeDecl *nominal);
164+
165+
// Retrieve the declaration of
166+
// DistributedTargetInvocationEncoder.recordReturnType(_:).
167+
AbstractFunctionDecl *
168+
getRecordReturnTypeOnDistributedInvocationEncoder(NominalTypeDecl *nominal);
169+
170+
// Retrieve the declaration of
171+
// DistributedTargetInvocationEncoder.recordErrorType(_:).
172+
AbstractFunctionDecl *
173+
getRecordErrorTypeOnDistributedInvocationEncoder(NominalTypeDecl *nominal);
174+
175+
// Retrieve the declaration of
176+
// DistributedTargetInvocationDecoder.getDecodeNextArgumentOnDistributedInvocationDecoder(_:).
177+
AbstractFunctionDecl *
178+
getDecodeNextArgumentOnDistributedInvocationDecoder(NominalTypeDecl *nominal);
179+
180+
// Retrieve the declaration of
181+
// getOnReturnOnDistributedTargetInvocationResultHandler.onReturn(_:).
182+
AbstractFunctionDecl *
183+
getOnReturnOnDistributedTargetInvocationResultHandler(NominalTypeDecl *nominal);
184+
185+
// Retrieve the declaration of DistributedInvocationEncoder.doneRecording().
186+
//
187+
// \param nominal optionally provide a 'NominalTypeDecl' from which the
188+
// function decl shall be extracted. This is useful to avoid witness calls
189+
// through the protocol which is looked up when nominal is null.
190+
FuncDecl *
191+
getDoneRecordingOnDistributedInvocationEncoder(NominalTypeDecl *nominal);
118192
}
119193

120194
#endif /* SWIFT_DECL_DISTRIBUTEDDECL_H */

lib/AST/ASTContext.cpp

Lines changed: 0 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,119 +1545,6 @@ FuncDecl *ASTContext::getEqualIntDecl() const {
15451545
return getBinaryComparisonOperatorIntDecl(*this, "==", getImpl().EqualIntDecl);
15461546
}
15471547

1548-
FuncDecl *ASTContext::getMakeInvocationEncoderOnDistributedActorSystem(
1549-
AbstractFunctionDecl *thunk) const {
1550-
auto systemTy = getConcreteReplacementForProtocolActorSystemType(thunk);
1551-
assert(systemTy && "No specific ActorSystem type found!");
1552-
1553-
auto systemNominal = systemTy->getNominalOrBoundGenericNominal();
1554-
assert(systemNominal && "No system nominal type found!");
1555-
1556-
for (auto result : systemNominal->lookupDirect(Id_makeInvocationEncoder)) {
1557-
auto *func = dyn_cast<FuncDecl>(result);
1558-
if (func && func->isDistributedActorSystemMakeInvocationEncoder()) {
1559-
return func;
1560-
}
1561-
}
1562-
1563-
return nullptr;
1564-
}
1565-
1566-
FuncDecl *
1567-
ASTContext::getRecordGenericSubstitutionOnDistributedInvocationEncoder(
1568-
NominalTypeDecl *nominal) const {
1569-
if (!nominal)
1570-
return nullptr;
1571-
1572-
for (auto result : nominal->lookupDirect(Id_recordGenericSubstitution)) {
1573-
auto *func = dyn_cast<FuncDecl>(result);
1574-
if (func &&
1575-
func->isDistributedTargetInvocationEncoderRecordGenericSubstitution()) {
1576-
return func;
1577-
}
1578-
}
1579-
1580-
return nullptr;
1581-
}
1582-
1583-
AbstractFunctionDecl *ASTContext::getRecordArgumentOnDistributedInvocationEncoder(
1584-
NominalTypeDecl *nominal) const {
1585-
if (!nominal)
1586-
return nullptr;
1587-
1588-
return evaluateOrDefault(
1589-
nominal->getASTContext().evaluator,
1590-
GetDistributedTargetInvocationEncoderRecordArgumentFunctionRequest{nominal},
1591-
nullptr);
1592-
}
1593-
1594-
AbstractFunctionDecl *ASTContext::getRecordReturnTypeOnDistributedInvocationEncoder(
1595-
NominalTypeDecl *nominal) const {
1596-
if (!nominal)
1597-
return nullptr;
1598-
1599-
return evaluateOrDefault(
1600-
nominal->getASTContext().evaluator,
1601-
GetDistributedTargetInvocationEncoderRecordReturnTypeFunctionRequest{nominal},
1602-
nullptr);
1603-
}
1604-
1605-
AbstractFunctionDecl *ASTContext::getRecordErrorTypeOnDistributedInvocationEncoder(
1606-
NominalTypeDecl *nominal) const {
1607-
if (!nominal)
1608-
return nullptr;
1609-
1610-
return evaluateOrDefault(
1611-
nominal->getASTContext().evaluator,
1612-
GetDistributedTargetInvocationEncoderRecordErrorTypeFunctionRequest{nominal},
1613-
nullptr);
1614-
}
1615-
1616-
AbstractFunctionDecl *ASTContext::getDecodeNextArgumentOnDistributedInvocationDecoder(
1617-
NominalTypeDecl *nominal) const {
1618-
if (!nominal)
1619-
return nullptr;
1620-
1621-
return evaluateOrDefault(
1622-
nominal->getASTContext().evaluator,
1623-
GetDistributedTargetInvocationDecoderDecodeNextArgumentFunctionRequest{nominal},
1624-
nullptr);
1625-
}
1626-
1627-
AbstractFunctionDecl *ASTContext::getOnReturnOnDistributedTargetInvocationResultHandler(
1628-
NominalTypeDecl *nominal) const {
1629-
if (!nominal)
1630-
return nullptr;
1631-
1632-
return evaluateOrDefault(
1633-
nominal->getASTContext().evaluator,
1634-
GetDistributedTargetInvocationResultHandlerOnReturnFunctionRequest{nominal},
1635-
nullptr);
1636-
}
1637-
1638-
FuncDecl *ASTContext::getDoneRecordingOnDistributedInvocationEncoder(
1639-
NominalTypeDecl *nominal) const {
1640-
1641-
llvm::SmallVector<ValueDecl *, 2> results;
1642-
nominal->lookupQualified(nominal, DeclNameRef(Id_doneRecording),
1643-
SourceLoc(), NL_QualifiedDefault, results);
1644-
for (auto result : results) {
1645-
auto *fd = dyn_cast<FuncDecl>(result);
1646-
if (!fd)
1647-
continue;
1648-
1649-
if (fd->getParameters()->size() != 0)
1650-
continue;
1651-
1652-
if (fd->getResultInterfaceType()->isVoid() &&
1653-
fd->hasThrows() &&
1654-
!fd->hasAsync())
1655-
return fd;
1656-
}
1657-
1658-
return nullptr;
1659-
}
1660-
16611548
FuncDecl *ASTContext::getHashValueForDecl() const {
16621549
if (getImpl().HashValueForDecl)
16631550
return getImpl().HashValueForDecl;

0 commit comments

Comments
 (0)