Skip to content

[Associated type inference] Allow _Default_Foo typealias guides for inference. #13567

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

Conversation

DougGregor
Copy link
Member

@DougGregor DougGregor commented Dec 21, 2017

Introduce an ugly hack where a typealias in a protocol extension that has the name _Default_Foo can be found by associated type inference for an associated type named Foo, respecting the constrains of the protocol extension in which that typealias resides.

Use this new machinery to define a conditional default type witness for the collection Indices associated type, so Indices becomes CountableRange<Index> when the Index type is
Strideable with Int as its Stride type.

This fixes the major regression with associated type inference for “minimal” random access collection types with Int index types, which has come up in a number of places.

Fixes rdar://problem/35035322 / SR-6620

@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor
Copy link
Member Author

@swift-ci please test source compatibility

@DougGregor
Copy link
Member Author

UPASS is the best failure :)

Introduce an ugly hack where a typealias in a protocol extension that
has the name `_Default_Foo` can be found by associated type inference for
an associated type named `Foo`, respecting the constrains of the protocol
extension in which that typealias resides.
…nly.

Factor out the two places where we were introducing a “tentative type
witness” function within associated type inference. Then, extend this
checking to allow us to use type witnesses from the known conformance
even when we’re looking into an inherited conformance. This improves our
ability to perform substitutions on the inferred-but-not-yet-committed
type witnesses.
Use the new `_Default_Foo` typealias trickery to define a conditional
default type witness for the collection `Indices` associated type, so
`Indices` becomes `CountableRange<Index>` when the `Index` type is
`Strideable` with `Int` as its `Stride` type.

This fixes the major regression with associated type inference for
“minimal” random access collection types with `Int` index types, which
has come up in a number of places.

Note that I dropped the `@_implements` requirement because `_Default_Foo`
is already off in its own namespace, and eventually we should get a real
syntax for this.

Fixes rdar://problem/35035322.
NFC to reduce the size of the “find solutions” function.
@DougGregor DougGregor force-pushed the assoc-type-infer-conditional-defaults branch from 1f327ae to 5494a1f Compare December 21, 2017 07:12
@DougGregor
Copy link
Member Author

@swift-ci please test and merge

1 similar comment
@DougGregor
Copy link
Member Author

@swift-ci please test and merge

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.

2 participants