Skip to content

Commit 2f6cb21

Browse files
committed
[AST] Prefer 'synthesized' conformances to 'implied' ones consistently.
When determining which declaration context should own a particular protocol conformance that was not explicitly spelled out, prefer "synthesized" contexts (i.e., which is always the nominal type itself) for automatically-generated conformances (such as a raw-valued enum's conformance to RawRepresentable) to conformances that are "implied" by conformance to a more-refined protocol. Previously, we biased the other way---but because conformances due to more-refined protocols can be discovered later, we could get into a problem where two files disagreed on which context would own the conformance---and neither would emit the corresponding witness table. Biasing toward "synthesized" contexts, which are always trivially discoverable from the nominal type declaration itself, eliminates the issue. Fixes SR-6839 / rdar://problem/36911943.
1 parent d0c6f73 commit 2f6cb21

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

include/swift/AST/DeclContext.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ enum class LocalDeclContextKind : uint8_t {
120120
///
121121
/// The enumerators are ordered in terms of decreasing preference:
122122
/// an inherited conformance is best, followed by explicit
123-
/// conformances, then implied conformances. Earlier conformance
124-
/// kinds supersede later conformance kinds, possibly with a
123+
/// conformances, then synthesized and implied conformances. Earlier
124+
/// conformance kinds supersede later conformance kinds, possibly with a
125125
/// diagnostic (e.g., if an inherited conformance supersedes an
126126
/// explicit conformance).
127127
enum class ConformanceEntryKind : unsigned {
@@ -131,11 +131,11 @@ enum class ConformanceEntryKind : unsigned {
131131
/// Explicitly specified.
132132
Explicit,
133133

134-
/// Implied by an explicitly-specified conformance.
135-
Implied,
136-
137134
/// Implicitly synthesized.
138135
Synthesized,
136+
137+
/// Implied by an explicitly-specified conformance.
138+
Implied,
139139
};
140140

141141
/// Describes the kind of conformance lookup desired.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class EnumValueConstructor<EnumType : EnumValueType> where EnumType.RawValue : Hashable {}
2+
class _PositionRelation_GeneratedWrapperConstructor : EnumValueConstructor<_PositionRelation> {}
3+
extension _PositionRelation : EnumValueType {}
4+
protocol EnumValueType : RawRepresentable {}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %target-swift-frontend -emit-sil -module-name main -primary-file %s %S/Inputs/protocol-conformance-sr6839-other.swift | %FileCheck -check-prefix CHECK-FIRST %s
2+
// RUN: %target-swift-frontend -emit-sil -module-name main %s -primary-file %S/Inputs/protocol-conformance-sr6839-other.swift | %FileCheck -check-prefix CHECK-SECOND %s
3+
4+
// We need to consistently pick where the witness table for _PositionRelation :
5+
// RawRepresentable goes.
6+
// CHECK-FIRST: sil_witness_table hidden _PositionRelation: RawRepresentable
7+
// CHECK-SECOND-NOT: sil_witness_table hidden _PositionRelation: RawRepresentable
8+
enum _PositionRelation: Int {
9+
case before = 0
10+
}

0 commit comments

Comments
 (0)