Skip to content

Conversation

@CodaFi
Copy link
Contributor

@CodaFi CodaFi commented Jul 29, 2020

A recent change to witness matching in #32578 suddenly made the
following construction illegal:

// File1.swift/SomeBridgingHeader.h
enum MyEnumInAnotherFile { /**/ }

// File2.swift
extension MyEnumInAnotherFile {
  static var allCases: [MyEnumInAnotherFile] { /**/ }
}

Because it was no longer possible to derive the type witness for
AllCases. This is because, when inference ran before synthesis, we
would use the value witness to pick out the type witness and thus had no
need for synthesis. Now that we run synthesis first, we ought to just
allow deriving type witnesses across files, but still ban deriving value
witnesses. In general, if you can utter a type in a different file to
extend it, you should be able to see the requirements necessary to
derive a default type witness.

rdar://66279278, rdar://66279375, rdar://66279384, rdar://66279415, rdar://66279503, rdar://65943338

A recent change to witness matching in swiftlang#32578 suddenly made the
following construction illegal:

// File1.swift
enum MyEnumInAnotherFile { /**/ }

// File2.swift
extension MyEnumInAnotherFile {
  static var allCases: [MyEnumInAnotherFile] { /**/ }
}

Because it was no longer possible to derive the type witness for
`AllCases`. This is because, when inference ran before synthesis, we
would use the value witness to pick out the type witness and thus had no
need for synthesis. Now that we run synthesis first, we ought to just
allow deriving type witnesses across files, but still ban deriving value
witnesses. In general, if you can utter a type in a different file to
extend it, you should be able to see the requirements necessary to
derive a default type witness.

rdar://66279278, rdar://66279375, rdar://66279384, rdar://66279415, rdar://66279503
@CodaFi CodaFi requested a review from slavapestov July 29, 2020 19:13
@CodaFi
Copy link
Contributor Author

CodaFi commented Jul 29, 2020

@swift-ci smoke test

@CodaFi
Copy link
Contributor Author

CodaFi commented Jul 29, 2020

@swift-ci test source compatibility

@CodaFi
Copy link
Contributor Author

CodaFi commented Jul 29, 2020

The emission of cannot_synthesize_in_crossfile_extension now occurs once per value witness. This is unfortunate but only because of the wording of this diagnostic. We need to mention the specific value witness that we cannot synthesize here. I'll see about improving it in a follow-up commit. For now, we need to undo the source break.

@CodaFi
Copy link
Contributor Author

CodaFi commented Jul 30, 2020

@CodaFi CodaFi merged commit 5c1f76c into swiftlang:master Jul 30, 2020
@CodaFi CodaFi deleted the youre-just-my-type branch July 30, 2020 15:49
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