The magic bit of
_openExistential is that, if you tried to write out its declaration, you’d end up with something like:
func _openExistential<Existential, Result>( _ existential: Existential, do fn: <Opened: Existential>(Opened) -> Result ) -> Result
The problem is that, although this signature might (might!) make sense to a human Swift programmer, to the compiler it is utter gibberish that doesn’t even parse correctly. Since
Existential is a generic parameter,
Opened: Existential is not valid to write, and the type of a parameter (or of any variable/value) can’t be generic anyway. And yet special cases have been hacked into the compiler to make
_openExistential behave like it has a signature like this.
(The fact that
_openExistential’s type is so weird is also why the type checker tends to say vague things like “type of expression is ambiguous without more context” instead of telling you what’s actually wrong.
_openExistential’s type checking failures look different from failures of types you can actually express in the language, and little effort has been put into polishing them.)