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
31 lines
1.9 KiB
Swift
31 lines
1.9 KiB
Swift
// RUN: %empty-directory(%t)
|
|
// RUN: %target-swift-frontend -emit-module -enable-library-evolution -emit-module-path=%t/resilient_struct.swiftmodule -module-name=resilient_struct %S/../Inputs/resilient_struct.swift
|
|
// RUN: %target-swift-frontend -emit-module -enable-library-evolution -emit-module-path=%t/resilient_class.swiftmodule -module-name=resilient_class -I %t %S/../Inputs/resilient_class.swift
|
|
|
|
// RUN: %target-swift-emit-silgen %s -I %t -enable-library-evolution | %FileCheck %s
|
|
|
|
import resilient_class
|
|
|
|
open class MySubclass<T> : ResilientOutsideParent {
|
|
public final var storedProperty: T? = nil
|
|
}
|
|
|
|
open class ConcreteSubclass : MySubclass<Int> {
|
|
public final var anotherStoredProperty: Int? = nil
|
|
}
|
|
|
|
// CHECK-LABEL: sil shared [thunk] [ossa] @$s26keypaths_resilient_generic10MySubclassC14storedPropertyxSgvplACyxGTK : $@convention(keypath_accessor_getter) <T> (@in_guaranteed MySubclass<T>) -> @out Optional<T> {
|
|
|
|
// CHECK-LABEL: sil shared [thunk] [ossa] @$s26keypaths_resilient_generic10MySubclassC14storedPropertyxSgvplACyxGTk : $@convention(keypath_accessor_setter) <T> (@in_guaranteed Optional<T>, @in_guaranteed MySubclass<T>) -> () {
|
|
|
|
// CHECK: sil_property #MySubclass.storedProperty<τ_0_0> (
|
|
// CHECK-SAME: settable_property $Optional<τ_0_0>,
|
|
// CHECK-SAME: id ##MySubclass.storedProperty,
|
|
// CHECK-SAME: getter @$s26keypaths_resilient_generic10MySubclassC14storedPropertyxSgvplACyxGTK : $@convention(keypath_accessor_getter) <τ_0_0> (@in_guaranteed MySubclass<τ_0_0>) -> @out Optional<τ_0_0>,
|
|
// CHECK-SAME: setter @$s26keypaths_resilient_generic10MySubclassC14storedPropertyxSgvplACyxGTk : $@convention(keypath_accessor_setter) <τ_0_0> (@in_guaranteed Optional<τ_0_0>, @in_guaranteed MySubclass<τ_0_0>) -> ()
|
|
// CHECK-SAME: )
|
|
|
|
// CHECK: sil_property #ConcreteSubclass.anotherStoredProperty (
|
|
// CHECK-SAME: stored_property #ConcreteSubclass.anotherStoredProperty : $Optional<Int>
|
|
// CHECK-SAME: )
|