[5.1] [runtime] Handle same-type constraints when resolving generic params #26032
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Explanation: Swift uses mangled names to encode references to types that can be resolved at run time. However, the runtime support for this wasn't doing so correctly when a nested generic context makes one of an outer context's generic parameters redundant with a same-type constraint. This patch fixes two ways in which that logic was incorrect: it wasn't following extensions back to the original type, and it wasn't looking at the innermost context to see if a type was redundant.
Scope: Affects how the runtime resolves generic parameters when referenced from the metadata of generic types.
Issue: rdar://problem/52364601
Risk: Medium. The scope is pretty broad here, even if working code shouldn't change behavior in practice. It's possible that an existing app is encountering this bug today but coincidentally "working" based on incorrect information, and that app could change behavior.
Testing: Added compiler regression tests.
Reviewed by: @jckarter, @DougGregor