mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Within Swift 6.0, we expanded an optimization for witness tables that that allowed direct access to the witness table for conformances to any protocol that can never have a witness table, rather than requiring access through `swift_getWitnessTable` that might need to instantiate the witness table. The previous optimization only covered Objective-C protocols, but Swift 6.0 expanded that to marker protocols (such as `Sendable`) as well. However, this constituted an API break when a Swift 6.0 compiler uses a witness table that comes from a library built with an earlier version of Swift, when the protocol inherits from Sendable but the conformance to that protocol otherwise does not require an instantiation function. In such cases, Swift 6.0 would generate code that directly accesses the uninstantiated witness table symbol, which will have NULL entries for any conformance in it that was considered "dependent" by the earlier Swift compiler. Introduce a deployment target check to guard the new optimization. Specifically, when building for a deployment target that predates Swift 6.0, treat conformances to marker protocols as if they might be dependent (so the access patterns go through `swift_getWitnessTable` for potential instantiation on older platforms). For newer deployment targets, use the more efficent direct access pattern. Fixes rdar://133157093.
61 lines
1.2 KiB
Swift
61 lines
1.2 KiB
Swift
|
|
public protocol OtherResilientProtocol {
|
|
}
|
|
|
|
var x: Int = 0
|
|
|
|
extension OtherResilientProtocol {
|
|
public var propertyInExtension: Int {
|
|
get { return x }
|
|
set { x = newValue }
|
|
}
|
|
|
|
public static var staticPropertyInExtension: Int {
|
|
get { return x }
|
|
set { x = newValue }
|
|
}
|
|
}
|
|
|
|
public protocol ResilientBaseProtocol {
|
|
func requirement() -> Int
|
|
}
|
|
|
|
public protocol ResilientDerivedProtocol : ResilientBaseProtocol {}
|
|
|
|
public protocol ProtocolWithRequirements {
|
|
associatedtype T
|
|
func first()
|
|
func second()
|
|
}
|
|
|
|
public struct Wrapper<T>: OtherResilientProtocol { }
|
|
|
|
public struct ConcreteWrapper: OtherResilientProtocol { }
|
|
|
|
public protocol ProtocolWithAssocTypeDefaults {
|
|
associatedtype T1 = Self
|
|
associatedtype T2: OtherResilientProtocol = Wrapper<T1>
|
|
}
|
|
|
|
public protocol ResilientSelfDefault : ResilientBaseProtocol {
|
|
associatedtype AssocType: ResilientBaseProtocol = Self
|
|
}
|
|
|
|
@_fixed_layout public protocol OtherFrozenProtocol {
|
|
func protocolMethod()
|
|
}
|
|
|
|
public protocol ResilientSendableBase: Sendable {
|
|
func f()
|
|
}
|
|
|
|
public protocol ResilientSendable: ResilientSendableBase {
|
|
func g()
|
|
}
|
|
|
|
|
|
public struct ConformsToResilientSendable: ResilientSendable {
|
|
public func f() { }
|
|
public func g() { }
|
|
}
|