Skip to content

[CSBindings] Don't priorize variables without direct bindings over di… #69331

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 24, 2023
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
4 changes: 4 additions & 0 deletions lib/Sema/CSBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1080,6 +1080,10 @@ bool BindingSet::favoredOverDisjunction(Constraint *disjunction) const {
return boundType->lookThroughAllOptionalTypes()->is<TypeVariableType>();
}

// Don't prioritize type variables that don't have any direct bindings.
if (Bindings.empty())
return false;

return !involvesTypeVariables();
}

Expand Down
6 changes: 3 additions & 3 deletions test/Constraints/casts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,8 @@ func test_compatibility_coercions(_ arr: [Int], _ optArr: [Int]?, _ dict: [Strin
_ = [i: stringAnyDict] as [String: Any] // expected-error {{cannot convert value of type 'Int' to expected dictionary key type 'String'}}

// These are currently not peepholed.
_ = [i].self as Magic as [String] // expected-warning {{coercion from '[Int]' to '[String]' may fail; use 'as?' or 'as!' instead}}
_ = (try [i]) as Magic as [String] // expected-warning {{coercion from '[Int]' to '[String]' may fail; use 'as?' or 'as!' instead}}
_ = [i].self as Magic as [String] // expected-error {{cannot convert value of type 'Int' to expected element type 'String'}}
_ = (try [i]) as Magic as [String] // expected-error {{cannot convert value of type 'Int' to expected element type 'String'}}
// expected-warning@-1 {{no calls to throwing functions occur within 'try' expression}}

// These are wrong, but make sure we don't warn about the value cast always succeeding.
Expand Down Expand Up @@ -750,4 +750,4 @@ do {
_ = a is Issue68825 // expected-error {{cannot find type 'Issue68825' in scope}}
_ = a is String // OK
}
}
}
11 changes: 0 additions & 11 deletions test/SILGen/collection_downcast.swift
Original file line number Diff line number Diff line change
Expand Up @@ -297,15 +297,4 @@ func testCollectionCompatibilityCoercions(_ arr: [Int], _ optArr: [Any]?, _ set:
// CHECK: [[CAST_FN:%.+]] = function_ref @$ss17_dictionaryUpCastySDyq0_q1_GSDyxq_GSHRzSHR0_r2_lF : $@convention(thin) <τ_0_0, τ_0_1, τ_0_2, τ_0_3 where τ_0_0 : Hashable, τ_0_2 : Hashable> (@guaranteed Dictionary<τ_0_0, τ_0_1>) -> @owned Dictionary<τ_0_2, τ_0_3>
// CHECK: apply [[CAST_FN]]<String, Int, Int, String>([[DICT]]) : $@convention(thin) <τ_0_0, τ_0_1, τ_0_2, τ_0_3 where τ_0_0 : Hashable, τ_0_2 : Hashable> (@guaranteed Dictionary<τ_0_0, τ_0_1>) -> @owned Dictionary<τ_0_2, τ_0_3>
_ = promote(promote(promote(dict))) as [Int: String]

typealias Magic<T> = T

// These are currently not peepholed.
// CHECK: [[CAST_FN:%.+]] = function_ref @$ss15_arrayForceCastySayq_GSayxGr0_lF : $@convention(thin) <τ_0_0, τ_0_1> (@guaranteed Array<τ_0_0>) -> @owned Array<τ_0_1>
// CHECK: apply [[CAST_FN]]<Int, String>
[i].self as Magic as [String]

// CHECK: [[CAST_FN:%.+]] = function_ref @$ss15_arrayForceCastySayq_GSayxGr0_lF : $@convention(thin) <τ_0_0, τ_0_1> (@guaranteed Array<τ_0_0>) -> @owned Array<τ_0_1>
// CHECK: apply [[CAST_FN]]<Int, String>
(try [i]) as Magic as [String]
}