Skip to content

Commit a3b266e

Browse files
committed
SIL: Don't create witness table declarations when creating new SIL instructions
Another simplification made possible by the change to SILModule::lookUpWitnessTable().
1 parent fef729a commit a3b266e

File tree

3 files changed

+1
-32
lines changed

3 files changed

+1
-32
lines changed

lib/SIL/SILInstructions.cpp

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -312,14 +312,6 @@ VarDecl *DebugValueAddrInst::getDecl() const {
312312
return getLoc().getAsASTNode<VarDecl>();
313313
}
314314

315-
static void declareWitnessTable(SILModule &Mod,
316-
ProtocolConformanceRef conformanceRef) {
317-
if (conformanceRef.isAbstract()) return;
318-
auto C = conformanceRef.getConcrete();
319-
if (!Mod.lookUpWitnessTable(C, false))
320-
Mod.createWitnessTableDeclaration(C);
321-
}
322-
323315
AllocExistentialBoxInst *AllocExistentialBoxInst::create(
324316
SILDebugLocation Loc, SILType ExistentialType, CanType ConcreteType,
325317
ArrayRef<ProtocolConformanceRef> Conformances,
@@ -331,8 +323,6 @@ AllocExistentialBoxInst *AllocExistentialBoxInst::create(
331323
SILModule &Mod = F->getModule();
332324
auto Size = totalSizeToAlloc<swift::Operand>(TypeDependentOperands.size());
333325
auto Buffer = Mod.allocateInst(Size, alignof(AllocExistentialBoxInst));
334-
for (ProtocolConformanceRef C : Conformances)
335-
declareWitnessTable(Mod, C);
336326
return ::new (Buffer) AllocExistentialBoxInst(Loc,
337327
ExistentialType,
338328
ConcreteType,
@@ -1631,7 +1621,6 @@ WitnessMethodInst::create(SILDebugLocation Loc, CanType LookupType,
16311621
auto Size = totalSizeToAlloc<swift::Operand>(TypeDependentOperands.size());
16321622
auto Buffer = Mod.allocateInst(Size, alignof(WitnessMethodInst));
16331623

1634-
declareWitnessTable(Mod, Conformance);
16351624
return ::new (Buffer) WitnessMethodInst(Loc, LookupType, Conformance, Member,
16361625
Ty, TypeDependentOperands);
16371626
}
@@ -1665,8 +1654,6 @@ InitExistentialAddrInst *InitExistentialAddrInst::create(
16651654
totalSizeToAlloc<swift::Operand>(1 + TypeDependentOperands.size());
16661655
void *Buffer = Mod.allocateInst(size,
16671656
alignof(InitExistentialAddrInst));
1668-
for (ProtocolConformanceRef C : Conformances)
1669-
declareWitnessTable(Mod, C);
16701657
return ::new (Buffer) InitExistentialAddrInst(Loc, Existential,
16711658
TypeDependentOperands,
16721659
ConcreteType,
@@ -1686,9 +1673,6 @@ InitExistentialValueInst *InitExistentialValueInst::create(
16861673
totalSizeToAlloc<swift::Operand>(1 + TypeDependentOperands.size());
16871674

16881675
void *Buffer = Mod.allocateInst(size, alignof(InitExistentialRefInst));
1689-
for (ProtocolConformanceRef C : Conformances)
1690-
declareWitnessTable(Mod, C);
1691-
16921676
return ::new (Buffer)
16931677
InitExistentialValueInst(Loc, ExistentialType, ConcreteType, Instance,
16941678
TypeDependentOperands, Conformances);
@@ -1709,9 +1693,6 @@ InitExistentialRefInst::create(SILDebugLocation Loc, SILType ExistentialType,
17091693

17101694
void *Buffer = Mod.allocateInst(size,
17111695
alignof(InitExistentialRefInst));
1712-
for (ProtocolConformanceRef C : Conformances)
1713-
declareWitnessTable(Mod, C);
1714-
17151696
return ::new (Buffer) InitExistentialRefInst(Loc, ExistentialType,
17161697
ConcreteType,
17171698
Instance,
@@ -1744,9 +1725,6 @@ InitExistentialMetatypeInst *InitExistentialMetatypeInst::create(
17441725
1 + TypeDependentOperands.size(), conformances.size());
17451726

17461727
void *buffer = M.allocateInst(size, alignof(InitExistentialMetatypeInst));
1747-
for (ProtocolConformanceRef conformance : conformances)
1748-
declareWitnessTable(M, conformance);
1749-
17501728
return ::new (buffer) InitExistentialMetatypeInst(
17511729
Loc, existentialMetatypeType, metatype,
17521730
TypeDependentOperands, conformances);

lib/SIL/SILVerifier.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2493,8 +2493,6 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
24932493
auto conformance = AMI->getConformance().getConcrete();
24942494
require(conformance->getType()->isEqual(AMI->getLookupType()),
24952495
"concrete type lookup requires conformance that matches type");
2496-
require(AMI->getModule().lookUpWitnessTable(conformance, false),
2497-
"Could not find witness table for conformance");
24982496
}
24992497

25002498
require(AMI->getMember().requiresNewWitnessTableEntry(),
@@ -3204,13 +3202,6 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
32043202
require(conformances[i].getRequirement() == protocols[i]->getDecl(),
32053203
"init_existential instruction must have conformances in "
32063204
"proper order");
3207-
3208-
if (conformances[i].isConcrete()) {
3209-
auto conformance = conformances[i].getConcrete();
3210-
require(F.getModule().lookUpWitnessTable(conformance, false),
3211-
"Could not find witness table for conformance.");
3212-
3213-
}
32143205
}
32153206
}
32163207

test/SILOptimizer/dead_witness_module.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ import TestModule
1212

1313
testit(MyStruct())
1414

15-
// CHECK: sil_witness_table MyStruct: Proto module TestModule{{$}}
15+
// CHECK-NOT: sil_witness_table MyStruct: Proto module TestModule

0 commit comments

Comments
 (0)