Skip to content

Commit 28f2621

Browse files
committed
Sema: Refactor evaluateMembersRequest() to not call TypeChecker::checkConformance()
1 parent 1bf5e1b commit 28f2621

7 files changed

+32
-37
lines changed

lib/Sema/TypeCheckDecl.cpp

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3057,33 +3057,27 @@ static ArrayRef<Decl *> evaluateMembersRequest(
30573057

30583058
// Force any conformances that may introduce more members.
30593059
for (auto conformance : idc->getLocalConformances()) {
3060-
auto proto = conformance->getProtocol();
3061-
bool isDerivable =
3062-
conformance->getState() == ProtocolConformanceState::Incomplete &&
3063-
proto->getKnownDerivableProtocolKind();
3064-
3065-
switch (kind) {
3066-
case MembersRequestKind::ABI:
3067-
// Force any derivable conformances in this context.
3068-
if (isDerivable)
3069-
break;
3070-
3060+
auto *normal = dyn_cast<NormalProtocolConformance>(
3061+
conformance->getRootConformance());
3062+
if (normal == nullptr)
30713063
continue;
30723064

3073-
case MembersRequestKind::All:
3074-
// Force any derivable conformances.
3075-
if (isDerivable)
3076-
break;
3065+
auto proto = conformance->getProtocol();
3066+
bool isDerivable = proto->getKnownDerivableProtocolKind().has_value();
30773067

3078-
// If there are any associated types in the protocol, they might add
3079-
// type aliases here.
3080-
if (!proto->getAssociatedTypeMembers().empty())
3081-
break;
30823068

3083-
continue;
3069+
if (kind == MembersRequestKind::All &&
3070+
!proto->getAssociatedTypeMembers().empty()) {
3071+
evaluateOrDefault(ctx.evaluator,
3072+
ResolveTypeWitnessesRequest{normal},
3073+
evaluator::SideEffect());
30843074
}
30853075

3086-
TypeChecker::checkConformance(conformance->getRootNormalConformance());
3076+
if (isDerivable) {
3077+
evaluateOrDefault(ctx.evaluator,
3078+
ResolveValueWitnessesRequest{normal},
3079+
evaluator::SideEffect());
3080+
}
30873081
}
30883082

30893083
if (nominal) {

test/AutoDiff/Sema/DerivedConformances/class_differentiable.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -432,9 +432,7 @@ final class TangentVectorWB: DummyAdditiveArithmetic, Differentiable {
432432
self.b = b
433433
}
434434
}
435-
// expected-error @+3 {{'Differentiable' requires the types 'VectorSpaceTypeAlias.TangentVector' (aka 'TangentVectorWB') and 'TangentVectorWB.TangentVector' be equivalent}}
436-
// expected-note @+2 {{requirement specified as 'Self.TangentVector' == 'Self.TangentVector.TangentVector' [with Self = VectorSpaceTypeAlias]}}
437-
// expected-error @+1 2 {{type 'VectorSpaceTypeAlias' does not conform to protocol 'Differentiable'}} FIXME: Duplicate error
435+
// expected-error @+1 {{type 'VectorSpaceTypeAlias' does not conform to protocol 'Differentiable'}}
438436
final class VectorSpaceTypeAlias: DummyAdditiveArithmetic, Differentiable {
439437
var w: Float
440438
var b: Float

test/Distributed/actor_protocols.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ actor A2: DistributedActor {
4848
// FIXME(distributed): error reporting is a bit whacky here; needs cleanup
4949
// expected-error@-2{{actor type 'A2' cannot conform to the 'DistributedActor' protocol. Isolation rules of these actor types are not interchangeable.}}
5050
// expected-error@-3{{actor type 'A2' cannot conform to the 'DistributedActor' protocol. Isolation rules of these actor types are not interchangeable.}}
51-
// expected-error@-4{{'DistributedActor' requires the types 'ObjectIdentifier' and 'FakeActorSystem.ActorID' (aka 'ActorAddress') be equivalent}}
52-
// expected-note@-5{{requirement specified as 'Self.ID' == 'Self.ActorSystem.ActorID' [with Self = A2]}}
5351
nonisolated var id: ID {
5452
fatalError()
5553
}

test/Distributed/distributed_actor_system_missing.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ import Distributed
88

99
distributed actor DA {
1010
// expected-error@-1{{distributed actor 'DA' does not declare ActorSystem it can be used with}}
11+
// expected-error@-2 {{type 'DA' does not conform to protocol 'DistributedActor'}}
1112

1213
// Since synthesis would have failed due to the missing ActorSystem:
13-
// expected-error@-4{{type 'DA' does not conform to protocol 'Encodable'}}
14-
// expected-error@-5{{type 'DA' does not conform to protocol 'Decodable'}}
14+
// expected-error@-5{{type 'DA' does not conform to protocol 'Encodable'}}
15+
// expected-error@-6{{type 'DA' does not conform to protocol 'Decodable'}}
1516

16-
// expected-note@-7{{you can provide a module-wide default actor system by declaring:}}
17+
// expected-note@-8{{you can provide a module-wide default actor system by declaring:}}
1718

1819
// Note to add the typealias is diagnosed on the protocol:
1920
// _Distributed.DistributedActor:3:20: note: diagnostic produced elsewhere: protocol requires nested type 'ActorSystem'; do you want to add it?
@@ -24,9 +25,10 @@ distributed actor DA {
2425
//
2526
// Test case for: https://github.com/apple/swift/issues/58663
2627
distributed actor Server { // expected-error 2 {{distributed actor 'Server' does not declare ActorSystem it can be used with}}
27-
// expected-note@-1{{you can provide a module-wide default actor system by declaring:}}
28-
// expected-error@-2{{type 'Server' does not conform to protocol 'Encodable'}}
29-
// expected-error@-3{{type 'Server' does not conform to protocol 'Decodable'}}
28+
// expected-error@-1 {{type 'Server' does not conform to protocol 'DistributedActor'}}
29+
// expected-note@-2{{you can provide a module-wide default actor system by declaring:}}
30+
// expected-error@-3{{type 'Server' does not conform to protocol 'Encodable'}}
31+
// expected-error@-4{{type 'Server' does not conform to protocol 'Decodable'}}
3032
typealias ActorSystem = DoesNotExistDataSystem
3133
// expected-error@-1{{cannot find type 'DoesNotExistDataSystem' in scope}}
3234
typealias SerializationRequirement = any Codable

test/Distributed/distributed_actor_system_missing_type_no_crash.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ import Distributed
1010
distributed actor Fish {
1111
// expected-error@-1{{distributed actor 'Fish' does not declare ActorSystem it can be used with}}
1212
// expected-error@-2{{distributed actor 'Fish' does not declare ActorSystem it can be used with}}
13-
// expected-note@-3{{you can provide a module-wide default actor system by declaring:\ntypealias DefaultDistributedActorSystem = <#ConcreteActorSystem#>}}
14-
// expected-error@-4{{type 'Fish' does not conform to protocol 'Encodable'}}
15-
// expected-error@-5{{type 'Fish' does not conform to protocol 'Decodable'}}
13+
// expected-error@-3{{type 'Fish' does not conform to protocol 'DistributedActor'}}
14+
// expected-note@-4{{you can provide a module-wide default actor system by declaring:\ntypealias DefaultDistributedActorSystem = <#ConcreteActorSystem#>}}
15+
// expected-error@-5{{type 'Fish' does not conform to protocol 'Encodable'}}
16+
// expected-error@-6{{type 'Fish' does not conform to protocol 'Decodable'}}
1617

1718
distributed func tell(_ text: String, by: Fish) {
1819
// What would the fish say, if it could talk?

test/Distributed/distributed_incomplete_system_no_crash.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public final class CompletelyHollowActorSystem: DistributedActorSystem {
2929
}
3030

3131
public struct Decoder: InvocationDecoder {
32+
// expected-error@-1 {{inheritance from non-protocol type 'CompletelyHollowActorSystem.InvocationDecoder' (aka 'CompletelyHollowActorSystem.Decoder')}}
3233

3334
}
3435

test/Distributed/distributed_protocols_distributed_func_serialization_requirements.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ distributed actor ProtocolWithChecksSeqReqDA_MissingSystem: ProtocolWithChecksSe
5252
//
5353
// expected-error@-4{{distributed actor 'ProtocolWithChecksSeqReqDA_MissingSystem' does not declare ActorSystem it can be used with}}
5454
//
55-
// expected-error@-6{{type 'ProtocolWithChecksSeqReqDA_MissingSystem' does not conform to protocol 'Encodable'}}
56-
// expected-error@-7{{type 'ProtocolWithChecksSeqReqDA_MissingSystem' does not conform to protocol 'Decodable'}}
55+
// expected-error@-6{{type 'ProtocolWithChecksSeqReqDA_MissingSystem' does not conform to protocol 'DistributedActor'}}
56+
// expected-error@-7{{type 'ProtocolWithChecksSeqReqDA_MissingSystem' does not conform to protocol 'Encodable'}}
57+
// expected-error@-8{{type 'ProtocolWithChecksSeqReqDA_MissingSystem' does not conform to protocol 'Decodable'}}
5758

5859
// Entire conformance is doomed, so we didn't proceed to checking the functions; that's fine
5960
distributed func testAT() async throws -> NotCodable { .init() }

0 commit comments

Comments
 (0)