Skip to content

[GenericSig Builder] Track and canonicalize same-type-to-concrete constraints #7518

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 5 commits into from
Feb 23, 2017

Conversation

DougGregor
Copy link
Member

@DougGregor DougGregor commented Feb 16, 2017

Track each same-type-to-concrete constraint on the potential archetype
against which it was written, and ensure that the requirement sources
for such same-type constraints stay with the potential archetypes on
which they were described. This is similar to the way we track
same-type constraints among potential archetypes.

Use this information to canonicalize same-type-to-concrete constraints
appropriately. For each connected component within an equivalence
class of potential archetypes, select the best requirement source to
the concrete type, or substitute in an abstract requirement source if
none exists. This approach ensures that components that would be
equivalent to that concrete type anyway get a derived source, while
components that get the concrete-type equivalence by being tied to
another component end up with (abstract) explicit requirements to the concrete type.

To get here, we also needed to change the notion of the archetype
anchor so that potential archetypes with no same-type constraints
directly in their path are preferred over potential archetypes that do
have a same-type constraint in their path. Otherwise, the anchor might
be something that is always concrete and is, therefore, not terribly
interesting.

Fixes the new case that popped up in rdar://problem/30478915.

@DougGregor
Copy link
Member Author

@swift-ci please smoke test and merge

@DougGregor
Copy link
Member Author

@swift-ci please smoke test

@DougGregor
Copy link
Member Author

Oh, requirement sources. Right.

…straints.

Track each same-type-to-concrete constraint on the potential archetype
against which it was written, and ensure that the requirement sources
for such same-type constraints stay with the potential archetypes on
which they were described. This is similar to the way we track
same-type constraints among potential archetypes.

Use this information to canonicalize same-type-to-concrete constraints
appropriately. For each connected component within an equivalence
class of potential archetypes, select the best requirement source to
the concrete type, or substitute in an abstract requirement source if
none exists. This approach ensures that components that would be
equivalent to that concrete type anyway get a derived source, while
components that get the concrete-type equivalence by being tied to
another

To get here, we also needed to change the notion of the archetype
anchor so that potential archetypes with no same-type constraints
directly in their path are preferred over potential archetypes that do
have a same-type constraint in their path. Otherwise, the anchor might
be something that is always concrete and is, therefore, not terribly
interesting.

Fixes the new case that popped up in rdar://problem/30478915.
`GenericSignatureBuilder::resolve()` was always jumping to the
representative, to treat typealias representatives as
special. However, doing this means that we put the same-type
constraint on the wrong potential archetype (with the wrong source).

Eliminate the use of `getRepresentative()`. This unfortunately
causes us to need recursive resolution, because we can't always depend
on jumping to the representative to avoid it.
@DougGregor DougGregor force-pushed the concrete-archetype-anchors branch from 65997d6 to 10fc3fa Compare February 22, 2017 06:20
@DougGregor DougGregor changed the title [GenericSig Builder] Prefer non-concrete to concrete archetype anchors. [GenericSig Builder] Track and canonicalize same-type-to-concrete constraints Feb 22, 2017
@DougGregor
Copy link
Member Author

@huonw the non-recursive resolution in the new resolve() ended up causing some fun issues here. Specifically, the last commit that removes the getRepresentative() from that function required me to do recursive expansion (which is a bit of a bummer).

@DougGregor
Copy link
Member Author

@swift-ci please smoke test

1 similar comment
@DougGregor
Copy link
Member Author

@swift-ci please smoke test

@DougGregor
Copy link
Member Author

Interesting failure on Linux:

swift::GenericEnvironment::getSubstitutionMap(SubstitutionList) const: Assertion `contextTy->hasError()' failed.

@DougGregor
Copy link
Member Author

@swift-ci please test OS X

@swift-ci
Copy link
Contributor

Build failed
Jenkins build - Swift Test OS X Platform
Git Commit - 65997d6badfbbe783bfce8bc40f9c29b76570cd3
Test requested by - @DougGregor

@slavapestov
Copy link
Contributor

@DougGregor You have a type that appears in getAllDependentTypes(), but maps to a concrete type... this isn't supposed to happen.

@DougGregor
Copy link
Member Author

@swift-ci please smoke test Linux

@huonw
Copy link
Contributor

huonw commented Feb 22, 2017

@huonw the non-recursive resolution in the new resolve() ended up causing some fun issues here. Specifically, the last commit that removes the getRepresentative() from that function required me to do recursive expansion (which is a bit of a bummer).

I think switching it to be recursive should be fine: the only reason it wasn't was that it didn't need to be at the time.

@DougGregor
Copy link
Member Author

Okay. I actually hope we can avoid the recursion, because in destroying type sugar we lose some information that I don't want to lose, but it Needs More Thought.

… map.

It turns out that GenericSignature::getAllDependentTypes() sometimes
includes generic type parameter types that have been made
concrete. Tolerate this for now, because fixing it causes issues
elsewhere.
@DougGregor
Copy link
Member Author

@swift-ci please smoke test and merge

1 similar comment
@DougGregor
Copy link
Member Author

@swift-ci please smoke test and merge

@swift-ci swift-ci merged commit f1231a4 into swiftlang:master Feb 23, 2017
@DougGregor DougGregor deleted the concrete-archetype-anchors branch February 23, 2017 02:46
@DougGregor
Copy link
Member Author

@slavapestov, I weakened the assert. But I still want to look into the generic parameters that are ending up concrete but are still in getAllDepwndentTypes

@swiftix
Copy link
Contributor

swiftix commented Feb 23, 2017

@DougGregor Very nice! Could you also try to fix rdar://30610428? This is the next blocker for the partial specialization.

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.

5 participants