Skip to content

Commit 2745565

Browse files
committed
Swift SIL: correctly bridge "invalid" witness table entries.
Originally, I thought that couldn't appear in valid SIL, but there are "no_default" entries in default witness tables, which map to "invalid" entries.
1 parent e090bc4 commit 2745565

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

SwiftCompilerSources/Sources/SIL/WitnessTable.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public struct WitnessTable : CustomStringConvertible, CustomReflectable {
2121
fileprivate let bridged: BridgedWitnessTableEntry
2222

2323
public enum Kind {
24+
case invalid
2425
case method
2526
case associatedType
2627
case associatedTypeProtocol
@@ -29,6 +30,7 @@ public struct WitnessTable : CustomStringConvertible, CustomReflectable {
2930

3031
public var kind: Kind {
3132
switch SILWitnessTableEntry_getKind(bridged) {
33+
case SILWitnessTableEntry_Invalid: return .invalid
3234
case SILWitnessTableEntry_Method: return .method
3335
case SILWitnessTableEntry_AssociatedType: return .associatedType
3436
case SILWitnessTableEntry_AssociatedTypeProtocol: return .associatedTypeProtocol

include/swift/SIL/SILBridging.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ typedef struct {
9999
} BridgedWitnessTableEntry;
100100

101101
typedef enum {
102+
SILWitnessTableEntry_Invalid,
102103
SILWitnessTableEntry_Method,
103104
SILWitnessTableEntry_AssociatedType,
104105
SILWitnessTableEntry_AssociatedTypeProtocol,

lib/SIL/Utils/SILBridging.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,8 @@ std::string SILWitnessTableEntry_debugDescription(BridgedWitnessTableEntry entry
625625

626626
SILWitnessTableEntryKind SILWitnessTableEntry_getKind(BridgedWitnessTableEntry entry) {
627627
switch (castToWitnessTableEntry(entry)->getKind()) {
628+
case SILWitnessTable::Invalid:
629+
return SILWitnessTableEntry_Invalid;
628630
case SILWitnessTable::Method:
629631
return SILWitnessTableEntry_Method;
630632
case SILWitnessTable::AssociatedType:
@@ -633,8 +635,6 @@ SILWitnessTableEntryKind SILWitnessTableEntry_getKind(BridgedWitnessTableEntry e
633635
return SILWitnessTableEntry_AssociatedTypeProtocol;
634636
case SILWitnessTable::BaseProtocol:
635637
return SILWitnessTableEntry_BaseProtocol;
636-
default:
637-
llvm_unreachable("wrong witness table entry kind");
638638
}
639639
}
640640

test/SILOptimizer/function_uses.sil

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,26 @@ sil_default_witness_table RP {
153153
method #RP.default_witness: @default_witness
154154
}
155155

156+
public protocol RP2 {
157+
}
158+
159+
sil_default_witness_table RP2 {
160+
no_default
161+
}
162+
156163
protocol P {
157164
func witness()
165+
func witness2()
158166
}
159167

160168
struct SP : P {
161169
func witness()
170+
func witness2()
171+
}
172+
173+
struct SP2 : P {
174+
func witness()
175+
func witness2()
162176
}
163177

164178
// CHECK-LABEL: Uses of witness
@@ -172,8 +186,20 @@ bb0(%0 : $*SP):
172186
return %7 : $()
173187
}
174188

189+
sil @witness2 : $@convention(witness_method: P) (@inout SP) -> () {
190+
bb0(%0 : $*SP):
191+
%7 = tuple ()
192+
return %7 : $()
193+
}
194+
175195
sil_witness_table SP: P module witness_tables {
176196
method #P.witness: @witness
197+
method #P.witness2: @witness2
198+
}
199+
200+
sil_witness_table SP2: P module witness_tables {
201+
method #P.witness: @witness
202+
method #P.witness2: @witness2
177203
}
178204

179205
// CHECK-LABEL: Uses of hash_func

0 commit comments

Comments
 (0)