Skip to content

[runtime] Handle same-type constraints when resolving generic params #25984

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

Merged
merged 2 commits into from
Jul 9, 2019

Conversation

jrose-apple
Copy link
Contributor

@jrose-apple jrose-apple commented Jul 5, 2019

Generic parameters for a context are normally classified as "key", meaning they have actual metadata provided at runtime, or non-key, meaning they're derivable from somewhere else. However, a nested context or constrained extension can take what would be a "key" parameter in a parent context and make it non-key in a child context. This messes with the mapping between the (depth, index) representation of generic parameters and the flat list of generic arguments. Fix this by (1) consistently substituting out extension contexts with the contexts of the extended types, and (2) checking if a same-type constraint was (2a) newly applied in a particular context, and (2b) constrains a parent's generic parameter using the most nested context to decide which parameters are key, instead of the context a parameter was originally introduced in.

Note that this may have problems if/when extensions start introducing their own generic parameters (*cough* #25263 *cough*). For now I tried to be consistent with what was there.

rdar://problem/52364601

@jrose-apple
Copy link
Contributor Author

Tests written to build on #25955.

@swift-ci Please test

@jrose-apple
Copy link
Contributor Author

I have a bunch of tests already but what did I miss? What classes of test did I miss?

Generic parameters for a context are normally classified as "key",
meaning they have actual metadata provided at runtime, or non-key,
meaning they're derivable from somewhere else. However, a nested
context or constrained extension can take what would be a "key"
parameter in a parent context and make it non-key in a child context.
This messes with the mapping between the (depth, index) representation
of generic parameters and the flat list of generic arguments. Fix this
by (1) consistently substituting out extension contexts with the
contexts of the extended types, and (2) using the most nested context
to decide which parameters are key, instead of the context a parameter
was originally introduced in.

Note that (1) may have problems if/when extensions start introducing
their /own/ generic parameters. For now I tried to be consistent with
what was there.

rdar://problem/52364601
@jrose-apple
Copy link
Contributor Author

@swift-ci Please test

@swift-ci
Copy link
Contributor

swift-ci commented Jul 9, 2019

Build failed
Swift Test Linux Platform
Git Sha - 3152543774100800774f93b4cf3f59e6be4fa609

@swift-ci
Copy link
Contributor

swift-ci commented Jul 9, 2019

Build failed
Swift Test OS X Platform
Git Sha - 3152543774100800774f93b4cf3f59e6be4fa609

Copy link
Contributor

@jckarter jckarter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks!

Copy link
Member

@DougGregor DougGregor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great

@jrose-apple
Copy link
Contributor Author

@swift-ci Please test Linux

@swift-ci
Copy link
Contributor

swift-ci commented Jul 9, 2019

Build failed
Swift Test Linux Platform
Git Sha - 4b8068d

@jrose-apple
Copy link
Contributor Author

@swift-ci Please test Linux

@jrose-apple
Copy link
Contributor Author

I'm going to merge this as is and then test type reconstruction separately in a follow-up change (as pointed out by Slava).

@jrose-apple jrose-apple merged commit 659c497 into swiftlang:master Jul 9, 2019
@jrose-apple jrose-apple deleted the same-gamgee branch July 9, 2019 20:43
jrose-apple added a commit to jrose-apple/swift that referenced this pull request Jul 9, 2019
[runtime] Handle same-type constraints when resolving generic params

rdar://problem/52364601
(cherry picked from commit 659c497)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants