Skip to content

Commit 7d6af90

Browse files
authored
Merge pull request #22659 from DougGregor/no-declcontext-local-protocol-sorting
Eliminate "sorting" of DeclContext-local protocols / conformances.
2 parents 57924c2 + d31ef61 commit 7d6af90

File tree

13 files changed

+33
-60
lines changed

13 files changed

+33
-60
lines changed

include/swift/AST/DeclContext.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -541,17 +541,13 @@ class alignas(1 << DeclContextAlignInBits) DeclContext {
541541
///
542542
/// \param diagnostics If non-null, will be populated with the set of
543543
/// diagnostics that should be emitted for this declaration context.
544-
///
545-
/// \param sorted Whether to sort the results in a canonical order.
546-
///
547544
/// FIXME: This likely makes more sense on IterableDeclContext or
548545
/// something similar.
549546
SmallVector<ProtocolDecl *, 2>
550547
getLocalProtocols(ConformanceLookupKind lookupKind
551548
= ConformanceLookupKind::All,
552549
SmallVectorImpl<ConformanceDiagnostic> *diagnostics
553-
= nullptr,
554-
bool sorted = false) const;
550+
= nullptr) const;
555551

556552
/// Retrieve the set of protocol conformances associated with this
557553
/// declaration context.
@@ -561,16 +557,13 @@ class alignas(1 << DeclContextAlignInBits) DeclContext {
561557
/// \param diagnostics If non-null, will be populated with the set of
562558
/// diagnostics that should be emitted for this declaration context.
563559
///
564-
/// \param sorted Whether to sort the results in a canonical order.
565-
///
566560
/// FIXME: This likely makes more sense on IterableDeclContext or
567561
/// something similar.
568562
SmallVector<ProtocolConformance *, 2>
569563
getLocalConformances(ConformanceLookupKind lookupKind
570564
= ConformanceLookupKind::All,
571565
SmallVectorImpl<ConformanceDiagnostic> *diagnostics
572-
= nullptr,
573-
bool sorted = false) const;
566+
= nullptr) const;
574567

575568
/// Retrieve the syntactic depth of this declaration context, i.e.,
576569
/// the number of non-module-scoped contexts.

lib/AST/ProtocolConformance.cpp

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,8 +1381,7 @@ NominalTypeDecl::getSatisfiedProtocolRequirementsForMember(
13811381
SmallVector<ProtocolDecl *, 2>
13821382
DeclContext::getLocalProtocols(
13831383
ConformanceLookupKind lookupKind,
1384-
SmallVectorImpl<ConformanceDiagnostic> *diagnostics,
1385-
bool sorted) const
1384+
SmallVectorImpl<ConformanceDiagnostic> *diagnostics) const
13861385
{
13871386
SmallVector<ProtocolDecl *, 2> result;
13881387

@@ -1401,19 +1400,13 @@ DeclContext::getLocalProtocols(
14011400
nullptr,
14021401
diagnostics);
14031402

1404-
// Sort if required.
1405-
if (sorted) {
1406-
llvm::array_pod_sort(result.begin(), result.end(), TypeDecl::compare);
1407-
}
1408-
14091403
return result;
14101404
}
14111405

14121406
SmallVector<ProtocolConformance *, 2>
14131407
DeclContext::getLocalConformances(
14141408
ConformanceLookupKind lookupKind,
1415-
SmallVectorImpl<ConformanceDiagnostic> *diagnostics,
1416-
bool sorted) const
1409+
SmallVectorImpl<ConformanceDiagnostic> *diagnostics) const
14171410
{
14181411
SmallVector<ProtocolConformance *, 2> result;
14191412

@@ -1439,12 +1432,6 @@ DeclContext::getLocalConformances(
14391432
&result,
14401433
diagnostics);
14411434

1442-
// If requested, sort the results.
1443-
if (sorted) {
1444-
llvm::array_pod_sort(result.begin(), result.end(),
1445-
&ConformanceLookupTable::compareProtocolConformances);
1446-
}
1447-
14481435
return result;
14491436
}
14501437

