mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
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
60 lines
2.2 KiB
Plaintext
60 lines
2.2 KiB
Plaintext
// RUN: %target-swift-frontend -emit-ir %s | %FileCheck %s -DINT=i%target-ptrsize
|
|
|
|
sil_stage canonical
|
|
import Swift
|
|
|
|
public struct Blah {
|
|
public subscript<T>(x: T) -> Int { get set }
|
|
public subscript<T>(x: T, y: T) -> Int { get set }
|
|
public subscript<T, U>(x: T, y: U) -> Int { get set }
|
|
}
|
|
|
|
// CHECK: define{{.*}} swiftcc void @"$simple_getter"(
|
|
// CHECK-SAME: ptr{{.*}} sret(%TSi) %0,
|
|
// CHECK-SAME: ptr{{.*}} %1,
|
|
// CHECK-SAME: ptr{{.*}} %2, [[INT]] %3)
|
|
sil @$simple_getter : $@convention(keypath_accessor_getter) (@in_guaranteed Blah) -> @out Int {
|
|
bb0(%0 : $*Int, %1 : $*Blah):
|
|
unreachable
|
|
}
|
|
|
|
// CHECK: define{{.*}} swiftcc void @"$generic_indices_getter"(
|
|
// CHECK-SAME: ptr{{.*}} {{.*}} %0,
|
|
// CHECK-SAME: ptr{{.*}} %1,
|
|
// %2 = the key path component buffer pointer and %3 is the size
|
|
// CHECK-SAME: ptr{{.*}} %2, [[INT]] %3)
|
|
sil @$generic_indices_getter : $@convention(keypath_accessor_getter) <T where T : Hashable> (@in_guaranteed Blah, @in_guaranteed (_: T)) -> @out Int {
|
|
bb0(%0 : $*Int, %1 : $*Blah, %2 : $*(_: T)):
|
|
unreachable
|
|
}
|
|
|
|
|
|
|
|
// CHECK: define{{.*}} swiftcc void @"$generic_indices_setter"(
|
|
// CHECK-SAME: ptr{{.*}} %0,
|
|
// CHECK-SAME: ptr{{.*}} %1,
|
|
// %2 = the key path component buffer pointer and %3 is the size
|
|
// CHECK-SAME: ptr{{.*}} %2, [[INT]] %3)
|
|
sil @$generic_indices_setter : $@convention(keypath_accessor_setter) <T where T : Hashable> (@in_guaranteed Int, @inout Blah, @in_guaranteed (_: T)) -> () {
|
|
bb0(%0 : $*Int, %1 : $*Blah, %2 : $*(_: T)):
|
|
unreachable
|
|
}
|
|
|
|
// CHECK: define{{.*}} swiftcc [[INT]] @"$generic_indices_hash"(
|
|
// %0 = the key path component buffer pointer and %1 is the size
|
|
// CHECK-SAME: ptr{{.*}} %0, [[INT]] %1)
|
|
sil @$generic_indices_hash : $@convention(keypath_accessor_hash) <T where T : Hashable> (@in_guaranteed (_: T)) -> Int {
|
|
bb0(%0 : $*(_: T)):
|
|
unreachable
|
|
}
|
|
|
|
// CHECK: define{{.*}} swiftcc i1 @"$generic_indices_equals"(
|
|
// %0 = LHS of key path component buffer pointer
|
|
// %1 = RHS of key path component buffer pointer
|
|
// %2 = the size of the key path component buffers
|
|
// CHECK-SAME: ptr{{.*}} %0, ptr{{.*}} %1, [[INT]] %2)
|
|
sil @$generic_indices_equals : $@convention(keypath_accessor_equals) <T where T : Hashable> (@in_guaranteed (_: T), @in_guaranteed (_: T)) -> Bool {
|
|
bb0(%0 : $*(_: T), %1 : $*(_: T)):
|
|
unreachable
|
|
}
|