Skip to content

Commit 406af83

Browse files
committed
[Distributed] Runtime/IRGen: Allow passing substitutions to distributed accessor
Accept an optional list of substitutions which are required to form a call to a generic distributed thunk.
1 parent 925b598 commit 406af83

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

lib/IRGen/GenDistributed.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ static CanSILFunctionType getAccessorType(IRGenModule &IGM,
161161
{/*argumentBuffer=*/getRawPointerParameter(),
162162
/*argumentTypes=*/getRawPointerParameter(),
163163
/*resultBuffer=*/getRawPointerParameter(),
164+
/*substitutions=*/getRawPointerParameter(),
164165
/*actor=*/targetTy->getParameters().back()},
165166
/*Yields=*/{},
166167
/*Results=*/{},
@@ -437,6 +438,8 @@ void DistributedAccessor::emit() {
437438
auto *argTypes = params.claimNext();
438439
// UnsafeRawPointer that is used to store the result.
439440
auto *resultBuffer = params.claimNext();
441+
// UnsafeRawPointer that represents a list of substitutions
442+
auto *substitutions = params.claimNext();
440443
// Reference to a `self` of the actor to be called.
441444
auto *actorSelf = params.claimNext();
442445

stdlib/public/Concurrency/Actor.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1723,14 +1723,16 @@ void *swift_distributed_get_generic_environment(const char *targetNameStart,
17231723
/// _ targetNameLength: UInt,
17241724
/// argumentBuffer: Builtin.RawPointer,
17251725
/// argumentTypes: UnsafeBufferPointer<Any.Type>,
1726-
/// resultBuffer: Builtin.RawPointer
1726+
/// resultBuffer: Builtin.RawPointer,
1727+
/// substitutions: UnsafeRawPointer?
17271728
/// ) async throws
17281729
using TargetExecutorSignature =
17291730
AsyncSignature<void(/*on=*/DefaultActor *,
17301731
/*targetName=*/const char *, /*targetNameSize=*/size_t,
17311732
/*argumentBuffer=*/void *,
17321733
/*argumentTypes=*/const Metadata *const *,
17331734
/*resultBuffer=*/void *,
1735+
/*substitutions=*/void *,
17341736
/*resumeFunc=*/TaskContinuationFunction *,
17351737
/*callContext=*/AsyncContext *),
17361738
/*throws=*/true>;
@@ -1742,12 +1744,15 @@ TargetExecutorSignature::FunctionType swift_distributed_execute_target;
17421744
/// Accessor takes:
17431745
/// - an async context
17441746
/// - an argument buffer as a raw pointer
1747+
/// - a list of all argument types (with substitutions applied)
17451748
/// - a result buffer as a raw pointer
1749+
/// - a list of substitutions
17461750
/// - a reference to an actor to execute method on.
17471751
using DistributedAccessorSignature =
17481752
AsyncSignature<void(/*argumentBuffer=*/void *,
17491753
/*argumentTypes=*/const Metadata *const *,
17501754
/*resultBuffer=*/void *,
1755+
/*substitutions=*/void *,
17511756
/*actor=*/HeapObject *),
17521757
/*throws=*/true>;
17531758

@@ -1777,6 +1782,7 @@ void ::swift_distributed_execute_target(
17771782
void *argumentBuffer,
17781783
const Metadata *const *argumentTypes,
17791784
void *resultBuffer,
1785+
void *substitutions,
17801786
TaskContinuationFunction *resumeFunc,
17811787
AsyncContext *callContext) {
17821788
auto *accessor = findDistributedAccessor(targetNameStart, targetNameLength);
@@ -1813,5 +1819,6 @@ void ::swift_distributed_execute_target(
18131819
accessorEntry(calleeContext,
18141820
argumentBuffer, argumentTypes,
18151821
resultBuffer,
1822+
substitutions,
18161823
actor);
18171824
}

stdlib/public/Distributed/DistributedActorSystem.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,8 @@ extension DistributedActorSystem {
307307
mangledTargetName, UInt(mangledTargetName.count),
308308
argumentBuffer: hargs.buffer._rawValue, // TODO(distributed): pass the invocationDecoder instead, so we can decode inside IRGen directly into the argument explosion
309309
argumentTypes: argumentTypesBuffer.baseAddress!._rawValue,
310-
resultBuffer: resultBuffer._rawValue
310+
resultBuffer: resultBuffer._rawValue,
311+
substitutions: UnsafeRawPointer(substitutionsBuffer)
311312
)
312313

313314
func onReturn<R>(_ resultTy: R.Type) async throws {
@@ -327,7 +328,8 @@ func _executeDistributedTarget(
327328
_ targetName: UnsafePointer<UInt8>, _ targetNameLength: UInt,
328329
argumentBuffer: Builtin.RawPointer, // HeterogeneousBuffer of arguments
329330
argumentTypes: Builtin.RawPointer,
330-
resultBuffer: Builtin.RawPointer
331+
resultBuffer: Builtin.RawPointer,
332+
substitutions: UnsafeRawPointer?
331333
) async throws
332334

333335
// ==== ----------------------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)