Skip to content

Commit 22e0f4a

Browse files
committed
[CSBindings] Mark generic parameter type vars as complete if they don't have any adjacent vars
Always marking generic parameter type variables as incomplete is too aggressive. That was the way to make sure that they are never attempted to eagerly, but really there are only a couple of situations where that can cause issues: ``` 1. Int <: $T_param $T1 <: $T_param 2. $T2 conv Generic<$T_param> $T2 conv Generic<Int?> Int <: $T_param ``` Attempting $T_param before $T1 in 1. could result in a missed optional type binding for example. Attempting $T_param too early in this case (before $T2) could miss some transitive bindings inferred through conversion of `Generic` type. If a type variable that represents a generic parameter is no longer associated with any type variables (directly or indirectly) it's safe to assume that its binding set is complete.
1 parent 34dd632 commit 22e0f4a

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

lib/Sema/CSBindings.cpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,30 @@ bool BindingSet::involvesTypeVariables() const {
173173
}
174174

175175
bool BindingSet::isPotentiallyIncomplete() const {
176-
// Generic parameters are always potentially incomplete.
176+
// Always marking generic parameter type variables as incomplete
177+
// is too aggressive. That was the way to make sure that they
178+
// are never attempted to eagerly, but really there are only a
179+
// couple of situations where that can cause issues:
180+
//
181+
// 1. Int <: $T_param
182+
// $T1 <: $T_param
183+
//
184+
// 2. $T2 conv Generic<$T_param>
185+
// $T2 conv Generic<Int?>
186+
// Int <: $T_param
187+
//
188+
// Attempting $T_param before $T1 in 1. could result in a missed
189+
// optional type binding for example.
190+
//
191+
// Attempting $T_param too early in this case (before $T2) could
192+
// miss some transitive bindings inferred through conversion
193+
// of `Generic` type.
194+
//
195+
// If a type variable that represents a generic parameter is no longer
196+
// associated with any type variables (directly or indirectly) it's safe
197+
// to assume that its binding set is complete.
177198
if (Info.isGenericParameter())
178-
return true;
199+
return involvesTypeVariables();
179200

180201
// Key path literal type is incomplete until there is a
181202
// contextual type or key path is resolved enough to infer

0 commit comments

Comments
 (0)