Skip to content

Commit e9c7f3c

Browse files
authored
[Distributed] Target identifiers for protocol calls (#70928)
1 parent 9eb9a2e commit e9c7f3c

File tree

58 files changed

+1304
-250
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1304
-250
lines changed

include/swift/ABI/Metadata.h

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4970,7 +4970,7 @@ class DynamicReplacementScope
49704970
/// and then called through a fully-abstracted entry point whose arguments
49714971
/// can be constructed in code.
49724972
template <typename Runtime>
4973-
struct TargetAccessibleFunctionRecord final {
4973+
struct TargetAccessibleFunctionRecord {
49744974
public:
49754975
/// The name of the function, which is a unique string assigned to the
49764976
/// function so it can be looked up later.
@@ -4992,7 +4992,24 @@ struct TargetAccessibleFunctionRecord final {
49924992
AccessibleFunctionFlags Flags;
49934993
};
49944994

4995+
/// More advanced than AccessibleFunctionRecord and contains Actor name
4996+
template <typename Runtime>
4997+
struct TargetAccessibleProtocolRequirementFunctionRecord
4998+
: public TargetAccessibleFunctionRecord<Runtime> {
4999+
public:
5000+
/// The concrete Actor type for this accessor.
5001+
RelativeDirectPointer<const char, /*nullable*/ false> ConcreteActorName;
5002+
5003+
/// The concrete witness method mangled name.
5004+
/// The record name for such record is the mangled name of the protocol
5005+
/// method. This is the mangled name of the concrete witness method.
5006+
RelativeDirectPointer<const char, /*nullable*/ false>
5007+
ConcreteWitnessMethodName;
5008+
};
5009+
49955010
using AccessibleFunctionRecord = TargetAccessibleFunctionRecord<InProcess>;
5011+
using AccessibleProtocolRequirementFunctionRecord =
5012+
TargetAccessibleProtocolRequirementFunctionRecord<InProcess>;
49965013

49975014
enum class PackLifetime : uint8_t {
49985015
OnStack = 0,

include/swift/ABI/MetadataValues.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1574,6 +1574,8 @@ namespace SpecialPointerAuthDiscriminators {
15741574

15751575
/// Functions accessible at runtime (i.e. distributed method accessors).
15761576
const uint16_t AccessibleFunctionRecord = 0x438c; // = 17292
1577+
const uint16_t AccessibleProtocolRequirementFunctionRecord =
1578+
0xa98e; // = 43406
15771579

15781580
/// C type GetExtraInhabitantTag function descriminator
15791581
const uint16_t GetExtraInhabitantTagFunction = 0x392e; // = 14638

include/swift/AST/ASTMangler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ class ASTMangler : public Mangler {
159159
DistributedThunk,
160160
DistributedAccessor,
161161
AccessibleFunctionRecord,
162+
AccessibleProtocolRequirementFunctionRecord,
162163
BackDeploymentThunk,
163164
BackDeploymentFallback,
164165
HasSymbolQuery,

include/swift/AST/Attr.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2603,6 +2603,28 @@ class RawLayoutAttr final : public DeclAttribute {
26032603
}
26042604
};
26052605

2606+
/// The @_distributedThunkTarget(for:) attribute.
2607+
class DistributedThunkTargetAttr final
2608+
: public DeclAttribute {
2609+
2610+
AbstractFunctionDecl *TargetFunction;
2611+
2612+
public:
2613+
DistributedThunkTargetAttr(AbstractFunctionDecl *target)
2614+
: DeclAttribute(DeclAttrKind::DistributedThunkTarget, SourceLoc(),
2615+
SourceRange(),
2616+
/*Implicit=*/false),
2617+
TargetFunction(target) {}
2618+
2619+
AbstractFunctionDecl *getTargetFunction() const {
2620+
return TargetFunction;
2621+
}
2622+
2623+
static bool classof(const DeclAttribute *DA) {
2624+
return DA->getKind() == DeclAttrKind::DistributedThunkTarget;
2625+
}
2626+
};
2627+
26062628
/// Predicate used to filter MatchingAttributeRange.
26072629
template <typename ATTR, bool AllowInvalid> struct ToAttributeKind {
26082630
ToAttributeKind() {}

include/swift/AST/Decl.h

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2773,6 +2773,12 @@ class ValueDecl : public Decl {
27732773
Bits.ValueDecl.Synthesized = value;
27742774
}
27752775

2776+
/// Does this have a 'distributed' modifier?
2777+
///
2778+
/// Only member methods and computed properties of a `distributed actor`
2779+
/// can be distributed.
2780+
bool isDistributed() const;
2781+
27762782
bool hasName() const { return bool(Name); }
27772783
bool isOperator() const { return Name.isOperator(); }
27782784

@@ -5869,9 +5875,6 @@ class AbstractStorageDecl : public ValueDecl {
58695875

58705876
bool hasAnyNativeDynamicAccessors() const;
58715877

5872-
/// Does this have a 'distributed' modifier?
5873-
bool isDistributed() const;
5874-
58755878
/// Return a distributed thunk if this computed property is marked as
58765879
/// 'distributed' and and nullptr otherwise.
58775880
FuncDecl *getDistributedThunk() const;
@@ -7379,9 +7382,6 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
73797382
/// Returns if the function is 'rethrows' or 'reasync'.
73807383
bool hasPolymorphicEffect(EffectKind kind) const;
73817384

7382-
/// Returns 'true' if the function is distributed.
7383-
bool isDistributed() const;
7384-
73857385
/// Is this a thunk function used to access a distributed method
73867386
/// or computed property outside of its actor isolation context?
73877387
bool isDistributedThunk() const {
@@ -7528,6 +7528,15 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
75287528
getSILSynthesizeKind() == SILSynthesizeKind::DistributedActorFactory;
75297529
}
75307530

7531+
/// Return a vector of distributed requirements that this distributed method
7532+
/// is implementing.
7533+
///
7534+
/// If the method is witness to multiple requirements this is incorrect and
7535+
/// should be diagnosed during type-checking as it may make remoteCalls
7536+
/// ambiguous.
7537+
llvm::ArrayRef<ValueDecl *>
7538+
getDistributedMethodWitnessedProtocolRequirements() const;
7539+
75317540
/// Determines whether this function is a 'remoteCall' function,
75327541
/// which is used as ad-hoc protocol requirement by the
75337542
/// 'DistributedActorSystem' protocol.

include/swift/AST/DeclAttr.def

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,10 @@ SIMPLE_DECL_ATTR(_noExistentials, NoExistentials,
485485
SIMPLE_DECL_ATTR(_noObjCBridging, NoObjCBridging,
486486
OnAbstractFunction | OnSubscript | UserInaccessible | ABIStableToAdd | ABIStableToRemove | APIStableToAdd | APIStableToRemove,
487487
155)
488-
LAST_DECL_ATTR(NoObjCBridging)
488+
DECL_ATTR(_distributedThunkTarget, DistributedThunkTarget,
489+
OnAbstractFunction | UserInaccessible | ABIStableToAdd | ABIBreakingToRemove | APIStableToAdd | APIStableToRemove,
490+
156)
491+
LAST_DECL_ATTR(DistributedThunkTarget)
489492

490493
#undef DECL_ATTR_ALIAS
491494
#undef CONTEXTUAL_DECL_ATTR_ALIAS

include/swift/AST/TypeCheckRequests.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,6 +1372,27 @@ class GetDistributedActorArgumentDecodingMethodRequest :
13721372
bool isCached() const { return true; }
13731373
};
13741374

1375+
/// Find out if a distributed method is implementing a distributed protocol
1376+
/// requirement.
1377+
class GetDistributedMethodWitnessedProtocolRequirements :
1378+
public SimpleRequest<GetDistributedMethodWitnessedProtocolRequirements,
1379+
llvm::ArrayRef<ValueDecl *> (AbstractFunctionDecl *),
1380+
RequestFlags::Cached> {
1381+
public:
1382+
using SimpleRequest::SimpleRequest;
1383+
1384+
private:
1385+
friend SimpleRequest;
1386+
1387+
llvm::ArrayRef<ValueDecl *> evaluate(
1388+
Evaluator &evaluator,
1389+
AbstractFunctionDecl *nominal) const;
1390+
1391+
public:
1392+
// Caching
1393+
bool isCached() const { return true; }
1394+
};
1395+
13751396
/// Retrieve the static "shared" property within a global actor that provides
13761397
/// the actor instance representing the global actor.
13771398
///

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ SWIFT_REQUEST(TypeChecker, GetDistributedActorSystemPropertyRequest,
150150
SWIFT_REQUEST(TypeChecker, GetDistributedRemoteCallTargetInitFunctionRequest,
151151
ConstructorDecl *(NominalTypeDecl *),
152152
Cached, NoLocationInfo)
153+
SWIFT_REQUEST(TypeChecker, GetDistributedMethodWitnessedProtocolRequirements,
154+
ArrayRef<ValueDecl *> (AbstractFunctionDecl *),
155+
Cached, NoLocationInfo)
153156
SWIFT_REQUEST(TypeChecker, GetDistributedRemoteCallArgumentInitFunctionRequest,
154157
ConstructorDecl *(NominalTypeDecl *),
155158
Cached, NoLocationInfo)

include/swift/Demangling/DemangleNodes.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,9 @@ NODE(AsyncSuspendResumePartialFunction)
358358
NODE(AccessibleFunctionRecord)
359359
NODE(CompileTimeConst)
360360

361+
// Added in Swift 5.11
362+
NODE(AccessibleProtocolRequirementFunctionRecord)
363+
361364
// Added in Swift 5.7
362365
NODE(BackDeploymentThunk)
363366
NODE(BackDeploymentFallback)

include/swift/IRGen/Linking.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,8 @@ class LinkEntity {
382382
/// A SIL global variable. The pointer is a SILGlobalVariable*.
383383
SILGlobalVariable,
384384

385-
/// An outlined read-only global object. The pointer is a SILGlobalVariable*.
385+
/// An outlined read-only global object. The pointer is a
386+
/// SILGlobalVariable*.
386387
ReadOnlyGlobalObject,
387388

388389
// These next few are protocol-conformance kinds.
@@ -513,13 +514,15 @@ class LinkEntity {
513514

514515
/// The pointer is SILFunction*
515516
DistributedAccessor,
516-
/// An async function pointer for a distributed accessor (method or property).
517+
/// An async function pointer for a distributed accessor (method or
518+
/// property).
517519
/// The pointer is a SILFunction*.
518520
DistributedAccessorAsyncPointer,
519521

520522
/// Accessible function record, which describes a function that can be
521523
/// looked up by name by the runtime.
522524
AccessibleFunctionRecord,
525+
AccessibleProtocolRequirementFunctionRecord,
523526

524527
/// Extended existential type shape.
525528
/// Pointer is the (generalized) existential type.

0 commit comments

Comments
 (0)