mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
We used to give witness thunks public linkage if the conforming type and the protocol are public. This is completely unnecessary. If the conformance is fragile, the thunk should be [shared] [serialized], allowing the thunk to be serialized into callers after devirtualization. Otherwise for private protocols or resilient modules, witness thunks can just always be private. This should reduce the size of compiled binaries. There are two other mildly interesting consequences: 1) In the bridged cast tests, we now inline the witness thunks from the bridgeable conformances, which removes one level of indirection. 2) This uncovered a flaw in our accessibility checking model. Usually, we reject a witness that is less visible than the protocol; however, we fail to reject it in the case that it comes from an extension. This is because members of an extension can be declared 'public' even if the extended type is not public, and it appears that in this case the 'public' keyword has no effect. I would prefer it if a) 'public' generated a warning here, and b) the conformance also generated a warning. In Swift 4 mode, we could then make this kind of sillyness into an error. But for now, live with the broken behavior, and add a test to exercise it to ensure we don't crash. There are other places where this "allow public but ignore it, kinda, except respect it in some places" behavior causes problems. I don't know if it was intentional or just emergent behavior from general messiness in Sema. 3) In the TBD code, there is one less 'failure' because now that witness thunks are no longer public, TBDGen does not need to reason about them (except for the case #2 above, which will probably require a similar workaround in TBDGen as what I put into SILGen).
11 lines
285 B
Swift
11 lines
285 B
Swift
// RUN: %target-swift-frontend -emit-silgen %s | %FileCheck %s
|
|
|
|
protocol Runcible {
|
|
func runce(x: Int)
|
|
}
|
|
|
|
// CHECK-LABEL: sil private [transparent] [thunk] @_T020witness_single_tuple3FooVAA8RuncibleA2aDP5runce{{[_0-9a-zA-Z]*}}FTW
|
|
struct Foo: Runcible {
|
|
func runce(x: Int = 0) {}
|
|
}
|