Skip to content

Commit 1675669

Browse files
committed
Revert "[Distributed] workaround for LocalTestingDAS crashes;"
This reverts commit bcd0f64.
1 parent 1e489d6 commit 1675669

File tree

5 files changed

+725
-732
lines changed

5 files changed

+725
-732
lines changed

lib/AST/DistributedDecl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,7 @@ bool AbstractFunctionDecl::isDistributedActorSystemRemoteCall(bool isVoidReturn)
472472
if (!invocationParam->isInOut()) {
473473
return false;
474474
}
475+
475476
// --- Check parameter: throwing: Err.Type
476477
auto thrownTypeParam = params->get(3);
477478
if (thrownTypeParam->getArgumentName() != C.Id_throwing) {

stdlib/public/Distributed/LocalTestingDistributedActorSystem.swift

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public final class LocalTestingDistributedActorSystem: DistributedActorSystem, @
4343
public init() {}
4444

4545
public func resolve<Act>(id: ActorID, as actorType: Act.Type)
46-
throws -> Act? where Act: DistributedActor {
46+
throws -> Act? where Act: DistributedActor, Act.ID == ActorID {
4747
guard let anyActor = self.activeActorsLock.withLock({ self.activeActors[id] }) else {
4848
throw LocalTestingDistributedActorSystemError(message: "Unable to locate id '\(id)' locally")
4949
}
@@ -54,7 +54,7 @@ public final class LocalTestingDistributedActorSystem: DistributedActorSystem, @
5454
}
5555

5656
public func assignID<Act>(_ actorType: Act.Type) -> ActorID
57-
where Act: DistributedActor {
57+
where Act: DistributedActor, Act.ID == ActorID {
5858
let id = self.idProvider.next()
5959
self.assignedIDsLock.withLock {
6060
self.assignedIDs.insert(id)
@@ -63,8 +63,7 @@ public final class LocalTestingDistributedActorSystem: DistributedActorSystem, @
6363
}
6464

6565
public func actorReady<Act>(_ actor: Act)
66-
where Act: DistributedActor,
67-
Act.ID == ActorID {
66+
where Act: DistributedActor, Act.ID == ActorID {
6867
guard self.assignedIDsLock.withLock({ self.assignedIDs.contains(actor.id) }) else {
6968
fatalError("Attempted to mark an unknown actor '\(actor.id)' ready")
7069
}
@@ -246,10 +245,27 @@ fileprivate class _Lock {
246245
private let underlying: UnsafeMutablePointer<pthread_mutex_t>
247246
#endif
248247

248+
init() {
249+
#if os(iOS) || os(macOS) || os(tvOS) || os(watchOS)
250+
self.underlying = UnsafeMutablePointer.allocate(capacity: 1)
251+
self.underlying.initialize(to: os_unfair_lock())
252+
#elseif os(Windows)
253+
self.underlying = UnsafeMutablePointer.allocate(capacity: 1)
254+
InitializeSRWLock(self.underlying)
255+
#elseif os(WASI)
256+
// WASI environment has only a single thread
257+
#else
258+
self.underlying = UnsafeMutablePointer.allocate(capacity: 1)
259+
guard pthread_mutex_init(self.underlying, nil) == 0 else {
260+
fatalError("pthread_mutex_init failed")
261+
}
262+
#endif
263+
}
264+
249265
deinit {
250266
#if os(iOS) || os(macOS) || os(tvOS) || os(watchOS)
251267
// `os_unfair_lock`s do not need to be explicitly destroyed
252-
#elseif os(Windows)
268+
#elseif os(Windows)
253269
// `SRWLOCK`s do not need to be explicitly destroyed
254270
#elseif os(WASI)
255271
// WASI environment has only a single thread
@@ -265,21 +281,6 @@ fileprivate class _Lock {
265281
#endif
266282
}
267283

268-
init() {
269-
#if os(iOS) || os(macOS) || os(tvOS) || os(watchOS)
270-
self.underlying = UnsafeMutablePointer.allocate(capacity: 1)
271-
#elseif os(Windows)
272-
self.underlying = UnsafeMutablePointer.allocate(capacity: 1)
273-
InitializeSRWLock(self.underlying)
274-
#elseif os(WASI)
275-
// WASI environment has only a single thread
276-
#else
277-
self.underlying = UnsafeMutablePointer.allocate(capacity: 1)
278-
guard pthread_mutex_init(self.underlying, nil) == 0 else {
279-
fatalError("pthread_mutex_init failed")
280-
}
281-
#endif
282-
}
283284

284285
@discardableResult
285286
func withLock<T>(_ body: () -> T) -> T {

test/Distributed/Runtime/distributed_actor_init_local.swift

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
// UNSUPPORTED: use_os_stdlib
99
// UNSUPPORTED: back_deployment_runtime
1010

11-
// REQUIRES: rdar92910719
12-
1311
import Distributed
1412

1513
enum MyError: Error {
@@ -92,15 +90,6 @@ distributed actor MaybeAfterAssign {
9290
}
9391
}
9492

95-
distributed actor LocalTestingSystemDA {
96-
typealias ActorSystem = LocalTestingDistributedActorSystem
97-
var x: Int
98-
init() {
99-
actorSystem = .init()
100-
x = 100
101-
}
102-
}
103-
10493
distributed actor LocalTestingDA_Int {
10594
typealias ActorSystem = LocalTestingDistributedActorSystem
10695
var int: Int
@@ -111,7 +100,6 @@ distributed actor LocalTestingDA_Int {
111100
}
112101
}
113102

114-
115103
// ==== Fake Transport ---------------------------------------------------------
116104

117105
struct ActorAddress: Sendable, Hashable, Codable {
@@ -297,6 +285,7 @@ func test() async {
297285
// CHECK-NOT: assign
298286
// CHECK: -- end of no-assign tests --
299287

288+
300289
// resigns that come out of the deinits:
301290

302291
// CHECK-DAG: resign id:ActorAddress(address: "[[ID1]]")

test/Distributed/distributed_actor_layout.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import FakeDistributedActorSystems
1212
@available(SwiftStdlib 5.7, *)
1313
typealias DefaultDistributedActorSystem = FakeActorSystem
1414

15+
class MyClass { }
16+
1517
// Ensure that the actor layout is (metadata pointer, default actor, id, system,
1618
// <user fields>)
1719

@@ -21,10 +23,10 @@ protocol HasActorSystem {
2123

2224
extension MyActor: HasActorSystem { }
2325

24-
// CHECK: %T27distributed_actor_accessors7MyActorC = type <{ %swift.refcounted, %swift.defaultactor, %T27FakeDistributedActorSystems0C7AddressV, %T27FakeDistributedActorSystems0aC6SystemV, %TSS }>
26+
// CHECK: %T27distributed_actor_accessors7MyActorC = type <{ %swift.refcounted, %swift.defaultactor, %T27FakeDistributedActorSystems0C7AddressV, %T27FakeDistributedActorSystems0aC6SystemV, %T27distributed_actor_accessors7MyClassC* }>
2527
@available(SwiftStdlib 5.7, *)
2628
public distributed actor MyActor {
27-
var field: String = ""
29+
var field: MyClass = MyClass()
2830

2931
init(actorSystem: FakeActorSystem) {
3032
self.actorSystem = actorSystem

0 commit comments

Comments
 (0)