Skip to content

Commit 57f6fc2

Browse files
committed
SILGen: Add test to ensure we don't have a vtable entry for synthesized members of a final class
I believe this was fixed with swiftlang#23932. 5.1 had an inconsistency here because the synthesized declaration was not marked as final; we would sometimes check if a method itself was final, other times we would check if both the method and the class were final. Lucky it worked out so that the emitted vtable entry did not appear to ever have been used. Make sure this behavior doesn't change going forward with a test.
1 parent e7c294a commit 57f6fc2

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

test/SILGen/synthesized_conformance_class.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,34 @@ extension Nonfinal: Encodable where T: Encodable {}
6363
// CHECK-LABEL: // Nonfinal<A>.encode(to:)
6464
// CHECK-NEXT: sil hidden [ossa] @$s29synthesized_conformance_class8NonfinalCAASERzlE6encode2toys7Encoder_p_tKF : $@convention(method) <T where T : Encodable> (@in_guaranteed Encoder, @guaranteed Nonfinal<T>) -> @error Error {
6565

66+
final class FinalHashableClass : Hashable {
67+
static func ==(lhs: FinalHashableClass, rhs: FinalHashableClass) -> Bool {
68+
return false
69+
}
70+
71+
func hash(into: inout Hasher) {}
72+
}
73+
74+
// CHECK-LABEL: sil hidden [ossa] @$s29synthesized_conformance_class4doItySiAA18FinalHashableClassCF : $@convention(thin) (@guaranteed FinalHashableClass) -> Int {
75+
// CHECK: bb0(%0 : @guaranteed $FinalHashableClass):
76+
// CHECK: [[FN:%.*]] = function_ref @$s29synthesized_conformance_class18FinalHashableClassC9hashValueSivg : $@convention(method) (@guaranteed FinalHashableClass) -> Int
77+
// CHECK-NEXT: [[RESULT:%.*]] = apply [[FN]](%0) : $@convention(method) (@guaranteed FinalHashableClass) -> Int
78+
// CHECK-NEXT: return [[RESULT]] : $Int
79+
80+
func doIt(_ c: FinalHashableClass) -> Int {
81+
return c.hashValue
82+
}
83+
84+
// VTable for FinalHashableClass
85+
//
86+
// Note: we should not be emitting a vtable entry for the synthesized
87+
// FinalHashableClass.hashValue getter!
88+
89+
// CHECK: sil_vtable FinalHashableClass {
90+
// CHECK-NEXT: #FinalHashableClass.init!allocator.1: (FinalHashableClass.Type) -> () -> FinalHashableClass : @$s29synthesized_conformance_class18FinalHashableClassCACycfC
91+
// CHECK-NEXT: #FinalHashableClass.deinit!deallocator.1: @$s29synthesized_conformance_class18FinalHashableClassCfD
92+
// CHECK-NEXT: }
93+
6694
// Witness tables for Final
6795

6896
// CHECK-LABEL: sil_witness_table hidden <T where T : Encodable> Final<T>: Encodable module synthesized_conformance_class {

0 commit comments

Comments
 (0)