mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +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
47 lines
6.0 KiB
Swift
47 lines
6.0 KiB
Swift
// RUN: %target-swift-emit-silgen %s | %FileCheck %s --check-prefix=CHECK --check-prefix=FRAGILE
|
|
// RUN: %target-swift-emit-silgen -enable-library-evolution %s | %FileCheck %s --check-prefix=CHECK --check-prefix=RESILIENT
|
|
|
|
// RUN: %target-swift-frontend -emit-ir %s
|
|
// RUN: %target-swift-frontend -emit-ir -enable-library-evolution %s
|
|
|
|
public struct KeypathStruct {
|
|
public var stored: Int = 0
|
|
public var computed: String { get { return "" } set { } }
|
|
|
|
public subscript(x: Int, y: String) -> Bool { get { return false } set { } }
|
|
}
|
|
|
|
// CHECK-LABEL: sil [serialized] [ossa] @$s18keypaths_inlinable11usesKeypathyyF : $@convention(thin) () -> ()
|
|
@inlinable public func usesKeypath() {
|
|
// FRAGILE: keypath $WritableKeyPath<KeypathStruct, Int>, (root $KeypathStruct; stored_property #KeypathStruct.stored : $Int)
|
|
// RESILIENT: keypath $WritableKeyPath<KeypathStruct, Int>, (root $KeypathStruct; settable_property $Int, id @$s18keypaths_inlinable13KeypathStructV6storedSivg : $@convention(method) (@in_guaranteed KeypathStruct) -> Int, getter @$s18keypaths_inlinable13KeypathStructV6storedSivpACTKq : $@convention(keypath_accessor_getter) (@in_guaranteed KeypathStruct) -> @out Int, setter @$s18keypaths_inlinable13KeypathStructV6storedSivpACTkq : $@convention(keypath_accessor_setter) (@in_guaranteed Int, @inout KeypathStruct) -> (), external #KeypathStruct.stored)
|
|
_ = \KeypathStruct.stored
|
|
|
|
// FRAGILE: keypath $WritableKeyPath<KeypathStruct, String>, (root $KeypathStruct; settable_property $String, id @$s18keypaths_inlinable13KeypathStructV8computedSSvg : $@convention(method) (KeypathStruct) -> @owned String, getter @$s18keypaths_inlinable13KeypathStructV8computedSSvpACTKq : $@convention(keypath_accessor_getter) (@in_guaranteed KeypathStruct) -> @out String, setter @$s18keypaths_inlinable13KeypathStructV8computedSSvpACTkq : $@convention(keypath_accessor_setter) (@in_guaranteed String, @inout KeypathStruct) -> ()
|
|
// RESILIENT: keypath $WritableKeyPath<KeypathStruct, String>, (root $KeypathStruct; settable_property $String, id @$s18keypaths_inlinable13KeypathStructV8computedSSvg : $@convention(method) (@in_guaranteed KeypathStruct) -> @owned String, getter @$s18keypaths_inlinable13KeypathStructV8computedSSvpACTKq : $@convention(keypath_accessor_getter) (@in_guaranteed KeypathStruct) -> @out String, setter @$s18keypaths_inlinable13KeypathStructV8computedSSvpACTkq : $@convention(keypath_accessor_setter) (@in_guaranteed String, @inout KeypathStruct) -> (), external #KeypathStruct.computed
|
|
_ = \KeypathStruct.computed
|
|
|
|
// FRAGILE: keypath $WritableKeyPath<KeypathStruct, Bool>, (root $KeypathStruct; settable_property $Bool, id @$s18keypaths_inlinable13KeypathStructVySbSi_SStcig : $@convention(method) (Int, @guaranteed String, KeypathStruct) -> Bool, getter @$s18keypaths_inlinable13KeypathStructVySbSi_SStcipACTKq : $@convention(keypath_accessor_getter) (@in_guaranteed KeypathStruct, @in_guaranteed (Int, String)) -> @out Bool, setter @$s18keypaths_inlinable13KeypathStructVySbSi_SStcipACTkq : $@convention(keypath_accessor_setter) (@in_guaranteed Bool, @inout KeypathStruct, @in_guaranteed (Int, String)) -> (), indices [%$0 : $Int : $Int, %$1 : $String : $String], indices_equals @$sSiSSTHq : $@convention(keypath_accessor_equals) (@in_guaranteed (Int, String), @in_guaranteed (Int, String)) -> Bool, indices_hash @$sSiSSThq : $@convention(keypath_accessor_hash) (@in_guaranteed (Int, String)) -> Int) ({{.*}})
|
|
// RESILIENT: keypath $WritableKeyPath<KeypathStruct, Bool>, (root $KeypathStruct; settable_property $Bool, id @$s18keypaths_inlinable13KeypathStructVySbSi_SStcig : $@convention(method) (Int, @guaranteed String, @in_guaranteed KeypathStruct) -> Bool, getter @$s18keypaths_inlinable13KeypathStructVySbSi_SStcipACTKq : $@convention(keypath_accessor_getter) (@in_guaranteed KeypathStruct, @in_guaranteed (Int, String)) -> @out Bool, setter @$s18keypaths_inlinable13KeypathStructVySbSi_SStcipACTkq : $@convention(keypath_accessor_setter) (@in_guaranteed Bool, @inout KeypathStruct, @in_guaranteed (Int, String)) -> (), indices [%$0 : $Int : $Int, %$1 : $String : $String], indices_equals @$sSiSSTHq : $@convention(keypath_accessor_equals) (@in_guaranteed (Int, String), @in_guaranteed (Int, String)) -> Bool, indices_hash @$sSiSSThq : $@convention(keypath_accessor_hash) (@in_guaranteed (Int, String)) -> Int, external #KeypathStruct.subscript) ({{.*}})
|
|
_ = \KeypathStruct[0, ""]
|
|
}
|
|
|
|
// RESILIENT-LABEL: sil shared [serialized] [thunk] [ossa] @$s18keypaths_inlinable13KeypathStructV6storedSivpACTKq : $@convention(keypath_accessor_getter) (@in_guaranteed KeypathStruct) -> @out Int
|
|
// RESILIENT: function_ref @$s18keypaths_inlinable13KeypathStructV6storedSivg
|
|
|
|
// RESILIENT-LABEL: sil shared [serialized] [thunk] [ossa] @$s18keypaths_inlinable13KeypathStructV6storedSivpACTkq : $@convention(keypath_accessor_setter) (@in_guaranteed Int, @inout KeypathStruct) -> ()
|
|
// RESILIENT: function_ref @$s18keypaths_inlinable13KeypathStructV6storedSivs
|
|
|
|
// CHECK-LABEL: sil shared [serialized] [thunk] [ossa] @$s18keypaths_inlinable13KeypathStructV8computedSSvpACTKq : $@convention(keypath_accessor_getter) (@in_guaranteed KeypathStruct) -> @out String
|
|
|
|
// CHECK-LABEL: sil shared [serialized] [thunk] [ossa] @$s18keypaths_inlinable13KeypathStructV8computedSSvpACTkq : $@convention(keypath_accessor_setter) (@in_guaranteed String, @inout KeypathStruct) -> ()
|
|
|
|
// CHECK-LABEL: sil shared [serialized] [thunk] [ossa] @$sSiSSTHq : $@convention(keypath_accessor_equals) (@in_guaranteed (Int, String), @in_guaranteed (Int, String)) -> Bool
|
|
|
|
// CHECK-LABEL: sil shared [serialized] [thunk] [ossa] @$sSiSSThq : $@convention(keypath_accessor_hash) (@in_guaranteed (Int, String)) -> Int
|
|
|
|
// CHECK-LABEL: sil shared [serialized] [thunk] [ossa] @$s18keypaths_inlinable13KeypathStructVySbSi_SStcipACTKq : $@convention(keypath_accessor_getter) (@in_guaranteed KeypathStruct, @in_guaranteed (Int, String)) -> @out Bool
|
|
|
|
// CHECK-LABEL: sil shared [serialized] [thunk] [ossa] @$s18keypaths_inlinable13KeypathStructVySbSi_SStcipACTkq : $@convention(keypath_accessor_setter) (@in_guaranteed Bool, @inout KeypathStruct, @in_guaranteed (Int, String)) -> ()
|
|
|