Skip to content

Commit d66eeae

Browse files
authored
Merge pull request #72107 from xedin/rework-getting-types-from-system
[AST/Sema] Distributed: Refactor type and member queries
2 parents d70ce6b + 1da0164 commit d66eeae

10 files changed

+367
-412
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: 80 additions & 17 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(DeclContext *actorOrExtension,
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.
@@ -47,12 +57,6 @@ Type getDistributedActorSystemType(NominalTypeDecl *actor);
4757
/// Determine the `ID` type for the given actor.
4858
Type getDistributedActorIDType(NominalTypeDecl *actor);
4959

50-
/// Similar to `getDistributedSerializationRequirementType`, however, from the
51-
/// perspective of a concrete function. This way we're able to get the
52-
/// serialization requirement for specific members, also in protocols.
53-
Type getSerializationRequirementTypesForMember(
54-
ValueDecl *member, llvm::SmallPtrSet<ProtocolDecl *, 2> &serializationRequirements);
55-
5660
/// Get specific 'SerializationRequirement' as defined in 'nominal'
5761
/// type, which must conform to the passed 'protocol' which is expected
5862
/// to require the 'SerializationRequirement'.
@@ -66,6 +70,12 @@ AbstractFunctionDecl *
6670
getAssociatedDistributedInvocationDecoderDecodeNextArgumentFunction(
6771
ValueDecl *thunk);
6872

73+
Type getDistributedActorSerializationType(DeclContext *actorOrExtension);
74+
75+
/// Get the specific 'SerializationRequirement' type of a specific distributed
76+
/// actor system.
77+
Type getDistributedActorSystemSerializationType(NominalTypeDecl *system);
78+
6979
/// Get the specific 'InvocationEncoder' type of a specific distributed actor
7080
/// system.
7181
Type getDistributedActorSystemInvocationEncoderType(NominalTypeDecl *system);
@@ -81,17 +91,6 @@ Type getDistributedActorSystemResultHandlerType(NominalTypeDecl *system);
8191
/// Get the 'ActorID' type of a specific distributed actor system.
8292
Type getDistributedActorSystemActorIDType(NominalTypeDecl *system);
8393

84-
/// Get the specific protocols that the `SerializationRequirement` specifies,
85-
/// and all parameters / return types of distributed targets must conform to.
86-
///
87-
/// E.g. if a system declares `typealias SerializationRequirement = Codable`
88-
/// then this will return `{encodableProtocol, decodableProtocol}`.
89-
///
90-
/// Returns an empty set if the requirement was `Any`.
91-
llvm::SmallPtrSet<ProtocolDecl *, 2>
92-
getDistributedSerializationRequirementProtocols(
93-
NominalTypeDecl *decl, ProtocolDecl* protocol);
94-
9594
/// Check if the `allRequirements` represent *exactly* the
9695
/// `Encodable & Decodable` (also known as `Codable`) requirement.
9796
///
@@ -115,6 +114,70 @@ getDistributedSerializationRequirements(
115114
ProtocolDecl *protocol,
116115
llvm::SmallPtrSetImpl<ProtocolDecl *> &requirementProtos);
117116

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

120183
#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)