Hello, given the following code
protocol Service: Sendable {}
struct Impl: Service {}
struct AView: View {
private let service: any Service
init(service: any Service) {
self.service = service
}
var body: some View {
genericView(service: service)
}
func genericView(service: some Service) -> some View {
EmptyView()
}
}
The body fails to compile with the Type 'any View' cannot conform to 'View'
error.
But, if I change the genericView
function to take an any Service
instead, it successfully compiles.
I've looked at the generated SIL, and the method signature looks like this:
sil hidden [ossa] @$s12SILInspector5AViewV11genericView7serviceQrx_tAA7ServiceRzlF : $@convention(method) <τ_0_0 where τ_0_0 : Service> (@in_guaranteed τ_0_0, @in_guaranteed AView) -> @out @_opaqueReturnTypeOf("$s12SILInspector5AViewV11genericView7serviceQrx_tAA7ServiceRzlF", 0) __<τ_0_0>
whereas when the argument is an existential container, it looks like this :
sil hidden [ossa] @$s12SILInspector5AViewV11genericView7serviceQrAA7Service_p_tF : $@convention(method) (@in_guaranteed any Service, @in_guaranteed AView) -> @out @_opaqueReturnTypeOf("$s12SILInspector5AViewV11genericView7serviceQrAA7Service_p_tF", 0) __
The only difference I mainly see is that the some variant has the generic argument specified at the end (__<τ_0_0>
) vs only __
on the existential one.
Can anyone explain what's actually happening?