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
56 lines
3.8 KiB
Swift
56 lines
3.8 KiB
Swift
// RUN: %target-swift-emit-sil -parse-as-library -module-name back_deploy %s -target %target-cpu-apple-macosx10.50 -verify
|
|
// RUN: %target-swift-emit-silgen -parse-as-library -module-name back_deploy %s | %FileCheck %s
|
|
// RUN: %target-swift-emit-silgen -parse-as-library -module-name back_deploy %s -target %target-cpu-apple-macosx10.50 | %FileCheck %s
|
|
|
|
// REQUIRES: OS=macosx
|
|
|
|
public struct TopLevelStruct {
|
|
// -- Fallback definition for TopLevelStruct.property.getter
|
|
// CHECK-LABEL: sil non_abi [serialized] [ossa] @$s11back_deploy14TopLevelStructV8propertyACvgTwB : $@convention(method) (TopLevelStruct) -> TopLevelStruct
|
|
// CHECK: bb0([[SELF:%.*]] : $TopLevelStruct):
|
|
// CHECK: return [[SELF]] : $TopLevelStruct
|
|
|
|
// -- Back deployment thunk for TopLevelStruct.property.getter
|
|
// CHECK-LABEL: sil non_abi [serialized] [thunk] [ossa] @$s11back_deploy14TopLevelStructV8propertyACvgTwb : $@convention(method) (TopLevelStruct) -> TopLevelStruct
|
|
// CHECK: bb0([[BB0_ARG:%.*]] : $TopLevelStruct):
|
|
// CHECK: [[MAJOR:%.*]] = integer_literal $Builtin.Word, 10
|
|
// CHECK: [[MINOR:%.*]] = integer_literal $Builtin.Word, 52
|
|
// CHECK: [[PATCH:%.*]] = integer_literal $Builtin.Word, 0
|
|
// CHECK: [[OSVFN:%.*]] = function_ref @$ss26_stdlib_isOSVersionAtLeastyBi1_Bw_BwBwtF : $@convention(thin) (Builtin.Word, Builtin.Word, Builtin.Word) -> Builtin.Int1
|
|
// CHECK: [[AVAIL:%.*]] = apply [[OSVFN]]([[MAJOR]], [[MINOR]], [[PATCH]]) : $@convention(thin) (Builtin.Word, Builtin.Word, Builtin.Word) -> Builtin.Int1
|
|
// CHECK: cond_br [[AVAIL]], [[AVAIL_BB:bb[0-9]+]], [[UNAVAIL_BB:bb[0-9]+]]
|
|
//
|
|
// CHECK: [[UNAVAIL_BB]]:
|
|
// CHECK: [[FALLBACKFN:%.*]] = function_ref @$s11back_deploy14TopLevelStructV8propertyACvgTwB : $@convention(method) (TopLevelStruct) -> TopLevelStruct
|
|
// CHECK: [[FALLBACKRES:%.*]] = apply [[FALLBACKFN]]([[BB0_ARG]]) : $@convention(method) (TopLevelStruct) -> TopLevelStruct
|
|
// CHECK: br [[RETURN_BB:bb[0-9]+]]([[FALLBACKRES]] : $TopLevelStruct)
|
|
//
|
|
// CHECK: [[AVAIL_BB]]:
|
|
// CHECK: [[ORIGFN:%.*]] = function_ref @$s11back_deploy14TopLevelStructV8propertyACvg : $@convention(method) (TopLevelStruct) -> TopLevelStruct
|
|
// CHECK: [[ORIGRES:%.*]] = apply [[ORIGFN]]([[BB0_ARG]]) : $@convention(method) (TopLevelStruct) -> TopLevelStruct
|
|
// CHECK: br [[RETURN_BB]]([[ORIGRES]] : $TopLevelStruct)
|
|
//
|
|
// CHECK: [[RETURN_BB]]([[RETURN_BB_ARG:%.*]] : $TopLevelStruct)
|
|
// CHECK: return [[RETURN_BB_ARG]] : $TopLevelStruct
|
|
|
|
// -- Original definition of TopLevelStruct.property.getter
|
|
// CHECK-LABEL: sil [available 10.52] [ossa] @$s11back_deploy14TopLevelStructV8propertyACvg : $@convention(method) (TopLevelStruct) -> TopLevelStruct
|
|
@backDeployed(before: macOS 10.52)
|
|
public var property: TopLevelStruct { self }
|
|
}
|
|
|
|
// CHECK-LABEL: sil hidden [ossa] @$s11back_deploy6calleryyAA14TopLevelStructVF : $@convention(thin) (TopLevelStruct) -> ()
|
|
// CHECK: bb0([[STRUCT_ARG:%.*]] : $TopLevelStruct):
|
|
func caller(_ s: TopLevelStruct) {
|
|
// -- Verify the thunk is called
|
|
// CHECK: {{%.*}} = function_ref @$s11back_deploy14TopLevelStructV8propertyACvgTwb : $@convention(method) (TopLevelStruct) -> TopLevelStruct
|
|
_ = s.property
|
|
|
|
// -- Verify key path
|
|
// CHECK: {{%.*}} = keypath $KeyPath<TopLevelStruct, TopLevelStruct>, (root $TopLevelStruct; gettable_property $TopLevelStruct, id @$s11back_deploy14TopLevelStructV8propertyACvg : $@convention(method) (TopLevelStruct) -> TopLevelStruct, getter @$s11back_deploy14TopLevelStructV8propertyACvpACTK : $@convention(keypath_accessor_getter) (@in_guaranteed TopLevelStruct) -> @out TopLevelStruct)
|
|
_ = \TopLevelStruct.property
|
|
}
|
|
|
|
// CHECK-LABEL: sil shared [thunk] [ossa] @$s11back_deploy14TopLevelStructV8propertyACvpACTK : $@convention(keypath_accessor_getter) (@in_guaranteed TopLevelStruct) -> @out TopLevelStruct
|
|
// CHECK: function_ref @$s11back_deploy14TopLevelStructV8propertyACvgTwb
|