Skip to content

Commit fca77b3

Browse files
authored
Merge pull request swiftlang#15069 from apple/revert-14846-rdar-37790062-alt
Revert "[CSSolver] Use correct locator when matching function result types re…"
2 parents c4c5b71 + d8b355d commit fca77b3

File tree

7 files changed

+14
-174
lines changed

7 files changed

+14
-174
lines changed

lib/SILGen/SILGenPoly.cpp

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,9 +1573,6 @@ class ResultPlanner {
15731573
///
15741574
/// Valid: reabstraction info, InnerResult, OuterResult.
15751575
ReabstractDirectToDirect,
1576-
1577-
/// Ignore the next direct inner result, since the outer is 'Void'.
1578-
IgnoreDirectResult,
15791576
};
15801577

15811578
Operation(Kind kind) : TheKind(kind) {}
@@ -1720,24 +1717,6 @@ class ResultPlanner {
17201717
SILResultInfo outerResult,
17211718
SILValue optOuterResultAddr);
17221719

1723-
void planIgnoredResult(AbstractionPattern innerOrigType,
1724-
CanType innerSubstType, PlanData &planData) {
1725-
if (innerOrigType.isTuple()) {
1726-
auto innerSubstTuple = cast<TupleType>(innerSubstType);
1727-
for (unsigned i = 0, n = innerSubstTuple->getNumElements(); i != n; ++i)
1728-
planIgnoredResult(innerOrigType.getTupleElementType(i),
1729-
innerSubstTuple.getElementType(i), planData);
1730-
return;
1731-
}
1732-
1733-
auto innerResult = claimNextInnerResult(planData);
1734-
if (innerResult.isFormalIndirect() &&
1735-
SGF.silConv.isSILIndirect(innerResult))
1736-
(void)addInnerIndirectResultTemporary(planData, innerResult);
1737-
else
1738-
addIgnoreDirectResult();
1739-
}
1740-
17411720
/// Claim the next inner result from the plan data.
17421721
SILResultInfo claimNextInnerResult(PlanData &data) {
17431722
return claimNext(data.InnerResults);
@@ -1887,10 +1866,6 @@ class ResultPlanner {
18871866
op.OuterOrigType = outerOrigType;
18881867
op.OuterSubstType = outerSubstType;
18891868
}
1890-
1891-
void addIgnoreDirectResult() {
1892-
(void)addOperation(Operation::IgnoreDirectResult);
1893-
}
18941869
};
18951870

