Skip to content

Commit 12fb6cb

Browse files
authored
Merge pull request #78305 from xedin/revert-CSBindings-changes-6.1
[6.1] Revert some changes to CSBinding that landed after branch was created
2 parents eaada37 + c55c2b6 commit 12fb6cb

File tree

4 files changed

+42
-39
lines changed

4 files changed

+42
-39
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -486,10 +486,6 @@ class TypeVariableType::Implementation {
486486
/// Determine whether this type variable represents a subscript result type.
487487
bool isSubscriptResultType() const;
488488

489-
/// Determine whether this type variable represents a result type of an
490-
/// application i.e. a call, an operator, or a subscript.
491-
bool isApplicationResultType() const;
492-
493489
/// Determine whether this type variable represents an opened
494490
/// type parameter pack.
495491
bool isParameterPack() const;

lib/Sema/CSBindings.cpp

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,19 +1208,7 @@ bool BindingSet::isViable(PotentialBinding &binding, bool isTransitive) {
12081208
if (!existingNTD || NTD != existingNTD)
12091209
continue;
12101210

1211-
// What is going on here needs to be thoroughly re-evaluated,
1212-
// but at least for now, let's not filter bindings of different
1213-
// kinds so if we have a situation like: `Array<$T0> conv $T1`
1214-
// and `$T1 conv Array<(String, Int)>` we can't lose `Array<$T0>`
1215-
// as a binding because `$T0` could be inferred to
1216-
// `(key: String, value: Int)` and binding `$T1` to `Array<(String, Int)>`
1217-
// eagerly would be incorrect.
1218-
if (existing->Kind != binding.Kind) {
1219-
// Array, Set and Dictionary allow conversions, everything else
1220-
// requires their generic arguments to match exactly.
1221-
if (existingType->isKnownStdlibCollectionType())
1222-
continue;
1223-
}
1211+
// FIXME: What is going on here needs to be thoroughly re-evaluated.
12241212

12251213
// If new type has a type variable it shouldn't
12261214
// be considered viable.
@@ -1276,8 +1264,7 @@ static bool hasConversions(Type type) {
12761264
}
12771265

12781266
return !(type->is<StructType>() || type->is<EnumType>() ||
1279-
type->is<BuiltinType>() || type->is<ArchetypeType>() ||
1280-
type->isVoid());
1267+
type->is<BuiltinType>() || type->is<ArchetypeType>());
12811268
}
12821269

12831270
bool BindingSet::favoredOverDisjunction(Constraint *disjunction) const {
@@ -1293,16 +1280,9 @@ bool BindingSet::favoredOverDisjunction(Constraint *disjunction) const {
12931280

12941281
return !hasConversions(binding.BindingType);
12951282
})) {
1296-
bool isApplicationResultType = TypeVar->getImpl().isApplicationResultType();
1297-
if (llvm::none_of(Info.DelayedBy, [&isApplicationResultType](
1298-
const Constraint *constraint) {
1299-
// Let's not attempt to bind result type before application
1300-
// happens. For example because it could be discardable or
1301-
// l-value (subscript applications).
1302-
if (isApplicationResultType &&
1303-
constraint->getKind() == ConstraintKind::ApplicableFunction)
1304-
return true;
1305-
1283+
// Result type of subscript could be l-value so we can't bind it early.
1284+
if (!TypeVar->getImpl().isSubscriptResultType() &&
1285+
llvm::none_of(Info.DelayedBy, [](const Constraint *constraint) {
13061286
return constraint->getKind() == ConstraintKind::Disjunction ||
13071287
constraint->getKind() == ConstraintKind::ValueMember;
13081288
}))

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -175,16 +175,6 @@ bool TypeVariableType::Implementation::isSubscriptResultType() const {
175175
KeyPathExpr::Component::Kind::UnresolvedSubscript;
176176
}
177177

178-
bool TypeVariableType::Implementation::isApplicationResultType() const {
179-
if (!(locator && locator->getAnchor()))
180-
return false;
181-
182-
if (!locator->isLastElement<LocatorPathElt::FunctionResult>())
183-
return false;
184-
185-
return isExpr<ApplyExpr>(locator->getAnchor()) || isSubscriptResultType();
186-
}
187-
188178
bool TypeVariableType::Implementation::isParameterPack() const {
189179
return locator
190180
&& locator->isForGenericParameter()

test/Constraints/rdar139812024.swift

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// RUN: %target-typecheck-verify-swift %clang-importer-sdk
2+
3+
// REQUIRES: objc_interop
4+
5+
// rdar://139812024 - error: cannot convert return expression of type 'NSObject' to return type 'NSImage'
6+
7+
import Foundation
8+
9+
@objc
10+
final class Image: NSObject {
11+
}
12+
13+
@available(*, unavailable)
14+
extension Image: Sendable {} // expected-note {{explicitly marked unavailable here}}
15+
16+
class Lock<State> {
17+
func withLock<R: Sendable>(_: @Sendable (inout State) -> R) -> R {
18+
fatalError()
19+
}
20+
}
21+
22+
extension Lock where State == Void {
23+
func withLock<R: Sendable>(_: @Sendable () -> R) -> R {
24+
fatalError()
25+
}
26+
}
27+
28+
class Test {
29+
var images: [Int: Image] = [:]
30+
31+
func fetchImage(lock: Lock<Void>, id: Int) -> Image? {
32+
if let existingImage = lock.withLock({ return images[id] }) { // expected-warning {{unavailable}}
33+
return existingImage
34+
}
35+
return nil
36+
}
37+
}

0 commit comments

Comments
 (0)