When devirtualizing witness method calls, it can happen that we need a cast between ABI compatible return types.
We were missing supporting type casts between nominal types which are ABI compatible.
This comes from whole-module reasoning of protocol conformances.
If a protocol only has a single conformance where the associated type (`ID`) is some concrete type (e.g. `Int`), then the devirtualizer knows that `p.get()` can only return an `Int`:
```
public struct X2<ID> {
let p: any P2<ID>
public func testit(i: ID, x: ID) -> S2<ID> {
return p.get(x: x)
}
}
```
and after devirtualizing the `get` function, its result must be cast from `Int` to `ID`.
The `layoutIsTypeDependent` utility is basically only used here to assert that this cast can only happen between layout compatible types.
rdar://129004015
Use Substitution::subst() to replace the opened existential with
the concrete type. I don't have a test case, but I think the old
code would have failed if a non-Self substitution also contained
the opened existential, which could happen after generic inlining.
Also, it looks like the guard against devirtualizing methods returning
Self is no longer necessary, because the devirtualizer can insert the
necessary casts. In any case, the check was incorrect because we now
allow calling methods on existentials that return Self as part of
another type in covariant position, such as Optional<Self> or
`() -> Self`.