Skip to content

Commit 3f7d7c2

Browse files
author
Greg Parker
authored
Merge pull request swiftlang#12949 from apple/revert-12910-conditional-conformance-equatable
Revert "Use conditional conformances to implement Equatable for Optional, Array and Dictionary"
2 parents 29279af + e8475cc commit 3f7d7c2

18 files changed

+315
-344
lines changed

lib/Sema/CSApply.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,9 @@ namespace {
474474
tc.conformsToProtocol(baseTy, proto, cs.DC,
475475
(ConformanceCheckFlags::InExpression|
476476
ConformanceCheckFlags::Used));
477+
assert((!conformance ||
478+
conformance->getConditionalRequirements().empty()) &&
479+
"unhandled conditional conformance");
477480
if (conformance && conformance->isConcrete()) {
478481
if (auto witness =
479482
conformance->getConcrete()->getWitnessDecl(decl, &tc)) {

lib/Sema/CSDiag.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4844,7 +4844,7 @@ bool FailureDiagnosis::diagnoseArgumentGenericRequirements(
48444844
AFD = dyn_cast<AbstractFunctionDecl>(candidate);
48454845
}
48464846

4847-
if (!AFD || !AFD->getGenericSignature() || !AFD->hasInterfaceType())
4847+
if (!AFD || !AFD->isGeneric() || !AFD->hasInterfaceType())
48484848
return false;
48494849

48504850
auto env = AFD->getGenericEnvironment();

lib/Sema/MiscDiagnostics.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,15 +1418,7 @@ static void diagSyntacticUseRestrictions(TypeChecker &TC, const Expr *E,
14181418
/// x == nil // also !=
14191419
///
14201420
void checkOptionalPromotions(ApplyExpr *call) {
1421-
// We only care about binary expressions.
1422-
if (!isa<BinaryExpr>(call)) return;
1423-
1424-
// Dig out the function we're calling.
1425-
auto fnExpr = call->getSemanticFn();
1426-
if (auto dotSyntax = dyn_cast<DotSyntaxCallExpr>(fnExpr))
1427-
fnExpr = dotSyntax->getSemanticFn();
1428-
1429-
auto DRE = dyn_cast<DeclRefExpr>(fnExpr);
1421+
auto DRE = dyn_cast<DeclRefExpr>(call->getSemanticFn());
14301422
auto args = dyn_cast<TupleExpr>(call->getArg());
14311423
if (!DRE || !DRE->getDecl()->isOperator() ||
14321424
!args || args->getNumElements() != 2)

stdlib/public/core/Arrays.swift.gyb

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2181,55 +2181,57 @@ extension _ArrayBufferProtocol {
21812181
// that are the same, e.g. Array<Int> and Array<Int>, not
21822182
// ArraySlice<Int> and Array<Int>.
21832183

2184-
extension ${Self} : Equatable where Element : Equatable {
2185-
/// Returns `true` if these arrays contain the same elements.
2186-
@_inlineable
2187-
public static func ==(lhs: ${Self}<Element>, rhs: ${Self}<Element>) -> Bool {
2188-
let lhsCount = lhs.count
2189-
if lhsCount != rhs.count {
2190-
return false
2191-
}
2184+
/// Returns `true` if these arrays contain the same elements.
2185+
@_inlineable
2186+
public func == <Element : Equatable>(
2187+
lhs: ${Self}<Element>, rhs: ${Self}<Element>
2188+
) -> Bool {
2189+
let lhsCount = lhs.count
2190+
if lhsCount != rhs.count {
2191+
return false
2192+
}
21922193

2193-
// Test referential equality.
2194-
if lhsCount == 0 || lhs._buffer.identity == rhs._buffer.identity {
2195-
return true
2196-
}
2194+
// Test referential equality.
2195+
if lhsCount == 0 || lhs._buffer.identity == rhs._buffer.identity {
2196+
return true
2197+
}
21972198

2198-
%if Self == 'ArraySlice':
2199+
%if Self == 'ArraySlice':
21992200

2200-
var streamLHS = lhs.makeIterator()
2201-
var streamRHS = rhs.makeIterator()
2201+
var streamLHS = lhs.makeIterator()
2202+
var streamRHS = rhs.makeIterator()
22022203

2203-
var nextLHS = streamLHS.next()
2204-
while nextLHS != nil {
2205-
let nextRHS = streamRHS.next()
2206-
if nextLHS != nextRHS {
2207-
return false
2208-
}
2209-
nextLHS = streamLHS.next()
2204+
var nextLHS = streamLHS.next()
2205+
while nextLHS != nil {
2206+
let nextRHS = streamRHS.next()
2207+
if nextLHS != nextRHS {
2208+
return false
22102209
}
2210+
nextLHS = streamLHS.next()
2211+
}
22112212

2212-
%else:
2213+
%else:
22132214

2214-
_sanityCheck(lhs.startIndex == 0 && rhs.startIndex == 0)
2215-
_sanityCheck(lhs.endIndex == lhsCount && rhs.endIndex == lhsCount)
2215+
_sanityCheck(lhs.startIndex == 0 && rhs.startIndex == 0)
2216+
_sanityCheck(lhs.endIndex == lhsCount && rhs.endIndex == lhsCount)
22162217

2217-
// We know that lhs.count == rhs.count, compare element wise.
2218-
for idx in 0..<lhsCount {
2219-
if lhs[idx] != rhs[idx] {
2220-
return false
2221-
}
2218+
// We know that lhs.count == rhs.count, compare element wise.
2219+
for idx in 0..<lhsCount {
2220+
if lhs[idx] != rhs[idx] {
2221+
return false
22222222
}
2223-
%end
2224-
2225-
return true
22262223
}
2224+
%end
22272225

2228-
/// Returns `true` if the arrays do not contain the same elements.
2229-
@_inlineable
2230-
public static func !=(lhs: ${Self}<Element>, rhs: ${Self}<Element>) -> Bool {
2231-
return !(lhs == rhs)
2232-
}
2226+
return true
2227+
}
2228+
2229+
/// Returns `true` if the arrays do not contain the same elements.
2230+
@_inlineable
2231+
public func != <Element : Equatable>(
2232+
lhs: ${Self}<Element>, rhs: ${Self}<Element>
2233+
) -> Bool {
2234+
return !(lhs == rhs)
22332235
}
22342236

22352237
extension ${Self} {

stdlib/public/core/HashedCollections.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2708,7 +2708,7 @@ extension Dictionary {
27082708
}
27092709
}
27102710

2711-
extension Dictionary : Equatable where Value : Equatable {
2711+
extension Dictionary where Value : Equatable {
27122712
@_inlineable // FIXME(sil-serialize-all)
27132713
public static func == (lhs: [Key : Value], rhs: [Key : Value]) -> Bool {
27142714
switch (lhs._variantBuffer, rhs._variantBuffer) {

0 commit comments

Comments
 (0)