Skip to content

Commit cb34c82

Browse files
committed
WIP trying to use buildGenericSignature
1 parent 2bdef63 commit cb34c82

File tree

2 files changed

+50
-17
lines changed

2 files changed

+50
-17
lines changed

lib/IRGen/GenDistributed.cpp

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -263,31 +263,43 @@ static CanSILFunctionType getAccessorType(IRGenModule &IGM,
263263
// Build generic signature that includes all contextual generic parameters.
264264
GenericSignature signature;
265265
{
266-
SmallVector<GenericTypeParamType *, 4> genericParams;
267-
SmallVector<Requirement, 4> genericRequirements;
266+
SmallVector<GenericTypeParamType *, 2> addedParameters;
267+
SmallVector<Requirement, 2> addedRequirements;
268268

269269
auto *actor = getDistributedActorOf(Target);
270270
assert(actor);
271271

272-
for (auto *genericParam : actor->getInnermostGenericParamTypes()) {
273-
genericParams.push_back(genericParam);
272+
unsigned targetDepth = 1;
273+
unsigned targetIndex = 0;
274274

275-
// and also forward all requirements this generic parameter might have.
276-
for (auto req : actor->getGenericRequirements()) {
277-
if (req.getFirstType()->isEqual(genericParam)) {
278-
genericRequirements.push_back(req);
279-
}
275+
if (Target->getGenericSignature()) {
276+
for (auto param: Target->getGenericSignature().getGenericParams()) {
277+
targetDepth = std::max(targetDepth, param->getDepth());
278+
targetIndex = std::max(targetIndex, param->getIndex());
279+
}
280+
// Target->getGenericSignature().getInnermostGenericParams().size();
281+
for (auto param: Target->getGenericSignature().getInnermostGenericParams()) {
282+
targetDepth = std::max(targetDepth, param->getDepth());
283+
targetIndex = std::max(targetIndex, param->getIndex());
284+
}
285+
if (!Target->getGenericSignature().getInnermostGenericParams().empty()) {
286+
targetIndex += 1;
280287
}
281288
}
282289

283-
// Add a generic parameter `D` which stands for decoder type in the
284-
// accessor signature - `inout D`.
285-
genericParams.push_back(decoderType);
286-
// Add a requirement that decoder conforms to the expected protocol.
287-
genericRequirements.push_back(
288-
{RequirementKind::Conformance, decoderType, decoderProtocolTy});
290+
auto decoderParamTy = GenericTypeParamType::get(
291+
// /*isParameterPack=*/false, /*depth=*/1, /*index=*/1, Context);
292+
/*isParameterPack=*/false,
293+
targetDepth,
294+
targetIndex,
295+
Context);
296+
addedParameters.push_back(decoderParamTy);
289297

290-
signature = GenericSignature::get(genericParams, genericRequirements);
298+
// Add a requirement that decoder conforms to the expected protocol.
299+
addedRequirements.push_back(
300+
{RequirementKind::Conformance, decoderParamTy, decoderProtocolTy});
301+
signature = buildGenericSignature(Context, Target->getGenericSignature(),
302+
addedParameters, addedRequirements);
291303
}
292304

293305
auto accessorTy = GenericFunctionType::get(

test/Distributed/Runtime/distributed_actor_hop_to.swift

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ protocol LifecycleWatch: DistributedActor where ActorSystem == FakeRoundtripActo
2626

2727
extension LifecycleWatch {
2828
func watch<T: Codable>(x: Int, _ y: T) async throws {
29+
self.preconditionIsolated()
2930
print("executed: \(#function) - x = \(x), y = \(y)")
3031
}
3132

@@ -39,15 +40,35 @@ extension LifecycleWatch {
3940
distributed actor Worker: LifecycleWatch {
4041
}
4142

43+
extension Worker {
44+
distributed actor Inside<Something> {
45+
distributed func test<A: Codable>(_: A) async throws {
46+
self.preconditionIsolated()
47+
print("executed: \(#function)")
48+
}
49+
distributed func moreParams<A: Codable, B: Codable>(_: A, _: B) async throws {
50+
self.preconditionIsolated()
51+
print("executed: \(#function)")
52+
}
53+
}
54+
}
55+
4256
@main struct Main {
4357
static func main() async {
44-
let worker: any LifecycleWatch = Worker(actorSystem: DefaultDistributedActorSystem())
58+
let system = DefaultDistributedActorSystem()
59+
let worker: any LifecycleWatch = Worker(actorSystem: system)
4560
try! await worker.test(x: 42, "on protocol")
4661

4762
// CHECK: executed: test(x:_:)
4863
// CHECK: executed: watch(x:_:) - x = 42, y = on protocol
4964
// CHECK: done executed: test(x:_:)
5065

66+
try! await Worker.Inside<String>(actorSystem: system).test(42)
67+
// CHECK: executed: test
68+
69+
try! await Worker.Inside<String>(actorSystem: system).moreParams(21, 42)
70+
// CHECK: executed: moreParams
71+
5172
print("OK") // CHECK: OK
5273
}
5374
}

0 commit comments

Comments
 (0)