Skip to content

[Stdlib] Use associated type where clauses to address various ABI FIXMEs. #8593

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 9 commits into from
Apr 20, 2017

Conversation

DougGregor
Copy link
Member

Start using associated type where clauses in the standard library to model same-type constraints that were inexpressible before SE-0142. Clean up the warnings that result from these constraints being in the protocols where they belong.

Resolves SR-2121 and standard library ABI FIXMEs 68, 89, 90, 91, 92, 94, 96, and most of 99. Some of these are merely warnings in the unit testing library, but a few (68, 92, 99) are part of the core standard library protocols.

@DougGregor
Copy link
Member Author

@dabrahams , @huonw , and @gribozavr might be interested in this. It's WIP right now because it regresses a compiler crasher

@slavapestov
Copy link
Contributor

It's unfortunate that associatedtype _Element pops up in completion results now - but I see it has a FIXME saying it's a hack that should be removed. Any chance the problem is already fixed, or we could fix it pretty easily?

@DougGregor
Copy link
Member Author

The problem is "the library needs recursive constraints"

@dabrahams
Copy link
Contributor

dabrahams commented Apr 9, 2017

@DougGregor Are you sure? IIRC, _Element should be Element and should be constrained to be the same as Iterator.Element (and all the Iterator.Elements in constraints should be changed to Element).

@DougGregor
Copy link
Member Author

Oh! @dabrahams has the right answer... that's nice big cleanup to have

associatedtype Element

within Sequence and have it be equivalent to (and, for expressiveness purposes, preferred over) Iterator.Element.

@DougGregor
Copy link
Member Author

Just gotta stop that one crasher from looping ;)

@dabrahams
Copy link
Contributor

Very W00t and Wunderful to see all that red in the diff! Do let me know the moment we can start using it in the unicode-rethink branch!

@huonw
Copy link
Contributor

huonw commented Apr 10, 2017

I think the crasher Doug is struggling with is fairly invalid code that, even without this PR, currently still crashes, so, you should be able to use (/find bugs in) these where clauses now.

@DougGregor
Copy link
Member Author

Yeah, my struggles are entirely with recursively-constructed types now, not with the rest of the feature. That said, minor perturbations of the Sequence/Collection protocols trip over the recursively-constructed types, so when you see the compiler spinning in compareDependentTypes.... you hit one.

When computing the connected components of within an equivalence class (based on derived same-type requirements), we might need derived-via-concrete constraints to maintain connectedness of the larger graph. Therefore, delay their removal until after we’ve computed connected components.
…requirement sources.

When we’re determining what type should be used to key a ProtocolRequirement based on the source’s potential archetype and the target’s potential archetype, use potential archetype identity (==) rather than equivalence-class membership to cover the basis case. This ensures that interesting identity relationships in the enclosing context (e.g., the current GenericSignatureBuilder) don’t cause us to compute incorrect stored types.
…swiftlang#90, swiftlang#91.

Address ABI FIXME swiftlang#68 by using same-type constraints directly on an
associated type to describe the requirements on the Indices associated
type of the Collection protocol. ABI FIXMEs swiftlang#89, swiftlang#90, swiftlang#91 are all in
StdlibUnittest, and provoke warnings once swiftlang#68 is fixed, but it's nice
to clear them out.

Fixes SR-2121.
…onsequences of other FIXMEs.

There isn't any work related to SE-0142 associated type where clauses
for these particular ABI FIXMEs. Rather, we get all of the constraints
we need from Collection and the recursive constraint we cannot yet
express, all of which are covered by other ABI FIXMEs.
@DougGregor
Copy link
Member Author

This stops after 5 recurrences of the same associated type. It is a
gross hack and a terrible idea, here as a placeholder to prevent us
from running off the rails in ill-formed code. This will go away when
we get further along the path with recursive protocol constraints.
@DougGregor DougGregor changed the title [WIP] [Stdlib] Use associated type where clauses to address various ABI FIXMEs. [Stdlib] Use associated type where clauses to address various ABI FIXMEs. Apr 20, 2017
@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 0f4ebfd into swiftlang:master Apr 20, 2017
@@ -646,6 +646,7 @@ public protocol Collection : _Indexable, Sequence {
/// supplying `IndexingIterator` as its associated `Iterator`
/// type.
associatedtype Iterator = IndexingIterator<Self>
where Self.Iterator.Element == _Element
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we rename _Element to Element, and write Element in place of Iterator.Element everywhere? :-)

@DougGregor DougGregor deleted the stdlib-se-0142 branch April 20, 2017 13:52
@DougGregor
Copy link
Member Author

@dabrahams suggested that above... I'm going to take a shot at it

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