Is 0309 in the beta of Swift 5.5 / Xcode 13?

I thought proposal 0309 was accepted a while ago, but I am still getting the old "Protocol can only be used as a generic constraint because it has Self or associated type requirements" error when I try to use a simple protocol with associated types as a variable.

protocol P {
    associatedtype A
}

struct X {
    var p:P ///Protocol 'P' can only be used as a generic constraint because it has Self or associated type requirements
}
1 Like

Implementation isn't ready to be merged yet

1 Like

It's too late to bring it into 5.5, as the proposal was only accepted a few weeks before WWDC and the cut off to bring features into 5.5 was passed the month before. Once we merge the implementation, the feature should be available in the next major release (5.6 I presume, likely early next year).

3 Likes

Next year?

Is there a reason it couldn't be added to one of the betas later this summer?

In theory it could be, though the criteria for including changes into a release after the cut-off gets stricter as release get nearer, so as to not destabilize the release, and as a result after the cut-off only low-risk changes or critical bug fixes gets accepted, at least in my experience. The release manager has the final say into what goes into 5.5, so if they decide SE-0309 isn't a high-risk change then we can certainly get it into 5.5. In my opinion, it is better to let it settle in the main branch for a while, as it gives us more time to fix any issues that might arise due to it.

3 Likes

Understood.

I was hoping to refactor my packages to use this at the same time I refactored them to add the new concurrency stuff.

If the release manager is reading this, please consider adding this to 5.5! I have several projects which have a metric ton of extra boilerplate (or which just can't use PATs) because this is missing. I am guessing I am not the only one...

2 Likes

Is there any update on that? According to SE-0309: Unlock existential types for all protocols by theblixguy · Pull Request #33767 · apple/swift · GitHub, it has now been merged to main, but it's not yet mentioned in the ChangeLog.

1 Like

It’s only partially implemented. I think @anthonylatsis is working on the remaining bits and once that is merged we can update the change log.

3 Likes

I have been using a snapshot just to for this feature. So you can use/test it that way.

Yep. The part that landed recently enables only the use of all protocols as types. I am currently working on the second part – which comprises known associated types and covariant erasure for associated typeshere. The final part would be to allow targeting a certain property/subscript accessor when only some of the accessors are available.

8 Likes

Hello @anthonylatsis !

I am testing "swift-DEVELOPMENT-SNAPSHOT-2021-10-05-a" to see how this feature works.
Here is my test code.

struct Apple {
    let count: Int
}

protocol Store {
    associatedtype Item
    var item: Item { get set }
}

protocol AppleStore: Store where Self.Item == Apple { }

class MySevice {
    private var store: AppleStore!

    func doStuff() {
        let asd = store.item
    }
}

Good: Now the declaration of a property with AppleStore type works, unlike in any previous release versions of Swift. This got me super hyped, because this is a very highly anticipated feature for our team (in fact, any teams I have ever worked with).

Bad: Referencing any property or function of an AppleStore instance (for example: let asd = store.item) gives an error, for example:
Member 'item' cannot be used on value of protocol type 'AppleStore'; use a generic constraint instead

Are you developing a feature for Swift that makes accessing functions and properties of an AppleStore instance possible? Is there a proposal or PR we can take a look?

1 Like

Are you developing a feature for Swift that makes accessing functions and properties of an AppleStore instance possible? Is there a proposal or PR we can take a look?

All these features were proposed in SE-309 (some of them are just not implemented yet). There is also a link to the PR I am currently working on in my previous reply.

5 Likes

Thank you for the confirmation and working on this! We are eager to see this released.

1 Like

Hello @anthonylatsis,

I hope you are well! We are very much looking forward to see SE0309 in our project.
We are regularly checking the current related PR SE-0309: Covariant erasure for dependent member types by AnthonyLatsis · Pull Request #39492 · apple/swift · GitHub (this is what we know about).

We haven't seen any activity recently on it. Could you please give us an update on the topic?

Hi @zsolt.molnar,

I am waiting for some final comments on a secondary PR that I want to upstream before we resume work on the main one. I know this has been dragging on for quite a while now, but there seems to be little I can do to ginger up the review feedback routine.

2 Likes

Thank you for the update!

Hello @anthonylatsis !
I was following the github PRs of this SE0309. I am super hyped to see things are merged.
Thank you for the efforts, highly appreciated!
Are there any more PRs regarding this feature? Do you happen to have an idea which Swift version will this be released with?

1 Like

It should ship with Swift 5.7 (the next release)

4 Likes

There's one more upcoming PR for the features described in the proposal, but we're not expecting the progress there to defer the inclusion of already implemented parts in the next release (the plan is to check it off the list in time for the next release anyways).

4 Likes

Excellent news, can‘t wait! Thanks a lot.