KeyPath's getter/setter/hash/equals functions have their own calling
convention, which receives generic arguments and embedded indices from a
given KeyPath argument buffer.
The convention was previously implemented by:
1. Accepting an argument buffer as an UnsafeRawPointer and casting it to
indices tuple pointer in SIL.
2. Bind generic arguments info from the given argument buffer while emitting
prologue in IRGen by creating a new forwarding thunk.
This 2-phase lowering approach was not ideal, as it blocked KeyPath
projection optimization [^1], and also required having a target arch
specific signature lowering logic in SIL-level [^2].
This patch centralizes the KeyPath accessor calling convention logic to
IRGen, by introducing `@convention(keypath_accessor_XXX)` convention in
SIL and lowering it in IRGen. This change unblocks the KeyPath projection
optimization while capturing subscript indices, and also makes it easier
to support WebAssembly target.
[^1]: https://github.com/apple/swift/pull/28799
[^2]: https://forums.swift.org/t/wasm-support/16087/21
`readonly` (instead of `readnone`) because we want there to be a memory control
dependence on potential preceeding availability checks.
`willreturn` such that LLVM can remove calls without a use.
KeyPath thunk helpers are called from stdlib indirectly through
descriptor and its calling-convention in the caller side is SwiftCC.
However, the definition side expects C calling-convention, so they
can be broken on some architectures, that SwiftCC is not compatible
with C-CC on it.
This patch changes to use SwiftCC consistently on caller side and
definition side.
This doesn't have any effect on the ABI stable platforms because
SwiftCC is compatible with C-CC on them.
several more places to use getOrCreateHelperFunction.
This means that several of these places are now emitting
shared functions rather than private ones, which I've
verified is okay. There are some other places where
privacy is still unfortunately necessary.
I've also fixed the name of the store-extra-inhabitants
helper function to say "store" instead of "get", which
is longstanding (but harmless because it's private).
Fixes rdar://66707994.