Should using ImplicitOpenExistentials with Swift 5.10 work?

I'm a bit confused, we really can't get it to work by using enable upcoming feature flags (which works fine for other things);

It is being mentioned several times in the upcoming future features in swift-evolution/proposals/0362-piecemeal-future-features.md at main · apple/swift-evolution · GitHub

and

says

  • Upcoming Feature Flag: ImplicitOpenExistentials (Implemented in Swift 6.0) (Enabled in Swift 6 language mode)
  • Implementation: apple/swift#41996, macOS toolchain

which is a bit confusing, as it was merged into main way back in 2022 and I'd expect the upcoming feature flag to work from 5.8+ (we're on the latest 5.10)

and it turns up in the evolution overview

This feature sorts out a blocking issue for us (tried it with the Swift 6 snapshot which works great, but doesn't work for other stuff....), so we'd love to be able to turn it on.

Should this work with 5.10, or not?

1 Like

As you note, the feature (implicitly opened existentials) was implemented before upcoming feature flags in general as a feature were implemented. Taking a look through the commit history, the issue here you're encountering appears to be that, while implementation work for implicitly opened existentials was merged in 2022, the specific feature flag ImplicitOpenExistentials and the accompanying behavior change gated behind that flag were not fully implemented until recently.

So unless I'm mistaken, you'll be able to turn on this feature flag in the (default) Swift 5 language mode when using Swift 6.0, but not earlier.

1 Like

Ouch. Thanks a lot @xwu for helping decipher the tea leaves - there weee just so many references to this feature as an example going way back, but that explains then… guess we’re stuck for some time then until 6.0 :pensive:

That we did and it worked fine for our small reproducer, unfortunately we can’t build our full stack with 6.0 toolchain yet.

Hm… are you sure the upcoming feature flag is even needed? I just dropped the example code from the proposal into an empty swift file, and it compiles and runs without error with Swift 5.10. My test case:

protocol P {
    associatedtype A
    func getA() -> A
}

struct S: P {
    func getA() -> Int {
        42
    }
}

func takeP<T: P>(_ value: T) { 
    print(value.getA())
}

func test(p: any P) {
    takeP(p)  // no error here anymore!
}

let s = S()
test(p: s)

Yeah, the issue is this one:

If you see the related repro case doesn’t work with 5.10 (doesn’t compile).

1 Like

If you see the related repro case doesn’t work with 5.10 (doesn’t compile).

AFAIK the only option to compile this on 5.10 is _openExistential.

1 Like

Thanks! We’ll give that a go as a stopgap until swift 6.

1 Like