18961871
} // end anonymous namespace
@@ -1901,13 +1876,6 @@ void ResultPlanner::plan(AbstractionPattern innerOrigType,
19011876
AbstractionPattern outerOrigType,
19021877
CanType outerSubstType,
19031878
PlanData &planData) {
1904-
// Conversion from `() -> T` to `() -> Void` is allowed when
1905-
// the argument is a closure.
1906-
if (!innerSubstType->isVoid() && outerSubstType->isVoid()) {
1907-
planIgnoredResult(innerOrigType, innerSubstType, planData);
1908-
return;
1909-
}
1910-
19111879
// The substituted types must match up in tuple-ness and arity.
19121880
assert(
19131881
isa<TupleType>(innerSubstType) == isa<TupleType>(outerSubstType) ||
@@ -2616,10 +2584,6 @@ void ResultPlanner::execute(ArrayRef<SILValue> innerDirectResults,
26162584
case Operation::InjectOptionalIndirect:
26172585
SGF.B.createInjectEnumAddr(Loc, op.OuterResultAddr, op.SomeDecl);
26182586
continue;
2619-
2620-
case Operation::IgnoreDirectResult:
2621-
(void)claimNext(innerDirectResults);
2622-
continue;
26232587
}
26242588
llvm_unreachable("bad operation kind");
26252589
}

lib/Sema/CSRanking.cpp

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,32 +1007,14 @@ SolutionCompareResult ConstraintSystem::compareSolutions(
10071007
// Compare the type variable bindings.
10081008
auto &tc = cs.getTypeChecker();
10091009
for (auto &binding : diff.typeBindings) {
1010-
auto type1 = binding.bindings[idx1];
1011-
auto type2 = binding.bindings[idx2];
1012-
1013-
auto &impl = binding.typeVar->getImpl();
1014-
1015-
if (auto *locator = impl.getLocator()) {
1016-
auto path = locator->getPath();
1017-
if (!path.empty() &&
1018-
path.back().getKind() == ConstraintLocator::ClosureResult) {
1019-
// Since we support `() -> T` to `() -> Void` and
1020-
// `() -> Never` to `() -> T` conversions, it's always
1021-
// preferable to pick `T` rather than `Never` with
1022-
// all else being equal.
1023-
if (type2->isUninhabited())
1024-
++score1;
1025-
1026-
if (type1->isUninhabited())
1027-
++score2;
1028-
}
1029-
}
1030-
10311010
// If the type variable isn't one for which we should be looking at the
10321011
// bindings, don't.
1033-
if (!impl.prefersSubtypeBinding())
1012+
if (!binding.typeVar->getImpl().prefersSubtypeBinding())
10341013
continue;
10351014

1015+
auto type1 = binding.bindings[idx1];
1016+
auto type2 = binding.bindings[idx2];
1017+
10361018
// If the types are equivalent, there's nothing more to do.
10371019
if (type1->isEqual(type2))
10381020
continue;

lib/Sema/CSSimplify.cpp

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,8 +1212,10 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
12121212
return result;
12131213

12141214
// Result type can be covariant (or equal).
1215-
return matchTypes(func1->getResult(), func2->getResult(), subKind, subflags,
1216-
locator.withPathElement(ConstraintLocator::FunctionResult));
1215+
return matchTypes(func1->getResult(), func2->getResult(), subKind,
1216+
subflags,
1217+
locator.withPathElement(
1218+
ConstraintLocator::FunctionResult));
12171219
}
12181220

12191221
ConstraintSystem::TypeMatchResult
@@ -1499,8 +1501,6 @@ ConstraintSystem::TypeMatchResult
14991501
ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
15001502
TypeMatchOptions flags,
15011503
ConstraintLocatorBuilder locator) {
1502-
auto origType1 = type1;
1503-
15041504
bool isArgumentTupleConversion
15051505
= kind == ConstraintKind::ArgumentTupleConversion ||
15061506
kind == ConstraintKind::OperatorArgumentTupleConversion;
@@ -2243,32 +2243,7 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
22432243
// Allow '() -> T' to '() -> ()' and '() -> Never' to '() -> T' for closure
22442244
// literals.
22452245
if (auto elt = locator.last()) {
2246-
auto isClosureResult = [&]() {
2247-
if (elt->getKind() == ConstraintLocator::ClosureResult)
2248-
return true;
2249-
2250-
// If constraint is matching function results where
2251-
// left-hand side is a 'closure result' we need to allow
2252-
// certain implicit conversions.
2253-
if (elt->getKind() != ConstraintLocator::FunctionResult)
2254-
return false;
2255-
2256-
if (auto *typeVar = origType1->getAs<TypeVariableType>()) {
2257-
auto *locator = typeVar->getImpl().getLocator();
2258-
if (!locator)
2259-
return false;
2260-
2261-
auto path = locator->getPath();
2262-
if (path.empty())
2263-
return false;
2264-
2265-
return path.back().getKind() == ConstraintLocator::ClosureResult;
2266-
}
2267-
2268-
return false;
2269-
};
2270-
2271-
if (isClosureResult()) {
2246+
if (elt->getKind() == ConstraintLocator::ClosureResult) {
22722247
if (concrete && kind >= ConstraintKind::Subtype &&
22732248
(type1->isUninhabited() || type2->isVoid())) {
22742249
increaseScore(SK_FunctionConversion);

test/Constraints/closures.swift

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,7 @@ func rdar33429010_2() {
630630
let iter = I_33429010()
631631
var acc: Int = 0 // expected-warning {{}}
632632
let _: Int = AnySequence { iter }.rdar33429010(into: acc, { $0 + $1 })
633+
// expected-warning@-1 {{result of operator '+' is unused}}
633634
let _: Int = AnySequence { iter }.rdar33429010(into: acc, { $0.rdar33429010_incr($1) })
634635
}
635636

@@ -651,38 +652,3 @@ func rdar36054961() {
651652
str.replaceSubrange(range, with: str[range].reversed())
652653
}])
653654
}
654-
655-
protocol P_37790062 {
656-
associatedtype T
657-
var elt: T { get }
658-
}
659-
660-
func rdar37790062() {
661-
struct S<T> {
662-
init(_ a: () -> T, _ b: () -> T) {}
663-
}
664-
665-
class C1 : P_37790062 {
666-
typealias T = Int
667-
var elt: T { return 42 }
668-
}
669-
670-
class C2 : P_37790062 {
671-
typealias T = (String, Int, Void)
672-
var elt: T { return ("question", 42, ()) }
673-
}
674-
675-
func foo() -> Int { return 42 }
676-
func bar() -> Void {}
677-
func baz() -> (String, Int) { return ("question", 42) }
678-
func bzz<T>(_ a: T) -> T { return a }
679-
func faz<T: P_37790062>(_ a: T) -> T.T { return a.elt }
680-
681-
_ = S({ foo() }, { bar() }) // Ok, should infer T to be 'Void'
682-
_ = S({ baz() }, { bar() }) // Ok, should infer T to be 'Void'
683-
_ = S({ bzz(("question", 42)) }, { bar() }) // Ok
684-
_ = S({ bzz(String.self) }, { bar() }) // Ok
685-
_ = S({ bzz(((), (()))) }, { bar() }) // Ok
686-
_ = S({ bzz(C1()) }, { bar() }) // Ok
687-
_ = S({ faz(C2()) }, { bar() }) // Ok
688-
}

test/Constraints/rdar37790062.swift

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

test/IRGen/objc_retainAutoreleasedReturnValue.swift

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,13 @@ public func test(_ dict: NSDictionary) {
2424
// popq %rbp ;<== Blocks the handshake from objc_autoreleaseReturnValue
2525
// jmp 0x01ec20 ; symbol stub for: objc_retainAutoreleasedReturnValue
2626

27-
// CHECK-LABEL: define {{.*}}swiftcc %TSo12NSEnumeratorC* @"$S34objc_retainAutoreleasedReturnValue4testyySo12NSDictionaryCFSo12NSEnumeratorCADXEfU_"(%TSo12NSDictionaryC*)
27+
// CHECK-LABEL: define {{.*}}swiftcc void @"$S34objc_retainAutoreleasedReturnValue4testyySo12NSDictionaryCFyADXEfU_"(%TSo12NSDictionaryC*)
2828
// CHECK: entry:
2929
// CHECK: call {{.*}}@objc_msgSend
3030
// CHECK: notail call i8* @objc_retainAutoreleasedReturnValue
31-
// CHECK: ret %TSo12NSEnumeratorC*
31+
// CHECK: ret void
3232

33-
// CHECK-LABEL: define {{.*}}swiftcc void @"$SSo12NSDictionaryCSo12NSEnumeratorCIgxo_ABIegx_TR"(%TSo12NSDictionaryC*, i8*, %swift.opaque*)
34-
35-
// OPT-LABEL: define {{.*}}swiftcc void @"$S34objc_retainAutoreleasedReturnValue10useClosureyySo12NSDictionaryC_yADXEtF06$SSo12h44CSo12NSEnumeratorCIgxo_ABIegx_TR049$S34objc_bcD42Value4testyySo12a6CFSo12B8CADXEfU_Tf3npf_nTf1nc_nTf4g_n"(%TSo12NSDictionaryC*)
33+
// OPT-LABEL: define {{.*}}swiftcc void @"$S34objc_retainAutoreleasedReturnValue4testyySo12NSDictionaryCFyADXEfU_"(%TSo12NSDictionaryC*)
3634
// OPT: entry:
3735
// OPT: call {{.*}}@objc_msgSend
3836
// OPT: notail call i8* @objc_retainAutoreleasedReturnValue

test/expr/closure/closures.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ func rdar19179412() -> (Int) -> Int {
259259
func takesVoidFunc(_ f: () -> ()) {}
260260
var i: Int = 1
261261

262+
// expected-warning @+1 {{expression of type 'Int' is unused}}
262263
takesVoidFunc({i})
263264
// expected-warning @+1 {{expression of type 'Int' is unused}}
264265
var f1: () -> () = {i}

0 commit comments

Comments
 (0)