Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions lib/Sema/CSOptimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,6 @@ static bool isStandardInfixLogicalOperator(Constraint *disjunction) {
return false;
}

static bool isOperatorNamed(Constraint *disjunction, StringRef name) {
auto *choice = disjunction->getNestedConstraints()[0];
if (auto *decl = getOverloadChoiceDecl(choice))
return decl->isOperator() && decl->getBaseIdentifier().is(name);
return false;
}

static bool isArithmeticOperator(ValueDecl *decl) {
return decl->isOperator() && decl->getBaseIdentifier().isArithmeticOperator();
}
Expand Down Expand Up @@ -1022,19 +1015,6 @@ static void determineBestChoicesInContext(
optionals.size());
types.push_back({type,
/*fromLiteral=*/true});
} else if (literal.first ==
cs.getASTContext().getProtocol(
KnownProtocolKind::ExpressibleByNilLiteral) &&
literal.second.IsDirectRequirement) {
// `==` and `!=` operators have special overloads that accept `nil`
// as `_OptionalNilComparisonType` which is preferred over a
// generic form `(T?, T?)`.
if (isOperatorNamed(disjunction, "==") ||
isOperatorNamed(disjunction, "!=")) {
auto nilComparisonTy =
cs.getASTContext().get_OptionalNilComparisonTypeType();
types.push_back({nilComparisonTy, /*fromLiteral=*/true});
}
}
}

Expand Down
16 changes: 16 additions & 0 deletions test/Constraints/rdar158063151.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// RUN: %target-swift-emit-silgen %s | %FileCheck %s

// Make sure that the type-checker selects an `Equatable.==` instead of one from stdlib that takes _OptionalNilComparisonType

struct Value: Equatable, ExpressibleByNilLiteral {
init(nilLiteral: ()) {
}
}

// CHECK-LABEL: sil hidden [ossa] @$s13rdar1580631514test1vyAA5ValueV_tF : $@convention(thin) (Value) -> ()
// function_ref static Value.__derived_struct_equals(_:_:)
// CHECK: [[EQUALS_REF:%.*]] = function_ref @$s13rdar1580631515ValueV23__derived_struct_equalsySbAC_ACtFZ
// CHECK-NEXT: apply [[EQUALS_REF]](%0, {{.*}})
func test(v: Value) {
_ = v == nil
}
2 changes: 1 addition & 1 deletion test/SILOptimizer/infinite_recursion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public class U {
}

func == (l: S?, r: S?) -> Bool {
if l == nil && r == nil { return true }
if l == nil && r == nil { return true } // expected-warning {{function call causes an infinite recursion}}
guard let l = l, let r = r else { return false }
return l === r
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ let i: Int? = 1
let j: Int?
let k: Int? = 2

// expected-error@+1 {{the compiler is unable to type-check this expression in reasonable time}}
let _ = [i, j, k].reduce(0 as Int?) {
$0 != nil && $1 != nil ? $0! + $1! : ($0 != nil ? $0! : ($1 != nil ? $1! : nil))
}