mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Whenever we have a reference to a foreign function/variable in SIL, use a mangled name at the SIL level with the C name in the asmname attribute. The expands the use of asmname to three kinds of cases that it hadn't been used in yet: * Declarations imported from C headers/modules * @_cdecl @implementation of C headers/modules * @_cdecl functions in general Some code within the SIL pipeline makes assumptions that the C names of various runtime functions are reflected at the SIL level. For example, the linking of Embedded Swift runtime functions is done by-name, and some of those names refer to C functions (like `swift_retain`) and others refer to Swift functions that use `@_silgen_name` (like `swift_getDefaultExecutor`). Extend the serialized module format to include a table that maps from the asmname of functions/variables over to their mangled names, so we can look up functions by asmname if we want. These tables could also be used for checking for declarations that conflict on their asmname in the future. Right now, we leave it up to LLVM or the linker to do the checking. `@_silgen_name` is not affected by these changes, nor should it be: that hidden feature is specifically meant to affect the name at the SIL level. The vast majority of test changes are SIL tests where we had expected to see the C/C++/Objective-C names in the tests for references to foreign entities, and now we see Swift mangled names (ending in To). The SIL declarations themselves will have a corresponding asmname. Notably, the IRGen tests have *not* changed, because we generally the same IR as before. It's only the modeling at the SIL lever that has changed. Another part of rdar://137014448.
81 lines
4.7 KiB
Swift
81 lines
4.7 KiB
Swift
// RUN: %target-swift-emit-silgen -Xllvm -sil-print-types -module-name cf -enable-objc-interop -import-cf-types -sdk %S/Inputs %s -o - | %FileCheck %s
|
|
|
|
import CoreCooling
|
|
|
|
// CHECK: sil hidden [ossa] @$s2cf8useEmAllyySo16CCMagnetismModelCF :
|
|
// CHECK: bb0([[ARG:%.*]] : @guaranteed $CCMagnetismModel):
|
|
func useEmAll(_ model: CCMagnetismModel) {
|
|
// CHECK: function_ref @$sSo23CCPowerSupplyGetDefaultSo0aB3RefaSgyFTo : $@convention(c) () -> @autoreleased Optional<CCPowerSupply>
|
|
let power = CCPowerSupplyGetDefault()
|
|
|
|
// CHECK: function_ref @$sSo20CCRefrigeratorCreateys9UnmanagedVySo0A3RefaGSgSo013CCPowerSupplyD0aSgFTo : $@convention(c) (Optional<CCPowerSupply>) -> Optional<Unmanaged<CCRefrigerator>>
|
|
let unmanagedFridge = CCRefrigeratorCreate(power)
|
|
|
|
// CHECK: function_ref @$sSo19CCRefrigeratorSpawnySo0A3RefaSgSo013CCPowerSupplyC0aSgFTo : $@convention(c) (Optional<CCPowerSupply>) -> @owned Optional<CCRefrigerator>
|
|
let managedFridge = CCRefrigeratorSpawn(power)
|
|
|
|
// CHECK: function_ref @$sSo18CCRefrigeratorOpenyySo0A3RefaSgFTo : $@convention(c) (Optional<CCRefrigerator>) -> ()
|
|
CCRefrigeratorOpen(managedFridge)
|
|
|
|
// CHECK: function_ref @$sSo18CCRefrigeratorCopyySo0A3RefaSgADFTo : $@convention(c) (Optional<CCRefrigerator>) -> @owned Optional<CCRefrigerator>
|
|
let copy = CCRefrigeratorCopy(managedFridge)
|
|
|
|
// CHECK: function_ref @$sSo19CCRefrigeratorCloneySo0A3RefaSgADFTo : $@convention(c) (Optional<CCRefrigerator>) -> @autoreleased Optional<CCRefrigerator>
|
|
let clone = CCRefrigeratorClone(managedFridge)
|
|
|
|
// CHECK: function_ref @$sSo21CCRefrigeratorDestroyyySo0A3RefaSgFTo : $@convention(c) (@owned Optional<CCRefrigerator>) -> ()
|
|
CCRefrigeratorDestroy(clone)
|
|
|
|
// CHECK: objc_method [[ARG]] : $CCMagnetismModel, #CCMagnetismModel.refrigerator!foreign : (CCMagnetismModel) -> () -> Unmanaged<CCRefrigerator>?, $@convention(objc_method) (CCMagnetismModel) -> @unowned_inner_pointer Optional<Unmanaged<CCRefrigerator>>
|
|
let f0 = model.refrigerator()
|
|
|
|
// CHECK: objc_method [[ARG]] : $CCMagnetismModel, #CCMagnetismModel.getRefrigerator!foreign : (CCMagnetismModel) -> () -> CCRefrigerator?, $@convention(objc_method) (CCMagnetismModel) -> @autoreleased Optional<CCRefrigerator>
|
|
let f1 = model.getRefrigerator()
|
|
|
|
// CHECK: objc_method [[ARG]] : $CCMagnetismModel, #CCMagnetismModel.takeRefrigerator!foreign : (CCMagnetismModel) -> () -> CCRefrigerator?, $@convention(objc_method) (CCMagnetismModel) -> @owned Optional<CCRefrigerator>
|
|
let f2 = model.takeRefrigerator()
|
|
|
|
// CHECK: objc_method [[ARG]] : $CCMagnetismModel, #CCMagnetismModel.borrowRefrigerator!foreign : (CCMagnetismModel) -> () -> CCRefrigerator?, $@convention(objc_method) (CCMagnetismModel) -> @autoreleased Optional<CCRefrigerator>
|
|
let f3 = model.borrowRefrigerator()
|
|
|
|
// CHECK: objc_method [[ARG]] : $CCMagnetismModel, #CCMagnetismModel.setRefrigerator!foreign : (CCMagnetismModel) -> (CCRefrigerator?) -> (), $@convention(objc_method) (Optional<CCRefrigerator>, CCMagnetismModel) -> ()
|
|
model.setRefrigerator(copy)
|
|
|
|
// CHECK: objc_method [[ARG]] : $CCMagnetismModel, #CCMagnetismModel.giveRefrigerator!foreign : (CCMagnetismModel) -> (CCRefrigerator?) -> (), $@convention(objc_method) (@owned Optional<CCRefrigerator>, CCMagnetismModel) -> ()
|
|
model.giveRefrigerator(copy)
|
|
|
|
// rdar://16846555
|
|
let prop: CCRefrigerator = model.fridgeProp
|
|
}
|
|
|
|
// Ensure that accessors are emitted for fields used as protocol witnesses.
|
|
protocol Impedance {
|
|
associatedtype Component
|
|
var real: Component { get }
|
|
var imag: Component { get }
|
|
}
|
|
|
|
extension CCImpedance: Impedance {}
|
|
|
|
// CHECK-LABEL: sil private [transparent] [thunk] [ossa] @$sSo11CCImpedanceV2cf9ImpedanceA2cDP4real9ComponentQzvgTW
|
|
// CHECK-LABEL: sil shared [transparent] [serialized] [ossa] @$sSo11CCImpedanceV4realSdvg
|
|
// CHECK-LABEL: sil private [transparent] [thunk] [ossa] @$sSo11CCImpedanceV2cf9ImpedanceA2cDP4imag9ComponentQzvgTW
|
|
// CHECK-LABEL: sil shared [transparent] [serialized] [ossa] @$sSo11CCImpedanceV4imagSdvg
|
|
|
|
class MyMagnetism : CCMagnetismModel {
|
|
// CHECK-LABEL: sil private [thunk] [ossa] @$s2cf11MyMagnetismC15getRefrigerator{{[_0-9a-zA-Z]*}}FTo : $@convention(objc_method) (MyMagnetism) -> @autoreleased CCRefrigerator
|
|
override func getRefrigerator() -> CCRefrigerator {
|
|
return super.getRefrigerator()
|
|
}
|
|
|
|
// CHECK-LABEL: sil private [thunk] [ossa] @$s2cf11MyMagnetismC16takeRefrigerator{{[_0-9a-zA-Z]*}}FTo : $@convention(objc_method) (MyMagnetism) -> @owned CCRefrigerator
|
|
override func takeRefrigerator() -> CCRefrigerator {
|
|
return super.takeRefrigerator()
|
|
}
|
|
|
|
// CHECK-LABEL: sil private [thunk] [ossa] @$s2cf11MyMagnetismC18borrowRefrigerator{{[_0-9a-zA-Z]*}}FTo : $@convention(objc_method) (MyMagnetism) -> @autoreleased CCRefrigerator
|
|
override func borrowRefrigerator() -> CCRefrigerator {
|
|
return super.borrowRefrigerator()
|
|
}
|
|
}
|