mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Invertible protocols are currently always mangled with `Ri`, followed by a single letter for each invertible protocol (e.g., `c` and `e` for `Copyable` and `Escapable`, respectively), followed by the generic parameter index. However, this requires that we extend the mangling for any future invertible protocols, which mean they won't be backward compatible. Replace this mangling with one that mangles the bit # for the invertible protocol, e.g., `Ri_` (followed by the generic parameter index) is bit 0, which is `Copyable`. `Ri0_` (then generic parameter index) is bit 1, which is `Escapable`. This allows us to round-trip through mangled names for any invertible protocol, without any knowledge of what the invertible protocol is, providing forward compatibility. The same forward compatibility is present in all metadata and the runtime, allowing us to add more invertible protocols in the future without updating any of them, and also allowing backward compatibility. Only the demangling to human-readable strings maps the bit numbers back to their names, and there's a fallback printing with just the bit number when appropriate. Also generalize the mangling a bit to allow for mangling of invertible requirements on associated types, e.g., `S.Sequence: ~Copyable`. This is currently unsupported by the compiler or runtime, but that may change, and it was easy enough to finish off the mangling work for it.
25 lines
1.3 KiB
Swift
25 lines
1.3 KiB
Swift
// RUN: %target-swift-emit-silgen %s | %FileCheck %s
|
|
|
|
public struct G<T> {
|
|
var t: T
|
|
|
|
public init(t: T) { self.t = t }
|
|
}
|
|
|
|
public func takesAutoclosureAndEscaping(_: @autoclosure () -> (), _: @escaping () -> ()) {}
|
|
public func takesVarargs(_: Int...) {}
|
|
|
|
public func f() {
|
|
_ = G(t: takesAutoclosureAndEscaping)
|
|
_ = G(t: takesVarargs)
|
|
}
|
|
|
|
// We shouldn't have @autoclosure and @escaping attributes in the lowered tuple type:
|
|
|
|
// CHECK-LABEL: sil shared [transparent] [serialized] [reabstraction_thunk] [ossa] @$sIg_Ieg_Ieggg_xRi_zRi0_zlyytIsgr_xRi_zRi0_zlyytIsegr_ytIegnnr_TR : $@convention(thin) (@in_guaranteed @noescape @callee_guaranteed @substituted <τ_0_0> () -> @out τ_0_0 for <()>, @in_guaranteed @callee_guaranteed @substituted <τ_0_0> () -> @out τ_0_0 for <()>, @guaranteed @callee_guaranteed (@guaranteed @noescape @callee_guaranteed () -> (), @guaranteed @callee_guaranteed () -> ()) -> ()) -> @out ()
|
|
|
|
// The one-element vararg tuple ([Int]...) should be exploded and not treated as opaque,
|
|
// even though its materializable:
|
|
|
|
// CHECK-LABEL: sil shared [transparent] [serialized] [reabstraction_thunk] [ossa] @$sSaySiGIegg_AAytIegnr_TR : $@convention(thin) (@in_guaranteed Array<Int>, @guaranteed @callee_guaranteed (@guaranteed Array<Int>) -> ()) -> @out ()
|