Skip to content

Commit 2950e45

Browse files
committed
SIL: representation for specialized witness tables
The main change here is to associate a witness table with a `ProtocolConformance` instead of a `RootProtocolConformance`. A `ProtocolConformance` is the base class and can be a `RootProtocolConformance` or a `SpecializedProtocolConformance`.
1 parent 46d3909 commit 2950e45

File tree

17 files changed

+47
-44
lines changed

17 files changed

+47
-44
lines changed

include/swift/AST/ASTMangler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ class ASTMangler : public Mangler {
239239
const ConstructorDecl *Derived,
240240
bool isAllocating);
241241

242-
std::string mangleWitnessTable(const RootProtocolConformance *C);
242+
std::string mangleWitnessTable(const ProtocolConformance *C);
243243

244244
std::string mangleWitnessThunk(const ProtocolConformance *Conformance,
245245
const ValueDecl *Requirement);

include/swift/IRGen/Linking.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,7 +1075,7 @@ class LinkEntity {
10751075
return entity;
10761076
}
10771077

1078-
static LinkEntity forProtocolWitnessTable(const RootProtocolConformance *C) {
1078+
static LinkEntity forProtocolWitnessTable(const ProtocolConformance *C) {
10791079
if (isEmbedded(C)) {
10801080
assert(C->getProtocol()->requiresClass());
10811081
}
@@ -1505,8 +1505,8 @@ class LinkEntity {
15051505
}
15061506

15071507
const RootProtocolConformance *getRootProtocolConformance() const {
1508-
assert(isRootProtocolConformanceKind(getKind()));
1509-
return cast<RootProtocolConformance>(getProtocolConformance());
1508+
assert(isProtocolConformanceKind(getKind()));
1509+
return getProtocolConformance()->getRootConformance();
15101510
}
15111511

15121512
const ProtocolConformance *getProtocolConformance() const {

include/swift/SIL/FormalLinkage.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace swift {
1717

1818
class CanGenericSignature;
1919
class CanType;
20-
class RootProtocolConformance;
20+
class ProtocolConformance;
2121
class ValueDecl;
2222
enum class SILLinkage : unsigned char;
2323
enum ForDefinition_t : bool;
@@ -53,7 +53,7 @@ FormalLinkage getGenericSignatureLinkage(CanGenericSignature signature);
5353
SILLinkage getSILLinkage(FormalLinkage linkage,
5454
ForDefinition_t forDefinition);
5555
SILLinkage
56-
getLinkageForProtocolConformance(const RootProtocolConformance *C,
56+
getLinkageForProtocolConformance(const ProtocolConformance *C,
5757
ForDefinition_t definition);
5858

5959
} // end swift namespace

include/swift/SIL/SILModule.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ class SILModule {
252252
VTableEntryCache;
253253

254254
/// Lookup table for SIL witness tables from conformances.
255-
llvm::DenseMap<const RootProtocolConformance *, SILWitnessTable *>
255+
llvm::DenseMap<const ProtocolConformance *, SILWitnessTable *>
256256
WitnessTableMap;
257257

258258
/// The list of SILWitnessTables in the module.

include/swift/SIL/SILWitnessTable.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ class SILWitnessTable : public llvm::ilist_node<SILWitnessTable>,
177177
SILLinkage Linkage;
178178

179179
/// The conformance mapped to this witness table.
180-
RootProtocolConformance *Conformance;
180+
ProtocolConformance *Conformance;
181181

182182
/// The various witnesses containing in this witness table. Is empty if the
183183
/// table has no witness entries or if it is a declaration.
@@ -201,33 +201,33 @@ class SILWitnessTable : public llvm::ilist_node<SILWitnessTable>,
201201

202202
/// Private constructor for making SILWitnessTable definitions.
203203
SILWitnessTable(SILModule &M, SILLinkage Linkage, SerializedKind_t Serialized,
204-
StringRef name, RootProtocolConformance *conformance,
204+
StringRef name, ProtocolConformance *conformance,
205205
ArrayRef<Entry> entries,
206206
ArrayRef<ConditionalConformance> conditionalConformances);
207207

208208
/// Private constructor for making SILWitnessTable declarations.
209209
SILWitnessTable(SILModule &M, SILLinkage Linkage, StringRef Name,
210-
RootProtocolConformance *conformance);
210+
ProtocolConformance *conformance);
211211

212212
void addWitnessTable();
213213

214214
public:
215215
/// Create a new SILWitnessTable definition with the given entries.
216216
static SILWitnessTable *
217217
create(SILModule &M, SILLinkage Linkage, SerializedKind_t SerializedKind,
218-
RootProtocolConformance *conformance, ArrayRef<Entry> entries,
218+
ProtocolConformance *conformance, ArrayRef<Entry> entries,
219219
ArrayRef<ConditionalConformance> conditionalConformances);
220220

221221
/// Create a new SILWitnessTable declaration.
222222
static SILWitnessTable *create(SILModule &M, SILLinkage Linkage,
223-
RootProtocolConformance *conformance);
223+
ProtocolConformance *conformance);
224224

225225
~SILWitnessTable();
226226

227227
SILModule &getModule() const { return Mod; }
228228

229229
/// Return the AST ProtocolConformance this witness table represents.
230-
RootProtocolConformance *getConformance() const {
230+
ProtocolConformance *getConformance() const {
231231
return Conformance;
232232
}
233233

lib/AST/ASTMangler.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,12 +249,15 @@ std::string ASTMangler::mangleConstructorVTableThunk(
249249
return finalize();
250250
}
251251

252-
std::string ASTMangler::mangleWitnessTable(const RootProtocolConformance *C) {
252+
std::string ASTMangler::mangleWitnessTable(const ProtocolConformance *C) {
253253
llvm::SaveAndRestore X(AllowInverses,
254254
inversesAllowedIn(C->getDeclContext()));
255255

256256
beginMangling();
257-
if (isa<NormalProtocolConformance>(C)) {
257+
if (auto *sc = dyn_cast<SpecializedProtocolConformance>(C)) {
258+
appendProtocolConformance(sc);
259+
appendOperator("WP");
260+
} else if (isa<NormalProtocolConformance>(C)) {
258261
appendProtocolConformance(C);
259262
appendOperator("WP");
260263
} else if (isa<SelfProtocolConformance>(C)) {

lib/IRGen/GenDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6108,7 +6108,7 @@ IRGenModule::getAddrOfWitnessTableLazyCacheVariable(
61086108
///
61096109
/// This can only be used with non-dependent conformances.
61106110
llvm::Constant*
6111-
IRGenModule::getAddrOfWitnessTable(const RootProtocolConformance *conf,
6111+
IRGenModule::getAddrOfWitnessTable(const ProtocolConformance *conf,
61126112
ConstantInit definition) {
61136113
IRGen.addLazyWitnessTable(conf);
61146114

lib/IRGen/GenProto.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,8 +1413,8 @@ class AccessorConformanceInfo : public ConformanceInfo {
14131413

14141414
WitnessTableBuilderBase(IRGenModule &IGM, SILWitnessTable *SILWT)
14151415
: IGM(IGM), SILWT(SILWT),
1416-
Conformance(*SILWT->getConformance()),
1417-
ConformanceInContext(*mapConformanceIntoContext(SILWT->getConformance())),
1416+
Conformance(*SILWT->getConformance()->getRootConformance()),
1417+
ConformanceInContext(*mapConformanceIntoContext(SILWT->getConformance()->getRootConformance())),
14181418
ConcreteType(Conformance.getDeclContext()
14191419
->mapTypeIntoContext(Conformance.getType())
14201420
->getCanonicalType()) {}
@@ -2352,7 +2352,7 @@ void IRGenerator::ensureRelativeSymbolCollocation(SILWitnessTable &wt) {
23522352

23532353
// Only resilient conformances use relative pointers for witness methods.
23542354
if (wt.isDeclaration() || isAvailableExternally(wt.getLinkage()) ||
2355-
!CurrentIGM->isResilientConformance(wt.getConformance()))
2355+
!CurrentIGM->isResilientConformance(wt.getConformance()->getRootConformance()))
23562356
return;
23572357

23582358
for (auto &entry : wt.getEntries()) {
@@ -2592,14 +2592,15 @@ void IRGenModule::emitSILWitnessTable(SILWitnessTable *wt) {
25922592
IRGen.ensureRelativeSymbolCollocation(*wt);
25932593

25942594
auto conf = wt->getConformance();
2595+
RootProtocolConformance *rootConf = conf->getRootConformance();
25952596
PrettyStackTraceConformance _st("emitting witness table for", conf);
25962597

25972598
unsigned tableSize = 0;
25982599
llvm::GlobalVariable *global = nullptr;
25992600
llvm::Function *instantiationFunction = nullptr;
2600-
bool isDependent = isDependentConformance(conf);
2601+
bool isDependent = isDependentConformance(rootConf);
26012602
SmallVector<llvm::Constant *, 4> resilientWitnesses;
2602-
bool isResilient = isResilientConformance(conf);
2603+
bool isResilient = isResilientConformance(rootConf);
26032604
bool useRelativeProtocolWitnessTable =
26042605
IRGen.Opts.UseRelativeProtocolWitnessTables;
26052606
if (useRelativeProtocolWitnessTable &&
@@ -2659,7 +2660,7 @@ void IRGenModule::emitSILWitnessTable(SILWitnessTable *wt) {
26592660
// Collect the information that will go into the protocol conformance
26602661
// descriptor.
26612662
unsigned tablePrivateSize = wt->getConditionalConformances().size();
2662-
ConformanceDescription description(conf, wt, global, tableSize,
2663+
ConformanceDescription description(rootConf, wt, global, tableSize,
26632664
tablePrivateSize, isDependent);
26642665

26652666
// Build the instantiation function, we if need one.

lib/IRGen/IRGenModule.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1837,7 +1837,7 @@ private: \
18371837
const NormalProtocolConformance *C,
18381838
CanType conformingType,
18391839
ForDefinition_t forDefinition);
1840-
llvm::Constant *getAddrOfWitnessTable(const RootProtocolConformance *C,
1840+
llvm::Constant *getAddrOfWitnessTable(const ProtocolConformance *C,
18411841
ConstantInit definition = ConstantInit());
18421842
llvm::Constant *getAddrOfWitnessTablePattern(
18431843
const NormalProtocolConformance *C,

lib/IRGen/Linking.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ std::string LinkEntity::mangleAsString() const {
347347
return mangler.mangleFieldOffset(getDecl());
348348

349349
case Kind::ProtocolWitnessTable:
350-
return mangler.mangleWitnessTable(getRootProtocolConformance());
350+
return mangler.mangleWitnessTable(getProtocolConformance());
351351

352352
case Kind::GenericProtocolWitnessTableInstantiationFunction:
353353
return mangler.mangleGenericProtocolWitnessTableInstantiationFunction(

0 commit comments

Comments
 (0)