Centralize KeyPath accessor calling convention logic to IRGen

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
This commit is contained in:
Yuta Saito
2022-05-15 09:23:10 +00:00
committed by Yuta Saito
parent fca24bd5c8
commit c5314bd3af
54 changed files with 1058 additions and 523 deletions

View File

@@ -4914,6 +4914,10 @@ static uint8_t getRawStableSILFunctionTypeRepresentation(
SIMPLE_CASE(SILFunctionTypeRepresentation, WitnessMethod)
SIMPLE_CASE(SILFunctionTypeRepresentation, Closure)
SIMPLE_CASE(SILFunctionTypeRepresentation, CXXMethod)
SIMPLE_CASE(SILFunctionTypeRepresentation, KeyPathAccessorGetter)
SIMPLE_CASE(SILFunctionTypeRepresentation, KeyPathAccessorSetter)
SIMPLE_CASE(SILFunctionTypeRepresentation, KeyPathAccessorEquals)
SIMPLE_CASE(SILFunctionTypeRepresentation, KeyPathAccessorHash)
}
llvm_unreachable("bad calling convention");
}