Skip to content

Commit 67628b7

Browse files
authored
Merge pull request #41218 from xedin/dist-watchos-32bit-issues
[Distributed] IRGen: Fix loading of the witness tables
2 parents 1161f92 + ab25d4e commit 67628b7

File tree

4 files changed

+43
-21
lines changed

4 files changed

+43
-21
lines changed

lib/IRGen/GenDistributed.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -513,15 +513,17 @@ void DistributedAccessor::emitLoadOfWitnessTables(llvm::Value *witnessTables,
513513

514514
IGF.Builder.emitBlock(contBB);
515515

516-
witnessTables = IGF.Builder.CreateBitCast(witnessTables, IGM.Int8PtrPtrTy);
516+
witnessTables = IGF.Builder.CreateBitCast(witnessTables,
517+
IGM.Int8PtrPtrTy->getPointerTo());
517518

518519
for (unsigned i = 0, n = expectedWitnessTables; i != n; ++i) {
519520
auto offset = Size(i * IGM.getPointerSize());
520521
auto alignment = IGM.getPointerAlignment();
521522

522523
auto witnessTableAddr = IGF.emitAddressAtOffset(
523-
witnessTables, Offset(offset), IGM.Int8PtrTy, Alignment(alignment));
524-
arguments.add(witnessTableAddr.getAddress());
524+
witnessTables, Offset(offset), IGM.Int8PtrPtrTy, Alignment(alignment));
525+
526+
arguments.add(IGF.Builder.CreateLoad(witnessTableAddr));
525527
}
526528
}
527529

test/Distributed/Runtime/distributed_actor_remoteCall.swift

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@
44
// REQUIRES: concurrency
55
// REQUIRES: distributed
66

7-
// rdar://87568630 - segmentation fault on 32-bit WatchOS simulator
8-
// UNSUPPORTED: OS=watchos && CPU=i386
9-
// rdar://88340451 - segmentation fault on arm64_32 WatchOS simulator
10-
// UNSUPPORTED: OS=watchos && CPU=arm64_32
11-
127
// rdar://76038845
138
// UNSUPPORTED: use_os_stdlib
149
// UNSUPPORTED: back_deployment_runtime
@@ -19,6 +14,7 @@
1914
// FIXME(distributed): remote calls seem to hang on linux - rdar://87240034
2015
// UNSUPPORTED: linux
2116

17+
import Foundation
2218
import _Distributed
2319

2420
final class Obj: @unchecked Sendable, Codable {}
@@ -39,9 +35,6 @@ struct S<T: Codable> : Codable {
3935
var data: T
4036
}
4137

