Skip to content

[stdlib] add missing Element type witnesses #70142

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 1 commit into from
Dec 1, 2023

Conversation

kavon
Copy link
Member

@kavon kavon commented Nov 30, 2023

With NoncopyableGenerics enabled, we currently lose some ability for associatedtype inference to find a suitable type witness based on a value witness. (rdar://118998138)

The stdlib accidentally uses that inference for Sequence.Element, due to the default witness for _customContainsEquatableElement mentioning Iterator.Element whereas the requirement only states Element.

With `NoncopyableGenerics` enabled, we currently lose some ability for
associatedtype inference to find a suitable type witness based on a
value witness. (rdar://118998138)

The stdlib accidentally uses that inference for Sequence.Element,
due to the default witness for `_customContainsEquatableElement`
mentioning `Iterator.Element` whereas the requirement only states
`Element`.
@kavon kavon requested a review from a team as a code owner November 30, 2023 23:06
Copy link
Contributor

@glessard glessard left a comment

Choose a reason for hiding this comment

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

Good find, thanks!

@glessard
Copy link
Contributor

@swift-ci please test

@kavon
Copy link
Member Author

kavon commented Nov 30, 2023

I'm fine with making these typealiases present even when NoncopyableGenerics is disabled. It should be a non-functional change.

@kavon kavon enabled auto-merge November 30, 2023 23:26
@slavapestov
Copy link
Contributor

slavapestov commented Dec 1, 2023

Can we revert this after fixing rdar://118998138? Doesn't this mean in its present state, NoncopyableGenerics could break non-stdlib code that hits this bug too?

@kavon kavon disabled auto-merge December 1, 2023 03:24
@kavon
Copy link
Member Author

kavon commented Dec 1, 2023

@swift-ci please test macOS platform

@kavon
Copy link
Member Author

kavon commented Dec 1, 2023

Can we revert this after fixing rdar://118998138 (associatedtype inference fails to check conformances correctly)?

Yes, once that associatedtype inference issue is resolved, in theory we can revert this patch. But @glessard and others have expressed a desire to make these typealiases explicit anyway, so they're going to end up becoming non-conditional in another PR. I'm just adding these in now since I'm going to rely on them soon.

Doesn't this mean in its present state, NoncopyableGenerics could break non-stdlib code that hits this bug too?

Yes. Until rdar://118998138 is fixed non-stdlib code relying on that inference is broken.

@slavapestov
Copy link
Contributor

But @glessard and others have expressed a desire to make these typealiases explicit anyway, so they're going to end up becoming non-conditional in another PR.

I think there's a good argument that this should not require an explicit type witness:

protocol P {
  associatedtype A: Q
  associatedtype B where B == A.B
}

protocol Q {
  associatedtype B
}

struct S: P {
  struct A: Q {
    typealias B = Int
  }

  // should not be needed:
  // typealias B = Int
}

@glessard
Copy link
Contributor

glessard commented Dec 1, 2023

It's fine to not require them, but the standard library can stand to be as explicit as possible.

@kavon kavon merged commit b6c7ff4 into swiftlang:main Dec 1, 2023
@kavon kavon deleted the ncgenerics-stdlib-workarounds branch December 2, 2023 05:59
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.

3 participants