Skip to content

Commit 7390f7d

Browse files
authored
Merge pull request #41842 from slavapestov/gsb-relax-verify-check
GSB: Relax -requirement-machine-protocol-signatures=verify check a little
2 parents cd93d23 + 5eb29ae commit 7390f7d

File tree

3 files changed

+71
-62
lines changed

3 files changed

+71
-62
lines changed

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8662,23 +8662,24 @@ RequirementSignatureRequest::evaluate(Evaluator &evaluator,
86628662

86638663
auto compare = [&](ArrayRef<Requirement> rqmResult,
86648664
ArrayRef<Requirement> gsbResult) {
8665-
if (proto->getParentModule()->isStdlibModule() &&
8666-
(proto->getName().is("Collection") ||
8667-
proto->getName().is("StringProtocol"))) {
8668-
if (rqmResult.size() > gsbResult.size())
8669-
return false;
8670-
} else {
8671-
if (rqmResult.size() != gsbResult.size())
8665+
if (rqmResult.size() > gsbResult.size())
8666+
return false;
8667+
8668+
if (!std::equal(rqmResult.begin(),
8669+
rqmResult.end(),
8670+
gsbResult.begin(),
8671+
[](const Requirement &lhs,
8672+
const Requirement &rhs) {
8673+
return lhs.getCanonical() == rhs.getCanonical();
8674+
}))
8675+
return false;
8676+
8677+
for (auto req : gsbResult.slice(rqmResult.size())) {
8678+
if (req.getKind() != RequirementKind::SameType)
86728679
return false;
86738680
}
86748681

8675-
return std::equal(rqmResult.begin(),
8676-
rqmResult.end(),
8677-
gsbResult.begin(),
8678-
[](const Requirement &lhs,
8679-
const Requirement &rhs) {
8680-
return lhs.getCanonical() == rhs.getCanonical();
8681-
});
8682+
return true;
86828683
};
86838684

86848685
switch (ctx.LangOpts.RequirementMachineProtocolSignatures) {

test/Generics/sr8968.swift

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// RUN: %target-typecheck-verify-swift -requirement-machine-protocol-signatures=on
2+
// RUN: %target-swift-frontend -typecheck %s -debug-generic-signatures -requirement-machine-protocol-signatures=on 2>&1 | %FileCheck %s
3+
4+
public class OFMAttachment : NativeInserting {
5+
// expected-warning@-1 {{non-final class 'OFMAttachment' cannot safely conform to protocol 'NativeInserting', which requires that 'Self.SnapshotType.NativeType' is exactly equal to 'Self'; this is an error in Swift 6}}
6+
public typealias SnapshotType = Message.Attachment
7+
}
8+
9+
// CHECK-LABEL: .Snapshotting@
10+
// CHECK-NEXT: Requirement signature: <Self where Self == Self.[Snapshotting]ChangeType.[SnapshotChange]SnapshotType, Self.[Snapshotting]ChangeType : SnapshotChange, Self.[Snapshotting]NativeType : NativeInserting, Self.[Snapshotting]RecordType : SnapshotRecord, Self.[Snapshotting]ChangeType.[SnapshotChange]SnapshotType == Self.[Snapshotting]NativeType.[NativeInserting]SnapshotType, Self.[Snapshotting]NativeType.[NativeInserting]SnapshotType == Self.[Snapshotting]RecordType.[SnapshotRecord]SnapshotType>
11+
public protocol Snapshotting {
12+
associatedtype NativeType: NativeInserting where NativeType.SnapshotType == Self
13+
associatedtype RecordType: SnapshotRecord where RecordType.SnapshotType == Self
14+
associatedtype ChangeType: SnapshotChange where ChangeType.SnapshotType == Self
15+
16+
static var baseMessageName: String { get }
17+
}
18+
19+
// CHECK-LABEL: .NativeInserting@
20+
// CHECK-NEXT: Requirement signature: <Self where Self == Self.[NativeInserting]SnapshotType.[Snapshotting]NativeType, Self.[NativeInserting]SnapshotType : Snapshotting>
21+
public protocol NativeInserting {
22+
associatedtype SnapshotType : Snapshotting where SnapshotType.NativeType == Self
23+
}
24+
25+
// CHECK-LABEL: .SnapshotRecord@
26+
// CHECK-NEXT: Requirement signature: <Self where Self == Self.[SnapshotRecord]SnapshotType.[Snapshotting]RecordType, Self.[SnapshotRecord]SnapshotType : Snapshotting>
27+
public protocol SnapshotRecord {
28+
associatedtype SnapshotType : Snapshotting where SnapshotType.RecordType == Self
29+
30+
}
31+
32+
// CHECK-LABEL: .SnapshotChange@
33+
// CHECK-NEXT: Requirement signature: <Self where Self == Self.[SnapshotChange]SnapshotType.[Snapshotting]ChangeType, Self.[SnapshotChange]SnapshotType : Snapshotting>
34+
public protocol SnapshotChange {
35+
associatedtype SnapshotType : Snapshotting where SnapshotType.ChangeType == Self
36+
}
37+
38+
public struct Message {
39+
public enum Attachment : Snapshotting {
40+
41+
public static var baseMessageName: String = "attachment"
42+
43+
public typealias NativeType = OFMAttachment
44+
public typealias RecordType = Record
45+
public typealias ChangeType = Change
46+
public struct Record : SnapshotRecord {
47+
public typealias SnapshotType = Message.Attachment
48+
}
49+
50+
public struct Change : SnapshotChange {
51+
public typealias SnapshotType = Message.Attachment
52+
}
53+
54+
}
55+
}
56+

validation-test/compiler_crashers_2/sr8968.swift

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)