Skip to content

Commit 1ee806f

Browse files
committed
SILGen: Don't emit default witness tables unless protocol is resilient
1 parent 4c99be4 commit 1ee806f

File tree

5 files changed

+5
-33
lines changed

5 files changed

+5
-33
lines changed

lib/SILGen/SILGenType.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,8 @@ class SILGenType : public TypeMemberVisitor<SILGenType> {
827827

828828
// Build a default witness table if this is a protocol.
829829
if (auto protocol = dyn_cast<ProtocolDecl>(theType)) {
830-
if (!protocol->isObjC())
830+
if (!protocol->isObjC() &&
831+
!protocol->hasFixedLayout())
831832
SGM.emitDefaultWitnessTable(protocol);
832833
return;
833834
}

lib/Sema/TypeChecker.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,8 @@ void swift::finishTypeCheckingFile(SourceFile &SF) {
678678

679679
for (auto D : SF.Decls)
680680
if (auto PD = dyn_cast<ProtocolDecl>(D))
681-
TC.inferDefaultWitnesses(PD);
681+
if (!PD->hasFixedLayout())
682+
TC.inferDefaultWitnesses(PD);
682683
}
683684

684685
void swift::performWholeModuleTypeChecking(SourceFile &SF) {

test/SILGen/protocol_resilience.swift

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -254,19 +254,6 @@ func inoutResilientProtocol(_ x: inout OtherConformingType) {
254254
inoutFunc(&OtherConformingType.staticPropertyInExtension)
255255
}
256256

257-
// Protocol is not public -- make sure default witnesses have the right linkage
258-
protocol InternalProtocol {
259-
func noDefaultF()
260-
func defaultG()
261-
}
262-
263-
extension InternalProtocol {
264-
265-
// CHECK-LABEL: sil private [transparent] [thunk] @_T019protocol_resilience16InternalProtocolP8defaultGyyF
266-
// CHECK: return
267-
func defaultG() {}
268-
}
269-
270257
// CHECK-LABEL: sil_default_witness_table P {
271258
// CHECK-NEXT: }
272259

@@ -328,8 +315,3 @@ extension InternalProtocol {
328315
// CHECK-NEXT: method #ReabstractSelfRefined.callback!setter.1: {{.*}} : @_T019protocol_resilience21ReabstractSelfRefinedP8callbackxxcvs
329316
// CHECK-NEXT: method #ReabstractSelfRefined.callback!materializeForSet.1: {{.*}} : @_T019protocol_resilience21ReabstractSelfRefinedP8callbackxxcvm
330317
// CHECK-NEXT: }
331-
332-
// CHECK-LABEL: sil_default_witness_table hidden InternalProtocol {
333-
// CHECK-NEXT: no_default
334-
// CHECK-NEXT: method #InternalProtocol.defaultG!1: {{.*}} : @_T019protocol_resilience16InternalProtocolP8defaultGyyF
335-
// CHECK-NEXT: }

test/SILGen/witness_accessibility.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ extension R {
2020

2121
public struct S : R {}
2222

23-
// CHECK-LABEL: sil private @_T021witness_accessibility1R{{.*}}AE18privateRequirementyyF
2423
// CHECK-LABEL: sil private @_T021witness_accessibility1R{{.*}}E17publicRequirementyyF
2524
// CHECK-LABEL: sil private @_T021witness_accessibility1R{{.*}}E19internalRequirementyyF
25+
// CHECK-LABEL: sil private @_T021witness_accessibility1R{{.*}}AE18privateRequirementyyF
2626

2727
// CHECK-LABEL: sil private [transparent] [thunk] @_T021witness_accessibility1SVAA1R{{.*}}dELLP18privateRequirementyyFTW
2828
// CHECK-LABEL: sil private [transparent] [thunk] @_T021witness_accessibility1SVAA1QA2aDP19internalRequirementyyFTW

test/SILOptimizer/dead_function_elimination.swift

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -216,15 +216,3 @@ internal func donotEliminate() {
216216

217217
// CHECK-TESTING-LABEL: sil_witness_table [serialized] Adopt: Prot
218218
// CHECK-TESTING: DeadWitness{{.*}}: @{{.*}}DeadWitness
219-
220-
// CHECK-LABEL: sil_default_witness_table hidden Prot
221-
// CHECK: no_default
222-
// CHECK: no_default
223-
// CHECK: method #Prot.aliveDefaultWitness!1: {{.*}} : @{{.*}}aliveDefaultWitness
224-
// CHECK: no_default
225-
226-
// CHECK-TESTING-LABEL: sil_default_witness_table Prot
227-
// CHECK-TESTING: no_default
228-
// CHECK-TESTING: no_default
229-
// CHECK-TESTING: method #Prot.aliveDefaultWitness!1: {{.*}} : @{{.*}}aliveDefaultWitness
230-
// CHECK-TESTING: method #Prot.DeadDefaultWitness!1: {{.*}} : @{{.*}}DeadDefaultWitness

0 commit comments

Comments
 (0)