-
Notifications
You must be signed in to change notification settings - Fork 10.6k
[CS] Open generic requirements for types with unbound + placeholder types #83870
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
b4adeff
to
d321ed0
Compare
@swift-ci please test source compatibility |
@swift-ci please SourceKit stress test |
Requirement opening relies on being able to query the opened type to allow requirement fix coalescing to work. Record the opened type before we open requirements to ensure we don't duplicate requirement fixes on the base type with requirement fixes for the member.
…ypes - Introduce a generic requirements opening function for type resolution, which is used by the constraint system in cases where we need to impose requirements on opened type variables. - Refactor `replaceInferableTypesWithTypeVars` to use this function when opening generic types that contain either placeholder or unbound generic types. Together these changes ensure that we don't drop generic requirements when an unbound generic or placeholder type is used as a generic argument.
@swift-ci please test |
// In principle we shouldn't need to open the generic parameters here, we | ||
// could just open the requirements using the substituted arguments directly, | ||
// but that doesn't allow us to correctly handle requirement fix coalescing | ||
// in `isFixedRequirement`. So instead we open the generic parameters and | ||
// then bind the resulting type variables to the substituted args. | ||
SmallVector<OpenedType, 4> replacements; | ||
cs.openGenericParameters(outerDC, sig, replacements, locator, | ||
preparedOverload); |
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 alternative approach here would be adjusting getTypeOfMemberReference
to avoid opening requirements that are already imposed by the base type (b4adeff), but that needs a workaround for at least LLDB, and generally seems like it could be more error prone. Given we need to fix the locators here anyway to be unique, this seems like the simplest way of avoiding the duplicate diagnostics
replaceInferableTypesWithTypeVars
to use this function when opening generic types that contain either placeholder or unbound generic types.Together these changes ensure that we don't drop generic requirements when an unbound generic or placeholder type is used as a generic argument.
rdar://154857586
Resolves #82722