Skip to content

Commit 284487c

Browse files
authored
Merge pull request #81831 from ktoso/pick-irgen-mangling-fix-distributed
2 parents 18a3f08 + 7c21ea8 commit 284487c

File tree

3 files changed

+267
-0
lines changed

3 files changed

+267
-0
lines changed

lib/IRGen/IRGenMangler.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ class IRGenMangler : public Mangle::ASTMangler {
5151
beginMangling();
5252
appendEntity(func);
5353
appendOperator("Tj");
54+
if (func->isDistributedThunk())
55+
appendSymbolKind(SymbolKind::DistributedThunk);
5456
return finalize();
5557
}
5658

@@ -86,6 +88,8 @@ class IRGenMangler : public Mangle::ASTMangler {
8688
beginMangling();
8789
appendEntity(func);
8890
appendOperator("Tq");
91+
if (func->isDistributedThunk())
92+
appendSymbolKind(SymbolKind::DistributedThunk);
8993
return finalize();
9094
}
9195

lib/SIL/IR/SILPrinter.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,11 +332,27 @@ void SILDeclRef::print(raw_ostream &OS) const {
332332
auto *accessor = dyn_cast<AccessorDecl>(getDecl());
333333
if (!accessor) {
334334
printValueDecl(getDecl(), OS);
335+
if (isDistributed()) {
336+
OS << "!distributed";
337+
OS << "(" << getDecl() << ")";
338+
}
339+
if (isDistributedThunk()) {
340+
OS << "!distributed_thunk";
341+
OS << "(" << getDecl() << ")";
342+
}
335343
isDot = false;
336344
break;
337345
}
338346

339347
printValueDecl(accessor->getStorage(), OS);
348+
if (isDistributed()) {
349+
OS << "!distributed";
350+
OS << "(" << getDecl() << ")";
351+
}
352+
if (isDistributedThunk()) {
353+
OS << "!distributed_thunk";
354+
OS << "(" << getDecl() << ")";
355+
}
340356
switch (accessor->getAccessorKind()) {
341357
case AccessorKind::WillSet:
342358
OS << "!willSet";
Lines changed: 247 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,247 @@
1+
// RUN: %empty-directory(%t/src)
2+
// RUN: split-file %s %t/src
3+
4+
/// Build the fake actor systems lib
5+
// RUN: %target-build-swift \
6+
// RUN: -target %target-swift-6.0-abi-triple \
7+
// RUN: -parse-as-library -emit-library \
8+
// RUN: -emit-module-path %t/FakeDistributedActorSystems.swiftmodule \
9+
// RUN: -module-name FakeDistributedActorSystems \
10+
// RUN: %S/../Inputs/FakeDistributedActorSystems.swift \
11+
// RUN: -enable-library-evolution \
12+
// RUN: -Xfrontend -validate-tbd-against-ir=all \
13+
// RUN: -o %t/%target-library-name(FakeDistributedActorSystems)
14+
15+
/// Build the ResilientAPILib
16+
// RUN: %target-build-swift \
17+
// RUN: -target %target-swift-6.0-abi-triple \
18+
// RUN: -parse-as-library -emit-library \
19+
// RUN: -emit-module-path %t/ResilientAPILib.swiftmodule \
20+
// RUN: -module-name ResilientAPILib \
21+
// RUN: -I %t \
22+
// RUN: -L %t \
23+
// RUN: -plugin-path %swift-plugin-dir \
24+
// RUN: %t/src/ResilientAPILib.swift \
25+
// RUN: %t/src/ResilientAPILibFile2.swift \
26+
// RUN: -lFakeDistributedActorSystems \
27+
// RUN: -enable-library-evolution \
28+
// RUN: -Xfrontend -validate-tbd-against-ir=all \
29+
// RUN: -o %t/%target-library-name(ResilientAPILib)
30+
31+
/// Build the ResilientImplLib
32+
// RUN: %target-build-swift \
33+
// RUN: -target %target-swift-6.0-abi-triple \
34+
// RUN: -parse-as-library -emit-library \
35+
// RUN: -module-name ResilientImplLib \
36+
// RUN: -I %t \
37+
// RUN: -L %t \
38+
// RUN: -plugin-path %swift-plugin-dir \
39+
// RUN: %t/src/ResilientImplLib.swift \
40+
// RUN: -lFakeDistributedActorSystems \
41+
// RUN: -lResilientAPILib \
42+
// RUN: -enable-library-evolution \
43+
// RUN: -Xfrontend -validate-tbd-against-ir=all \
44+
// RUN: -emit-irgen \
45+
// RUN: | %FileCheck %s --color --dump-input=always
46+
47+
// REQUIRES: executable_test
48+
// REQUIRES: concurrency
49+
// REQUIRES: distributed
50+
51+
// Locating the built libraries failed on Linux (construction of test case),
52+
// but we primarily care about macOS in this test
53+
// UNSUPPORTED: OS=linux-gnu
54+
55+
// %env does not seem to work on Windows
56+
// UNSUPPORTED: OS=windows-msvc
57+
58+
// UNSUPPORTED: use_os_stdlib
59+
// UNSUPPORTED: back_deployment_runtime
60+
// UNSUPPORTED: remote_run || device_run
61+
62+
//--- ResilientAPILib.swift
63+
64+
import Distributed
65+
import FakeDistributedActorSystems
66+
67+
@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
68+
public struct Response: Codable {}
69+
70+
@Resolvable
71+
@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
72+
public protocol DistributedNotificationService: DistributedActor where ActorSystem == FakeRoundtripActorSystem {
73+
distributed func getArray(a1: [Int], a2: String?) -> [Response]
74+
}
75+
76+
public protocol IdentifiableActor {
77+
static var actorID: FakeRoundtripActorSystem.ActorID { get }
78+
}
79+
80+
//--- ResilientAPILibFile2.swift
81+
82+
final class Another { }
83+
84+
//--- ResilientImplLib.swift
85+
86+
import ResilientAPILib
87+
88+
import Distributed
89+
import FakeDistributedActorSystems
90+
91+
@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
92+
public distributed actor ServiceImpl: DistributedNotificationService, IdentifiableActor {
93+
public typealias ActorSystem = FakeRoundtripActorSystem
94+
95+
public static var actorID: FakeRoundtripActorSystem.ActorID {
96+
.init(parse: "test")
97+
}
98+
99+
public distributed func getArray(a1: [Int], a2: String?) -> [Response] {
100+
[]
101+
}
102+
}
103+
104+
extension ServiceImpl {}
105+
106+
//--- ResilientImplLibFile2.swift
107+
108+
class AnotherImpl {}
109+
110+
111+
// @"protocol conformance descriptor for ResilientImplLib.ServiceImpl : ResilientAPILib.DistributedNotificationService in ResilientImplLib" = constant {
112+
// CHECK: @"$s16ResilientImplLib07ServiceB0C0A6APILib023DistributedNotificationD0AAMc" = constant {
113+
// CHECK-SAME: i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i16, i16, i32, i32
114+
// CHECK-SAME: } {
115+
// CHECK-SAME: i32 add (
116+
// CHECK-SAME: i32 trunc (
117+
// CHECK-SAME: i64 sub (
118+
// i64 ptrtoint (ptr @"got.protocol descriptor for ResilientAPILib.DistributedNotificationService" to i64),
119+
// CHECK-SAME: i64 ptrtoint (ptr @"got.$s15ResilientAPILib30DistributedNotificationServiceMp" to i64),
120+
// i64 ptrtoint (ptr @"protocol conformance descriptor for ResilientImplLib.ServiceImpl : ResilientAPILib.DistributedNotificationService in ResilientImplLib" to i64)
121+
// CHECK-SAME: i64 ptrtoint (ptr @"$s16ResilientImplLib07ServiceB0C0A6APILib023DistributedNotificationD0AAMc" to i64)
122+
// CHECK-SAME: ) to i32
123+
// CHECK-SAME: ),
124+
// CHECK-SAME: i32 1
125+
// CHECK-SAME: ),
126+
//
127+
// CHECK-SAME: i32 trunc (
128+
// CHECK-SAME: i64 sub (
129+
// i64 ptrtoint (ptr @"nominal type descriptor for ResilientImplLib.ServiceImpl" to i64),
130+
// CHECK-SAME: i64 ptrtoint (ptr @"$s16ResilientImplLib07ServiceB0CMn" to i64),
131+
// CHECK-SAME: i64 ptrtoint (ptr getelementptr inbounds (
132+
// CHECK-SAME: { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i16, i16, i32, i32 },
133+
// CHECK-SAME: ptr @"$s16ResilientImplLib07ServiceB0C0A6APILib023DistributedNotificationD0AAMc",
134+
// CHECK-SAME: i32 0, i32 1
135+
// CHECK-SAME: ) to i64)
136+
// CHECK-SAME: ) to i32
137+
// CHECK-SAME: ),
138+
//
139+
// CHECK-SAME: i32 0,
140+
// CHECK-SAME: i32 196608,
141+
// CHECK-SAME: i32 3,
142+
//
143+
// CHECK-SAME: i32 add (
144+
// CHECK-SAME: i32 trunc (
145+
// CHECK-SAME: i64 sub (
146+
// i64 ptrtoint (ptr @"got.base conformance descriptor for ResilientAPILib.DistributedNotificationService: Distributed.DistributedActor" to i64),
147+
// CHECK-SAME: i64 ptrtoint (ptr @"got.$s15ResilientAPILib30DistributedNotificationServiceP0C00C5ActorTb" to i64),
148+
// CHECK-SAME: i64 ptrtoint (ptr getelementptr inbounds (
149+
// CHECK-SAME: { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i16, i16, i32, i32 },
150+
// CHECK-SAME: ptr @"$s16ResilientImplLib07ServiceB0C0A6APILib023DistributedNotificationD0AAMc",
151+
// CHECK-SAME: i32 0, i32 5
152+
// CHECK-SAME: ) to i64)
153+
// CHECK-SAME: ) to i32
154+
// CHECK-SAME: ),
155+
// CHECK-SAME: i32 1
156+
// CHECK-SAME: ),
157+
//
158+
// CHECK-SAME: i32 trunc (
159+
// CHECK-SAME: i64 sub (
160+
// CHECK-SAME: i64 ptrtoint (ptr getelementptr (
161+
// CHECK-SAME: i8, ptr @"associated conformance 16ResilientImplLib07ServiceB0C0A6APILib023DistributedNotificationD0AA0F00F5Actor",
162+
// CHECK-SAME: i64 1
163+
// CHECK-SAME: ) to i64),
164+
// CHECK-SAME: i64 ptrtoint (ptr getelementptr inbounds (
165+
// CHECK-SAME: { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i16, i16, i32, i32 },
166+
// CHECK-SAME: ptr @"$s16ResilientImplLib07ServiceB0C0A6APILib023DistributedNotificationD0AAMc",
167+
// CHECK-SAME: i32 0, i32 6
168+
// CHECK-SAME: ) to i64)
169+
// CHECK-SAME: ) to i32
170+
// CHECK-SAME: ),
171+
//
172+
// CHECK-SAME: i32 add (
173+
// CHECK-SAME: i32 trunc (
174+
// CHECK-SAME: i64 sub (
175+
// i64 ptrtoint (ptr @"got.method descriptor for ResilientAPILib.DistributedNotificationService.getArray(a1: [Swift.Int], a2: Swift.String?) -> [ResilientAPILib.Response]" to i64),
176+
// CHECK-SAME: i64 ptrtoint (ptr @"got.$s15ResilientAPILib30DistributedNotificationServiceP8getArray2a12a2SayAA8ResponseVGSaySiG_SSSgtFTq" to i64),
177+
// CHECK-SAME: i64 ptrtoint (ptr getelementptr inbounds (
178+
// CHECK-SAME: { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i16, i16, i32, i32 },
179+
// CHECK-SAME: ptr @"$s16ResilientImplLib07ServiceB0C0A6APILib023DistributedNotificationD0AAMc",
180+
// CHECK-SAME: i32 0, i32 7
181+
// CHECK-SAME: ) to i64)
182+
// CHECK-SAME: ) to i32
183+
// CHECK-SAME: ),
184+
// CHECK-SAME: i32 1
185+
// CHECK-SAME: ),
186+
//
187+
// CHECK-SAME: i32 trunc (
188+
// CHECK-SAME: i64 sub (
189+
// i64 ptrtoint (ptr @"protocol witness for ResilientAPILib.DistributedNotificationService.getArray(a1: [Swift.Int], a2: Swift.String?) -> [ResilientAPILib.Response] in conformance ResilientImplLib.ServiceImpl : ResilientAPILib.DistributedNotificationService in ResilientImplLib" to i64),
190+
// CHECK-SAME: i64 ptrtoint (ptr @"$s16ResilientImplLib07ServiceB0C0A6APILib023DistributedNotificationD0AadEP8getArray2a12a2SayAD8ResponseVGSaySiG_SSSgtFTW" to i64),
191+
// CHECK-SAME: i64 ptrtoint (ptr getelementptr inbounds (
192+
// CHECK-SAME: { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i16, i16, i32, i32 },
193+
// ptr @"protocol conformance descriptor for ResilientImplLib.ServiceImpl : ResilientAPILib.DistributedNotificationService in ResilientImplLib",
194+
// CHECK-SAME: ptr @"$s16ResilientImplLib07ServiceB0C0A6APILib023DistributedNotificationD0AAMc",
195+
// CHECK-SAME: i32 0, i32 8
196+
// CHECK-SAME: ) to i64)
197+
// CHECK-SAME: ) to i32
198+
// CHECK-SAME: ),
199+
//
200+
// THIS ONE HAS .7 IN OUR REAL EXAMPLE >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
201+
// CHECK-SAME: i32 add (
202+
// CHECK-SAME: i32 trunc (
203+
// CHECK-SAME: i64 sub (
204+
// i64 ptrtoint (ptr @"got.method descriptor for ResilientAPILib.DistributedNotificationService.getArray(a1: [Swift.Int], a2: Swift.String?) async throws -> [ResilientAPILib.Response]" to i64),
205+
// CHECK-SAME: i64 ptrtoint (ptr @"got.$s15ResilientAPILib30DistributedNotificationServiceP8getArray2a12a2SayAA8ResponseVGSaySiG_SSSgtYaKFTqTE" to i64),
206+
// CHECK-SAME: i64 ptrtoint (ptr getelementptr inbounds (
207+
// CHECK-SAME: { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i16, i16, i32, i32 },
208+
// ptr @"protocol conformance descriptor for ResilientImplLib.ServiceImpl : ResilientAPILib.DistributedNotificationService in ResilientImplLib",
209+
// CHECK-SAME: ptr @"$s16ResilientImplLib07ServiceB0C0A6APILib023DistributedNotificationD0AAMc",
210+
// CHECK-SAME: i32 0, i32 9
211+
// CHECK-SAME: ) to i64)
212+
// CHECK-SAME: ) to i32
213+
// CHECK-SAME: ),
214+
// CHECK-SAME: i32 1
215+
// CHECK-SAME: ),
216+
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
217+
//
218+
// CHECK-SAME: i32 trunc (
219+
// CHECK-SAME: i64 sub (
220+
// i64 ptrtoint (ptr @"async function pointer to distributed thunk protocol witness for ResilientAPILib.DistributedNotificationService.getArray(a1: [Swift.Int], a2: Swift.String?) async throws -> [ResilientAPILib.Response] in conformance ResilientImplLib.ServiceImpl : ResilientAPILib.DistributedNotificationService in ResilientImplLib" to i64),
221+
// CHECK-SAME: i64 ptrtoint (ptr @"$s16ResilientImplLib07ServiceB0C0A6APILib023DistributedNotificationD0AadEP8getArray2a12a2SayAD8ResponseVGSaySiG_SSSgtYaKFTWTETu" to i64),
222+
// CHECK-SAME: i64 ptrtoint (ptr getelementptr inbounds (
223+
// CHECK-SAME: { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i16, i16, i32, i32 },
224+
// ptr @"protocol conformance descriptor for ResilientImplLib.ServiceImpl : ResilientAPILib.DistributedNotificationService in ResilientImplLib",
225+
// CHECK-SAME: ptr @"$s16ResilientImplLib07ServiceB0C0A6APILib023DistributedNotificationD0AAMc",
226+
// CHECK-SAME: i32 0, i32 10
227+
// CHECK-SAME: ) to i64)
228+
// CHECK-SAME: ) to i32
229+
// CHECK-SAME: ),
230+
//
231+
// CHECK-SAME: i16 0,
232+
// CHECK-SAME: i16 1,
233+
// CHECK-SAME: i32 0,
234+
//
235+
// CHECK-SAME: i32 trunc (
236+
// CHECK-SAME: i64 sub (
237+
// i64 ptrtoint (ptr @"metadata instantiation cache for protocol conformance descriptor for ResilientImplLib.ServiceImpl : ResilientAPILib.DistributedNotificationService in ResilientImplLib" to i64),
238+
// CHECK-SAME: i64 ptrtoint (ptr @"$s16ResilientImplLib07ServiceB0C0A6APILib023DistributedNotificationD0AAMcMK" to i64),
239+
// CHECK-SAME: i64 ptrtoint (ptr getelementptr inbounds (
240+
// CHECK-SAME: { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i16, i16, i32, i32 },
241+
// ptr @"protocol conformance descriptor for ResilientImplLib.ServiceImpl : ResilientAPILib.DistributedNotificationService in ResilientImplLib",
242+
// CHECK-SAME: ptr @"$s16ResilientImplLib07ServiceB0C0A6APILib023DistributedNotificationD0AAMc",
243+
// CHECK-SAME: i32 0, i32 14
244+
// CHECK-SAME: ) to i64)
245+
// CHECK-SAME: ) to i32
246+
// CHECK-SAME: )
247+
// CHECK-SAME: }, section "__TEXT,__const", no_sanitize_address, align 4

0 commit comments

Comments
 (0)