42-
@_silgen_name("swift_distributed_actor_is_remote")
43-
func __isRemoteActor(_ actor: AnyObject) -> Bool
44-
4538
distributed actor Greeter {
4639
distributed func echo(name: String, age: Int) -> String {
4740
return "Echo: name: \(name), age: \(age)"
@@ -92,6 +85,20 @@ distributed actor Greeter {
9285
print("---> B = \(b), type(of:) = \(type(of: b))")
9386
print("---> C = \(c), type(of:) = \(type(of: c))")
9487
print("---> D = \(d), type(of:) = \(type(of: d))")
88+
89+
// try encoding generic arguments to make sure that witness tables are passed correctly
90+
let json = JSONEncoder()
91+
92+
let jsonA = try! String(data: json.encode(a), encoding: .utf8)
93+
let jsonB = try! String(data: json.encode(b), encoding: .utf8)
94+
let jsonC = try! String(data: json.encode(c), encoding: .utf8)
95+
let jsonD = try! String(data: json.encode(d), encoding: .utf8)
96+
97+
print("---> A(JSON) = \(jsonA!)")
98+
print("---> B(JSON) = \(jsonB!)")
99+
print("---> C(JSON) = \(jsonC!)")
100+
print("---> D(JSON) = \(jsonD!)")
101+
95102
}
96103

97104
distributed func genericOptional<T: Codable>(t: T?) {
@@ -450,6 +457,10 @@ func test() async throws {
450457
// CHECK-NEXT: ---> B = S<Int>(data: 42), type(of:) = S<Int>
451458
// CHECK-NEXT: ---> C = Hello, World!, type(of:) = String
452459
// CHECK-NEXT: ---> D = [0.0, 3737844653.0], type(of:) = Array<Double>
460+
// CHECK-NEXT: ---> A(JSON) = 42
461+
// CHECK-NEXT: ---> B(JSON) = {"data":42}
462+
// CHECK-NEXT: ---> C(JSON) = "Hello, World!"
463+
// CHECK-NEXT: ---> D(JSON) = [0,3737844653]
453464
// CHECK-NEXT: RETURN: ()
454465

455466
var genericOptInvocation = system.makeInvocationEncoder()

test/Distributed/distributed_actor_accessor_thunks_32bit.swift

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -386,11 +386,16 @@ public distributed actor MyOtherActor {
386386
// CHECK: incorrect-witness-tables:
387387
// CHECK-NEXT: unreachable
388388

389-
// CHECK: [[WITNESS_BUF:%.*]] = bitcast i8* [[WITNESS_TABLES]] to i8**
390-
// CHECK-NEXT: [[T_ENCODABLE:%.*]] = getelementptr inbounds i8*, i8** [[WITNESS_BUF]], i32 0
391-
// CHECK-NEXT: [[T_DECODABLE:%.*]] = getelementptr inbounds i8*, i8** [[WITNESS_BUF]], i32 1
392-
// CHECK-NEXT: [[U_ENCODABLE:%.*]] = getelementptr inbounds i8*, i8** [[WITNESS_BUF]], i32 2
393-
// CHECK-NEXT: [[U_DECODABLE:%.*]] = getelementptr inbounds i8*, i8** [[WITNESS_BUF]], i32 3
389+
// CHECK: [[WITNESS_BUF:%.*]] = bitcast i8* [[WITNESS_TABLES]] to i8***
390+
// CHECK-NEXT: [[T_ENCODABLE_ADDR:%.*]] = getelementptr inbounds i8**, i8*** [[WITNESS_BUF]], i32 0
391+
// CHECK-NEXT: [[T_ENCODABLE:%.*]] = load i8**, i8*** [[T_ENCODABLE_ADDR]]
392+
// CHECK-NEXT: [[T_DECODABLE_ADDR:%.*]] = getelementptr inbounds i8**, i8*** [[WITNESS_BUF]], i32 1
393+
// CHECK-NEXT: [[T_DECODABLE:%.*]] = load i8**, i8*** [[T_DECODABLE_ADDR]]
394+
// CHECK-NEXT: [[U_ENCODABLE_ADDR:%.*]] = getelementptr inbounds i8**, i8*** [[WITNESS_BUF]], i32 2
395+
// CHECK-NEXT: [[U_ENCODABLE:%.*]] = load i8**, i8*** [[U_ENCODABLE_ADDR]]
396+
// CHECK-NEXT: [[U_DECODABLE_ADDR:%.*]] = getelementptr inbounds i8**, i8*** [[WITNESS_BUF]], i32 3
397+
// CHECK-NEXT: [[U_DECODABLE:%.*]] = load i8**, i8*** [[U_DECODABLE_ADDR]]
398+
394399

395400
/// ---> Check that distributed thunk code is formed correctly
396401

test/Distributed/distributed_actor_accessor_thunks_64bit.swift

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -366,11 +366,15 @@ public distributed actor MyOtherActor {
366366
// CHECK: incorrect-witness-tables:
367367
// CHECK-NEXT: unreachable
368368

369-
// CHECK: [[WITNESS_BUF:%.*]] = bitcast i8* [[WITNESS_TABLES]] to i8**
370-
// CHECK-NEXT: [[T_ENCODABLE:%.*]] = getelementptr inbounds i8*, i8** [[WITNESS_BUF]], i64 0
371-
// CHECK-NEXT: [[T_DECODABLE:%.*]] = getelementptr inbounds i8*, i8** [[WITNESS_BUF]], i64 1
372-
// CHECK-NEXT: [[U_ENCODABLE:%.*]] = getelementptr inbounds i8*, i8** [[WITNESS_BUF]], i64 2
373-
// CHECK-NEXT: [[U_DECODABLE:%.*]] = getelementptr inbounds i8*, i8** [[WITNESS_BUF]], i64 3
369+
// CHECK: [[WITNESS_BUF:%.*]] = bitcast i8* [[WITNESS_TABLES]] to i8***
370+
// CHECK-NEXT: [[T_ENCODABLE_ADDR:%.*]] = getelementptr inbounds i8**, i8*** [[WITNESS_BUF]], i64 0
371+
// CHECK-NEXT: [[T_ENCODABLE:%.*]] = load i8**, i8*** [[T_ENCODABLE_ADDR]]
372+
// CHECK-NEXT: [[T_DECODABLE_ADDR:%.*]] = getelementptr inbounds i8**, i8*** [[WITNESS_BUF]], i64 1
373+
// CHECK-NEXT: [[T_DECODABLE:%.*]] = load i8**, i8*** [[T_DECODABLE_ADDR]]
374+
// CHECK-NEXT: [[U_ENCODABLE_ADDR:%.*]] = getelementptr inbounds i8**, i8*** [[WITNESS_BUF]], i64 2
375+
// CHECK-NEXT: [[U_ENCODABLE:%.*]] = load i8**, i8*** [[U_ENCODABLE_ADDR]]
376+
// CHECK-NEXT: [[U_DECODABLE_ADDR:%.*]] = getelementptr inbounds i8**, i8*** [[WITNESS_BUF]], i64 3
377+
// CHECK-NEXT: [[U_DECODABLE:%.*]] = load i8**, i8*** [[U_DECODABLE_ADDR]]
374378

375379
/// ---> Check that distributed thunk code is formed correctly
376380

0 commit comments

Comments
 (0)