-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[IDE] Inspect all equivalent type variables to replace a type variable by an archetype #63849
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
Conversation
…e by an archetype Sometimes the type variable itself doesn't have have an originator that can be replaced by an archetype but one of its equivalent type variable does. Search thorough all equivalent type variables, looking for one that can be replaced by a generic parameter.
@swift-ci Please smoke test |
@swift-ci Please SourceKit stress test |
@swift-ci Please smoke test macOS |
for (auto binding : bindings) { | ||
if (auto placeholder = binding.second->getAs<PlaceholderType>()) { | ||
if (placeholder->getOriginator().dyn_cast<TypeVariableType *>() == | ||
typeVar) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't quite understand what is going on here... Could you please elaborate on what you are trying to archive?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The motivation is what we are already doing above: If we have a placeholder whose originator is a type variable that represents a generic parameter, we want to replace that placeholder by the generic parameter before printing code completion results because for example in the test case I modified MyStruct<T>
looks more useful than MyStruct<_>
.
But, again in the test case below, we are receiving the following solution
--- Solution ---
Fixed score: <default 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0>
Type variables:
$T0 as <<placeholder for $T8>> @ locator@0x138048218 [Type@/Users/alex/swift-src/swift/test/IDE/complete_subscript.swift:40:11 -> generic parameter 'T']
$T1 as Int @ locator@0x1380482f0 [CodeCompletion@/Users/alex/swift-src/swift/test/IDE/complete_subscript.swift:40:20]
$T2 as MyStruct<<<placeholder for $T8>>> @ locator@0x1380483a8 [Subscript@/Users/alex/swift-src/swift/test/IDE/complete_subscript.swift:40:19 -> function result]
$T3 as (Int, <<placeholder for $T8>>) -> MyStruct<<<placeholder for $T8>>> @ locator@0x138048380 [Subscript@/Users/alex/swift-src/swift/test/IDE/complete_subscript.swift:40:19 -> subscript member]
$T7 as <<placeholder for $T8>> @ locator@0x138048ab8 [Subscript@/Users/alex/swift-src/swift/test/IDE/complete_subscript.swift:40:19 -> subscript member -> generic parameter 'T']
$T8 as <<placeholder for $T8>> @ locator@0x138048d78 [Subscript@/Users/alex/swift-src/swift/test/IDE/complete_subscript.swift:40:19 -> apply argument -> comparing call argument #1 to parameter #1 -> synthesized argument #1]
And the argument we want to look up has type T8
. Now T8
doesn’t represent a generic parameter and thus we were outputting _
for the placeholder in the results. But actually looking at the solution, you can see that T8
has the same type as T0
(because T0
is bound to T8
) and T0
represents a generic parameter. Thus, for printing purposes we can replace the placeholder for T8
by the generic parameter that T0
represents, which is T
.
Does this make sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this transformation should happen in ConstraintSystem::finalize
while we are forming a complete solution in code completion mode instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed offline, I’ll do this in a follow up PR and filed rdar://106082607 so we don’t forget about it.
Sometimes the type variable itself doesn't have have an originator that can be replaced by an archetype but one of its equivalent type variable does. Search thorough all equivalent type variables, looking for one that can be replaced by a generic parameter.