- Notifications
You must be signed in to change notification settings - Fork10.6k
IRGen: Narrow fix for type equivalence problem in searchNominalTypeMetadata()#85356
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Draft
slavapestov wants to merge1 commit intoswiftlang:mainChoose a base branch fromslavapestov:fix-rdar160649141
base:main
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
+73 −2
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
…tadata()This fixes a regression introduced bye3c8f42,but the root cause was actually a subtle invariant violationin IRGen.FulfillmentMap's use of canonical types as keys assumes thatcanonical type equality is sufficient for checking if two types"are the same". However, this is not true when those typescontain type parameters, because two distinct type parametersmight belong to the same equivalence class.Thus, when we take the type's context substitution map, andapply it to each type parameter in our given list ofrequirements, the substitution operation could output adifferent but equivalent type parameter.However, it turns out that in practice, we only end up herewith a type that is either fully substituted, or is exactlythe declared interface type of their nominal.In the latter case, the type's substitution map is theidentity substitution map, so we can just detect this case andskip the call to subst(). This avoids the problem.I added an assertion that will fire if this assumption is everviolated in the future. To support the general case, we willneed to pass down a generic signature that describes thetype parameters that appear in the given type, and use thissignature to reduce the type of each lookup key before weproceed.Fixes rdar://160649141.
@aschwaighofer@rjmccall This fixes the provided test case, but some validation tests now fail because it is in fact not true that the type we get here is always either fully substituted or the declared interface type. So this needs a real fix where we either pass down the right generic signature for reduction, or we map the type into the right generic environment so that we can then do |
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
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.
This fixes a regression introduced bye3c8f42, but the root cause was actually a subtle invariant violation in IRGen.
FulfillmentMap's use of canonical types as keys assumes that canonical type equality is sufficient for checking if two types "are the same". However, this is not true when those types contain type parameters, because two distinct type parameters might belong to the same equivalence class.
Thus, when we take the type's context substitution map, and apply it to each type parameter in our given list of requirements, the substitution operation could output a different but equivalent type parameter.
However, it turns out that in practice, we only end up here with a type that is either fully substituted, or is exactly the declared interface type of their nominal.
In the latter case, the type's substitution map is the identity substitution map, so we can just detect this case and skip the call to subst(). This avoids the problem.
I added an assertion that will fire if this assumption is ever violated in the future. To support the general case, we will need to pass down a generic signature that describes the type parameters that appear in the given type, and use this signature to reduce the type of each lookup key before we proceed.
Fixes rdar://160649141.