[Accepted] Amendment: SE-0364 Allow Same Package Conformances

Hi folks --

The review for an amendment to SE-0364, Allow Same Package Conformances ran from May 15 through June 17, 2024. The Language Steering Group has decided to accept the proposal.

This amendment was almost entirely uncontroversial; the only real objection came from the LSG itself, which the authors addressed by tweaking the proposal to make it so that same-package conformances are not retroactive at all. In an extended review period to consider this tweak, there was essentially no further discussion. It has taken a long time to get this proposal to completion, but I am delighted with the design that we finally landed on.

Thank you all for your feedback and patience.


Great improvement, thanks everyone!

Will this change be included in Swift 6.0?

If my understanding of this accepted proposal is correct, it seems that the following will trigger a warning:

// Local SPM package named Lib
public struct Feature {}
// Local SPM package named LibInterface 
public protocol FeatureAPI {}
// Local SPM package named LibOverlay
import Lib
import LibInterface
extension Feature: FeatureAPI {} // triggers warning

While the following will emit no warnings, as it is provided affordances given to modules found in the same SPM package:

// Package LibKit

// Target named Lib
public struct Feature {}
// Target named LibAPI
public protocol FeatureAPI {}
// Target named LibOverlay
import Lib
import LibAPI
extension Feature: FeatureAPI {} // no warnings here

Apologies if the above seems obvious from the proposal to some, I did in fact read it several times but am still uncertain related to the above.

The code above is and will continue to cause a compilation error:

'public' modifier cannot be used with extensions that declare protocol conformances

I've updated my post to remove the public modifier associated with the extension.

Still, I'm curious whether the new warnings will be emitted between local package boundaries, where we have user defined types in two different local packages and then provide protocol witnesses in a third local package.

Your understanding is correct, the @retroactive attribute will not be required in your second example where LibOverlay is part of the same package as Lib/LibAPI.

1 Like

Thanks a lot for confirming, I suspected as much but was not 100% certain.

Yes, it will be in 6: [6.0 🍒] [SE-0364] Relax @retroactive check to allow same-package declarations (#73512) by harlanhaskins · Pull Request #75079 · swiftlang/swift · GitHub