Skip to content

Commit 2cc4984

Browse files
committed
update more tests
fixing tests fix TBD test fix Serialization/distributed fix irgen test Fix null pointer crashes
1 parent cbaf7fe commit 2cc4984

File tree

45 files changed

+1166
-635
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1166
-635
lines changed

lib/SILGen/SILGenConstructor.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -955,10 +955,6 @@ void SILGenFunction::emitClassConstructorInitializer(ConstructorDecl *ctor) {
955955
else
956956
B.createReturn(returnLoc, selfArg.forward(*this));
957957
}
958-
959-
fprintf(stderr, "[%s:%d] (%s) CONSTRUCTOR =====\n", __FILE__, __LINE__, __FUNCTION__);
960-
F.dump();
961-
fprintf(stderr, "[%s:%d] (%s) END CONSTRUCTOR =====\n", __FILE__, __LINE__, __FUNCTION__);
962958
}
963959

964960
static ManagedValue emitSelfForMemberInit(SILGenFunction &SGF, SILLocation loc,

lib/SILGen/SILGenDistributed.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,25 +61,17 @@ static SILValue emitActorPropertyReference(
6161
static void initializeProperty(SILGenFunction &SGF, SILLocation loc,
6262
SILValue actorSelf,
6363
VarDecl* prop, SILValue value) {
64-
fprintf(stderr, "[%s:%d] (%s) Initialize property: %s\n", __FILE__, __LINE__, __FUNCTION__, prop->getNameStr().str().c_str());
65-
value->dump();
66-
fprintf(stderr, "[%s:%d] (%s) IS KIND: %d\n", __FILE__, __LINE__, __FUNCTION__, value->getKind());
6764
Type formalType = SGF.F.mapTypeIntoContext(prop->getInterfaceType());
6865
SILType loweredType = SGF.getLoweredType(formalType);
6966

7067
auto fieldAddr = emitActorPropertyReference(SGF, loc, actorSelf, prop);
7168

7269
if (loweredType.isAddressOnly(SGF.F)) {
73-
fprintf(stderr, "[%s:%d] (%s) IS ADDRESS ONLY\n", __FILE__, __LINE__, __FUNCTION__);
7470
SGF.B.createCopyAddr(loc, value, fieldAddr, IsNotTake, IsInitialization);
7571
} else {
76-
fprintf(stderr, "[%s:%d] (%s) ELSE\n", __FILE__, __LINE__, __FUNCTION__);
7772
if (value->getType().isAddress()) {
78-
fprintf(stderr, "[%s:%d] (%s) ELSE, IS ADDR\n", __FILE__, __LINE__, __FUNCTION__);
7973
value = SGF.B.createTrivialLoadOr(
8074
loc, value, LoadOwnershipQualifier::Take);
81-
// auto managed = ManagedValue::forUnmanaged(value);
82-
// managed.borrow(SGF, loc);
8375
} else {
8476
value = SGF.B.emitCopyValueOperation(loc, value);
8577
}
@@ -90,7 +82,6 @@ static void initializeProperty(SILGenFunction &SGF, SILLocation loc,
9082
if (value->getType().isAddress()) {
9183
SGF.B.createDestroyAddr(loc, value);
9284
}
93-
9485
}
9586
}
9687

@@ -406,8 +397,6 @@ void SILGenFunction::emitDistributedActorFactory(FuncDecl *fd) { // TODO(distrib
406397
Cleanups.emitCleanupsForReturn(CleanupLocation(loc), IsForUnwind);
407398
B.createThrow(loc, error);
408399
}
409-
410-
F.dump();
411400
}
412401

413402
// MARK: transport.resignID()

lib/SILOptimizer/Utils/DistributedActor.cpp

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ void emitDistributedActorSystemWitnessCall(
5656
SILBuilder &B, SILLocation loc, DeclName methodName,
5757
SILValue actorSystem, SILType actorType, ArrayRef<SILValue> args,
5858
Optional<std::pair<SILBasicBlock *, SILBasicBlock *>> tryTargets) {
59-
fprintf(stderr, "[%s:%d] (%s) Prepare call: %s ========================================================================\n", __FILE__, __LINE__, __FUNCTION__, methodName.getBaseName().getIdentifier().str().str().c_str());
6059
auto &F = B.getFunction();
6160
auto &M = B.getModule();
6261
auto &C = F.getASTContext();
@@ -146,35 +145,13 @@ void emitDistributedActorSystemWitnessCall(
146145
if (params[i].isFormalIndirect() &&
147146
!arg->getType().isAddress() &&
148147
!dyn_cast<AnyMetatypeType>(arg->getType().getASTType())) {
149-
fprintf(stderr, "[%s:%d] (%s) push arg, make pointer\n", __FILE__, __LINE__, __FUNCTION__);
150148
auto buf = B.createAllocStack(loc, arg->getType(), None);
151149
auto argCopy = B.emitCopyValueOperation(loc, arg);
152150
B.emitStoreValueOperation(
153151
loc, argCopy, buf, StoreOwnershipQualifier::Init);
154152
temporaryActorIDBuffer = SILValue(buf);
155-
156-
arg->getType().dump();
157-
fprintf(stderr, "[%s:%d] (%s) made into: %s\n", __FILE__, __LINE__, __FUNCTION__, (*temporaryActorIDBuffer)->getType().getMangledName().c_str());
158-
(*temporaryActorIDBuffer)->getType().dump();
159-
160153
allArgs.push_back(*temporaryActorIDBuffer);
161-
// } else if (methodName.getBaseName().getIdentifier() == C.Id_assignID) {
162-
// fprintf(stderr, "[%s:%d] (%s) push arg, ACTOR, make pointer\n", __FILE__, __LINE__, __FUNCTION__);
163-
// arg->dump();
164-
// auto buf = B.createAllocStack(loc, arg->getType(), None);
165-
// auto argCopy = B.emitCopyValueOperation(loc, arg);
166-
// B.emitStoreValueOperation(
167-
// loc, argCopy, buf, StoreOwnershipQualifier::Init);
168-
// temporaryActorIDBuffer = SILValue(buf);
169-
//
170-
// arg->getType().dump();
171-
// fprintf(stderr, "[%s:%d] (%s) made into: %s\n", __FILE__, __LINE__, __FUNCTION__, (*temporaryActorIDBuffer)->getType().getMangledName().c_str());
172-
// (*temporaryActorIDBuffer)->getType().dump();
173-
//
174-
// allArgs.push_back(*temporaryActorIDBuffer);
175154
} else {
176-
fprintf(stderr, "[%s:%d] (%s) push arg, directly\n", __FILE__, __LINE__, __FUNCTION__);
177-
arg->getType().dump();
178155
allArgs.push_back(arg);
179156
}
180157
}

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2921,16 +2921,16 @@ bool ConformanceChecker::checkActorIsolation(
29212921
// witness this requirement. I.e. since checks to the distributed function
29222922
// passed, it can be called through this protocol.
29232923
if (witnessFunc && witnessFunc->isDistributed()) {
2924-
// If the requirement was also a 'distributed func' we most definitely
2925-
// can witness it with our 'distributed func' witness.
2926-
if (requirementFunc && requirementFunc->isDistributed()) {
2927-
return false;
2928-
}
2929-
if (requirementFunc->hasAsync() && requirementFunc->hasThrows()) {
2930-
return false;
2931-
}
2932-
29332924
if (requirementFunc) {
2925+
// If the requirement was also a 'distributed func' we most definitely
2926+
// can witness it with our 'distributed func' witness.
2927+
if (requirementFunc->isDistributed()) {
2928+
return false;
2929+
}
2930+
if (requirementFunc->hasAsync() && requirementFunc->hasThrows()) {
2931+
return false;
2932+
}
2933+
29342934
// The witness was distributed, but the requirement func was not
29352935
// 'async throws', so we can suggest adding those to the protocol
29362936
int suggestAddingModifiers = 0;
@@ -2954,22 +2954,24 @@ bool ConformanceChecker::checkActorIsolation(
29542954

29552955
// witness is not 'distributed', if the requirement was though,
29562956
// then we definitely must mark the witness distributed as well.
2957-
if (requirementFunc->isDistributed()) {
2958-
witness->diagnose(diag::note_add_distributed_to_decl,
2959-
witness->getName(),
2960-
witness->getDescriptiveKind())
2961-
.fixItInsert(witness->getAttributeInsertionLoc(true),
2962-
"distributed ");
2963-
requirement->diagnose(diag::note_distributed_requirement_defined_here,
2964-
requirement->getName());
2965-
} else if (requirementFunc->hasAsync() && requirementFunc->hasThrows()) {
2966-
assert(!requirementFunc->isDistributed());
2967-
// If the requirement is 'async throws' we can add 'distributed' to the
2968-
// distributed actor function to witness the requirement.
2969-
witness->diagnose(diag::note_add_distributed_to_decl,
2970-
witness->getName(), witness->getDescriptiveKind())
2971-
.fixItInsert(witness->getAttributeInsertionLoc(true),
2972-
"distributed ");
2957+
if (requirementFunc) {
2958+
if (requirementFunc->isDistributed()) {
2959+
witness->diagnose(diag::note_add_distributed_to_decl,
2960+
witness->getName(),
2961+
witness->getDescriptiveKind())
2962+
.fixItInsert(witness->getAttributeInsertionLoc(true),
2963+
"distributed ");
2964+
requirement->diagnose(diag::note_distributed_requirement_defined_here,
2965+
requirement->getName());
2966+
} else if (requirementFunc->hasAsync() && requirementFunc->hasThrows()) {
2967+
assert(!requirementFunc->isDistributed());
2968+
// If the requirement is 'async throws' we can add 'distributed' to the
2969+
// distributed actor function to witness the requirement.
2970+
witness->diagnose(diag::note_add_distributed_to_decl,
2971+
witness->getName(), witness->getDescriptiveKind())
2972+
.fixItInsert(witness->getAttributeInsertionLoc(true),
2973+
"distributed ");
2974+
}
29732975
}
29742976

29752977
if (!requirementFunc->hasAsync() && !requirementFunc->isDistributed()) {

stdlib/public/Distributed/AssertDistributed.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ public func _missingDistributedActorSystem(
2828
Invoked remote placeholder function '\(functionName)' on remote \
2929
distributed actor of type '\(className)'. Configure an appropriate \
3030
'DistributedActorSystem' for this actor to resolve this error (e.g. by depending \
31-
on some specific transport library).
31+
on some specific actor system library).
3232
""", file: file, line: line)
3333
}

stdlib/public/Distributed/DistributedActor.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ public protocol DistributedActor:
4444
/// The type of transport used to communicate with actors of this type.
4545
associatedtype ActorSystem: DistributedActorSystem
4646

47+
/// The serialization requirement to apply to all distributed declarations inside the actor.
48+
typealias SerializationRequirement = ActorSystem.SerializationRequirement
49+
4750
/// Logical identity of this distributed actor.
4851
///
4952
/// Many distributed actor references may be pointing at, logically, the same actor.
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift open source project
4+
//
5+
// Copyright (c) 2021 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0
7+
//
8+
// See LICENSE.txt for license information
9+
// See CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
// SPDX-License-Identifier: Apache-2.0
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
import _Distributed
16+
17+
// ==== Fake Address -----------------------------------------------------------
18+
19+
public struct ActorAddress: Hashable, Sendable, Codable {
20+
public let address: String
21+
public init(parse address : String) {
22+
self.address = address
23+
}
24+
25+
public init(from decoder: Decoder) throws {
26+
let container = try decoder.singleValueContainer()
27+
self.address = try container.decode(String.self)
28+
}
29+
30+
public func encode(to encoder: Encoder) throws {
31+
var container = encoder.singleValueContainer()
32+
try container.encode(self.address)
33+
}
34+
}
35+
36+
// ==== Fake Transport ---------------------------------------------------------
37+
38+
public struct FakeActorSystem: DistributedActorSystem {
39+
public typealias ActorID = ActorAddress
40+
public typealias Invocation = FakeInvocation
41+
public typealias SerializationRequirement = Codable
42+
43+
init() {
44+
print("Initialized new FakeActorSystem")
45+
}
46+
47+
public func resolve<Act>(id: ActorID, as actorType: Act.Type) throws -> Act?
48+
where Act: DistributedActor,
49+
Act.ID == ActorID {
50+
nil
51+
}
52+
53+
public func assignID<Act>(_ actorType: Act.Type) -> ActorID
54+
where Act: DistributedActor,
55+
Act.ID == ActorID {
56+
ActorAddress(parse: "xxx")
57+
}
58+
59+
public func actorReady<Act>(_ actor: Act)
60+
where Act: DistributedActor,
61+
Act.ID == ActorID {
62+
}
63+
64+
public func resignID(_ id: ActorID) {
65+
}
66+
67+
public func makeInvocation() -> Invocation {
68+
.init()
69+
}
70+
}
71+
72+
public struct FakeInvocation: DistributedTargetInvocation {
73+
public typealias ArgumentDecoder = FakeArgumentDecoder
74+
public typealias SerializationRequirement = Codable
75+
76+
public mutating func recordGenericSubstitution<T>(mangledType: T.Type) throws {}
77+
public mutating func recordArgument<Argument: SerializationRequirement>(argument: Argument) throws {}
78+
public mutating func recordReturnType<R: SerializationRequirement>(mangledType: R.Type) throws {}
79+
public mutating func recordErrorType<E: Error>(mangledType: E.Type) throws {}
80+
public mutating func doneRecording() throws {}
81+
82+
// === Receiving / decoding -------------------------------------------------
83+
84+
public mutating func decodeGenericSubstitutions() throws -> [Any.Type] { [] }
85+
public mutating func argumentDecoder() -> FakeArgumentDecoder { .init() }
86+
public mutating func decodeReturnType() throws -> Any.Type? { nil }
87+
public mutating func decodeErrorType() throws -> Any.Type? { nil }
88+
89+
public struct FakeArgumentDecoder: DistributedTargetInvocationArgumentDecoder {
90+
public typealias SerializationRequirement = Codable
91+
}
92+
}

test/Distributed/Inputs/dynamic_replacement_da_decl.swift

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,85 @@
1414

1515
import _Distributed
1616

17+
18+
// ==== Fake Transport ---------------------------------------------------------
19+
20+
struct ActorAddress: Hashable, Sendable, Codable {
21+
let address: String
22+
init(parse address : String) {
23+
self.address = address
24+
}
25+
26+
init(from decoder: Decoder) throws {
27+
let container = try decoder.singleValueContainer()
28+
self.address = try container.decode(String.self)
29+
}
30+
31+
func encode(to encoder: Encoder) throws {
32+
var container = encoder.singleValueContainer()
33+
try container.encode(self.address)
34+
}
35+
}
36+
37+
final class FakeActorSystem: DistributedActorSystem {
38+
typealias ActorID = ActorAddress
39+
typealias Invocation = FakeInvocation
40+
typealias SerializationRequirement = Codable
41+
42+
func resolve<Act>(id: ActorID, as actorType: Act.Type) throws -> Act?
43+
where Act: DistributedActor,
44+
Act.ID == ActorID {
45+
return nil
46+
}
47+
48+
func assignID<Act>(_ actorType: Act.Type) -> ActorID
49+
where Act: DistributedActor,
50+
Act.ID == ActorID {
51+
ActorAddress(parse: "xxx")
52+
}
53+
54+
func actorReady<Act>(_ actor: Act)
55+
where Act: DistributedActor,
56+
Act.ID == ActorID {
57+
}
58+
59+
func resignID(_ id: ActorID) {
60+
}
61+
62+
func makeInvocation() -> Invocation {
63+
.init()
64+
}
65+
}
66+
67+
struct FakeInvocation: DistributedTargetInvocation {
68+
typealias ArgumentDecoder = FakeArgumentDecoder
69+
typealias SerializationRequirement = Codable
70+
71+
mutating func recordGenericSubstitution<T>(mangledType: T.Type) throws {}
72+
mutating func recordArgument<Argument: SerializationRequirement>(argument: Argument) throws {}
73+
mutating func recordReturnType<R: SerializationRequirement>(mangledType: R.Type) throws {}
74+
mutating func recordErrorType<E: Error>(mangledType: E.Type) throws {}
75+
mutating func doneRecording() throws {}
76+
77+
// === Receiving / decoding -------------------------------------------------
78+
79+
mutating func decodeGenericSubstitutions() throws -> [Any.Type] { [] }
80+
mutating func argumentDecoder() -> FakeArgumentDecoder { .init() }
81+
mutating func decodeReturnType() throws -> Any.Type? { nil }
82+
mutating func decodeErrorType() throws -> Any.Type? { nil }
83+
84+
struct FakeArgumentDecoder: DistributedTargetInvocationArgumentDecoder {
85+
typealias SerializationRequirement = Codable
86+
}
87+
}
88+
89+
@available(SwiftStdlib 5.5, *)
90+
typealias DefaultDistributedActorSystem = FakeActorSystem
91+
92+
// ==== ------------------------------------------------------------------------
93+
1794
distributed actor DA {
18-
typealias Transport = AnyDistributedActorSystem
95+
typealias ActorSystem = FakeActorSystem
1996

2097
distributed func hello(other: DA) {}
2198
}

test/Distributed/Runtime/distributed_actor_decode.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ final class FakeActorSystem: DistributedActorSystem {
4646
typealias SerializationRequirement = Codable
4747

4848
func resolve<Act>(id: ActorID, as actorType: Act.Type) throws -> Act?
49-
where Act: DistributedActor, Act.ID == ActorID {
49+
where Act: DistributedActor,
50+
Act.ID == ActorID {
5051
print("resolve type:\(actorType), address:\(id)")
5152
return nil
5253
}

0 commit comments

Comments
 (0)