lib/IRGen/GenClass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1174,7 +1174,7 @@ namespace {
11741174
llvm::SmallSetVector<ProtocolDecl *, 2> protocols;
11751175
for (auto conformance : dc->getLocalConformances(
11761176
ConformanceLookupKind::OnlyExplicit,
1177-
nullptr, /*sorted=*/true)) {
1177+
nullptr)) {
11781178
ProtocolDecl *proto = conformance->getProtocol();
11791179
getObjCProtocols(proto, protocols);
11801180
}

lib/IRGen/GenDecl.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -880,8 +880,7 @@ IRGenModule::getConstantReferenceForProtocolDescriptor(ProtocolDecl *proto) {
880880

881881
void IRGenModule::addLazyConformances(DeclContext *dc) {
882882
for (const ProtocolConformance *conf :
883-
dc->getLocalConformances(ConformanceLookupKind::All,
884-
nullptr, /*sorted=*/true)) {
883+
dc->getLocalConformances(ConformanceLookupKind::All, nullptr)) {
885884
IRGen.addLazyWitnessTable(conf);
886885
}
887886
}

lib/SILGen/SILGenDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1438,7 +1438,7 @@ void SILGenModule::emitExternalDefinition(Decl *d) {
14381438
// Emit witness tables.
14391439
auto nom = cast<NominalTypeDecl>(d);
14401440
for (auto c : nom->getLocalConformances(ConformanceLookupKind::All,
1441-
nullptr, /*sorted=*/true)) {
1441+
nullptr)) {
14421442
auto *proto = c->getProtocol();
14431443
if (Lowering::TypeConverter::protocolRequiresWitnessTable(proto) &&
14441444
isa<NormalProtocolConformance>(c) &&

lib/SILGen/SILGenType.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -968,8 +968,7 @@ class SILGenType : public TypeMemberVisitor<SILGenType> {
968968
// Emit witness tables for conformances of concrete types. Protocol types
969969
// are existential and do not have witness tables.
970970
for (auto *conformance : theType->getLocalConformances(
971-
ConformanceLookupKind::All,
972-
nullptr, /*sorted=*/true)) {
971+
ConformanceLookupKind::All, nullptr)) {
973972
if (conformance->isComplete() &&
974973
isa<NormalProtocolConformance>(conformance))
975974
SGM.getWitnessTable(conformance);
@@ -1070,7 +1069,7 @@ class SILGenExtension : public TypeMemberVisitor<SILGenExtension> {
10701069
// extension.
10711070
for (auto *conformance : e->getLocalConformances(
10721071
ConformanceLookupKind::All,
1073-
nullptr, /*sorted=*/true)) {
1072+
nullptr)) {
10741073
if (conformance->isComplete() &&
10751074
isa<NormalProtocolConformance>(conformance))
10761075
SGM.getWitnessTable(conformance);

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5020,8 +5020,7 @@ void TypeChecker::checkConformancesInContext(DeclContext *dc,
50205020
// Check each of the conformances associated with this context.
50215021
SmallVector<ConformanceDiagnostic, 4> diagnostics;
50225022
auto conformances = dc->getLocalConformances(ConformanceLookupKind::All,
5023-
&diagnostics,
5024-
/*sorted=*/true);
5023+
&diagnostics);
50255024

50265025
// The conformance checker bundle that checks all conformances in the context.
50275026
MultiConformanceChecker groupChecker(*this);

lib/Serialization/Serialization.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2771,8 +2771,7 @@ void Serializer::writeDecl(const Decl *D) {
27712771
(void)addDeclRef(baseNominal);
27722772

27732773
auto conformances = extension->getLocalConformances(
2774-
ConformanceLookupKind::All,
2775-
nullptr, /*sorted=*/true);
2774+
ConformanceLookupKind::All, nullptr);
27762775

27772776
SmallVector<TypeID, 8> inheritedAndDependencyTypes;
27782777
for (auto inherited : extension->getInherited()) {
@@ -3027,8 +3026,7 @@ void Serializer::writeDecl(const Decl *D) {
30273026
auto contextID = addDeclContextRef(theStruct->getDeclContext());
30283027

30293028
auto conformances = theStruct->getLocalConformances(
3030-
ConformanceLookupKind::All,
3031-
nullptr, /*sorted=*/true);
3029+
ConformanceLookupKind::All, nullptr);
30323030

30333031
SmallVector<TypeID, 4> inheritedTypes;
30343032
for (auto inherited : theStruct->getInherited()) {
@@ -3065,8 +3063,7 @@ void Serializer::writeDecl(const Decl *D) {
30653063
auto contextID = addDeclContextRef(theEnum->getDeclContext());
30663064

30673065
auto conformances = theEnum->getLocalConformances(
3068-
ConformanceLookupKind::All,
3069-
nullptr, /*sorted=*/true);
3066+
ConformanceLookupKind::All, nullptr);
30703067

30713068
SmallVector<TypeID, 4> inheritedAndDependencyTypes;
30723069
for (auto inherited : theEnum->getInherited()) {
@@ -3120,8 +3117,7 @@ void Serializer::writeDecl(const Decl *D) {
31203117
auto contextID = addDeclContextRef(theClass->getDeclContext());
31213118

31223119
auto conformances = theClass->getLocalConformances(
3123-
ConformanceLookupKind::All,
3124-
nullptr, /*sorted=*/true);
3120+
ConformanceLookupKind::All, nullptr);
31253121

31263122
SmallVector<TypeID, 4> inheritedTypes;
31273123
for (auto inherited : theClass->getInherited()) {

test/IRGen/deserialize-clang-importer-witness-tables.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ public func foo(line: String) {
99
// from the default argument expression passed to `RegEx(pattern:options:)`
1010
// below. Ensure that a local copy of the definition was deserialized
1111
// and lowered to IR.
12-
// CHECK-LABEL: define {{.*}} i8** @"$sSo26NSRegularExpressionOptionsVABSQSCWl"()
1312
// CHECK-LABEL: define {{.*}} void @"$sSo26NSRegularExpressionOptionsVs10SetAlgebraSCsACPxycfCTW"
13+
// CHECK-LABEL: define {{.*}} i8** @"$sSo26NSRegularExpressionOptionsVABSQSCWl"()
1414
let versionRegex = try! RegEx(pattern: "Apple")
1515
_ = versionRegex.firstMatch(in: line)
1616
}

test/SILGen/synthesized_conformance_class.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ final class Final<T> {
1010
// CHECK: deinit
1111
// CHECK: enum CodingKeys : CodingKey {
1212
// CHECK: case x
13+
// CHECK: @_implements(Equatable, ==(_:_:)) static func __derived_enum_equals(_ a: Final<T>.CodingKeys, _ b: Final<T>.CodingKeys) -> Bool
14+
// CHECK: var hashValue: Int { get }
15+
// CHECK: func hash(into hasher: inout Hasher)
1316
// CHECK: var stringValue: String { get }
1417
// CHECK: init?(stringValue: String)
1518
// CHECK: var intValue: Int? { get }
1619
// CHECK: init?(intValue: Int)
17-
// CHECK: @_implements(Equatable, ==(_:_:)) static func __derived_enum_equals(_ a: Final<T>.CodingKeys, _ b: Final<T>.CodingKeys) -> Bool
18-
// CHECK: var hashValue: Int { get }
19-
// CHECK: func hash(into hasher: inout Hasher)
2020
// CHECK: }
2121
// CHECK: }
2222

@@ -30,13 +30,13 @@ class Nonfinal<T> {
3030
// CHECK: deinit
3131
// CHECK: enum CodingKeys : CodingKey {
3232
// CHECK: case x
33+
// CHECK: @_implements(Equatable, ==(_:_:)) static func __derived_enum_equals(_ a: Nonfinal<T>.CodingKeys, _ b: Nonfinal<T>.CodingKeys) -> Bool
34+
// CHECK: var hashValue: Int { get }
35+
// CHECK: func hash(into hasher: inout Hasher)
3336
// CHECK: var stringValue: String { get }
3437
// CHECK: init?(stringValue: String)
3538
// CHECK: var intValue: Int? { get }
3639
// CHECK: init?(intValue: Int)
37-
// CHECK: @_implements(Equatable, ==(_:_:)) static func __derived_enum_equals(_ a: Nonfinal<T>.CodingKeys, _ b: Nonfinal<T>.CodingKeys) -> Bool
38-
// CHECK: var hashValue: Int { get }
39-
// CHECK: func hash(into hasher: inout Hasher)
4040
// CHECK: }
4141
// CHECK: }
4242

test/SILGen/synthesized_conformance_struct.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ struct Struct<T> {
1010
// CHECK: init(x: T)
1111
// CHECK: enum CodingKeys : CodingKey {
1212
// CHECK: case x
13-
// CHECK: var stringValue: String { get }
14-
// CHECK: init?(stringValue: String)
15-
// CHECK: var intValue: Int? { get }
16-
// CHECK: init?(intValue: Int)
1713
// CHECK-FRAGILE: @_implements(Equatable, ==(_:_:)) static func __derived_enum_equals(_ a: Struct<T>.CodingKeys, _ b: Struct<T>.CodingKeys) -> Bool
1814
// CHECK-RESILIENT: static func == (a: Struct<T>.CodingKeys, b: Struct<T>.CodingKeys) -> Bool
1915
// CHECK: var hashValue: Int { get }
2016
// CHECK: func hash(into hasher: inout Hasher)
17+
// CHECK: var stringValue: String { get }
18+
// CHECK: init?(stringValue: String)
19+
// CHECK: var intValue: Int? { get }
20+
// CHECK: init?(intValue: Int)
2121
// CHECK: }
2222
// CHECK: }
2323
// CHECK-LABEL: extension Struct : Equatable where T : Equatable {

test/api-digester/Outputs/cake-abi.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,8 +1203,8 @@
12031203
"conformances": [
12041204
{
12051205
"kind": "Conformance",
1206-
"name": "Comparable",
1207-
"printedName": "Comparable"
1206+
"name": "FixedWidthInteger",
1207+
"printedName": "FixedWidthInteger"
12081208
},
12091209
{
12101210
"kind": "Conformance",
@@ -1318,8 +1318,8 @@
13181318
},
13191319
{
13201320
"kind": "Conformance",
1321-
"name": "FixedWidthInteger",
1322-
"printedName": "FixedWidthInteger"
1321+
"name": "Comparable",
1322+
"printedName": "Comparable"
13231323
},
13241324
{
13251325
"kind": "Conformance",

test/api-digester/Outputs/cake.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,8 +1092,8 @@
10921092
"conformances": [
10931093
{
10941094
"kind": "Conformance",
1095-
"name": "Comparable",
1096-
"printedName": "Comparable"
1095+
"name": "FixedWidthInteger",
1096+
"printedName": "FixedWidthInteger"
10971097
},
10981098
{
10991099
"kind": "Conformance",
@@ -1216,8 +1216,8 @@
12161216
},
12171217
{
12181218
"kind": "Conformance",
1219-
"name": "FixedWidthInteger",
1220-
"printedName": "FixedWidthInteger"
1219+
"name": "Comparable",
1220+
"printedName": "Comparable"
12211221
},
12221222
{
12231223
"kind": "Conformance",

0 commit comments

Comments
 (0)