Skip to content

Commit 6ac2515

Browse files
authored
Merge pull request swiftlang#36331 from slavapestov/fix-retroactive-conformance-mangling
IRGen: Set the mangler's generic signature correctly
2 parents ab42dd5 + fc74fb0 commit 6ac2515

File tree

13 files changed

+58
-47
lines changed

13 files changed

+58
-47
lines changed

include/swift/AST/PrettyStackTrace.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,12 @@ class PrettyStackTraceTypeRepr : public llvm::PrettyStackTraceEntry {
167167
/// PrettyStackTraceConformance - Observe that we are processing a
168168
/// specific protocol conformance.
169169
class PrettyStackTraceConformance : public llvm::PrettyStackTraceEntry {
170-
const ASTContext &Context;
171170
const ProtocolConformance *Conformance;
172171
const char *Action;
173172
public:
174-
PrettyStackTraceConformance(const ASTContext &C, const char *action,
173+
PrettyStackTraceConformance(const char *action,
175174
const ProtocolConformance *conformance)
176-
: Context(C), Conformance(conformance), Action(action) {}
175+
: Conformance(conformance), Action(action) {}
177176
virtual void print(llvm::raw_ostream &OS) const override;
178177
};
179178

lib/AST/PrettyStackTrace.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ void PrettyStackTraceTypeRepr::print(llvm::raw_ostream &out) const {
232232

233233
void PrettyStackTraceConformance::print(llvm::raw_ostream &out) const {
234234
out << "While " << Action << ' ';
235+
auto &Context = Conformance->getDeclContext()->getASTContext();
235236
printConformanceDescription(out, Conformance, Context);
236237
}
237238

lib/ClangImporter/ImportDecl.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8539,8 +8539,7 @@ void ClangImporter::Implementation::finishNormalConformance(
85398539
(void)unused;
85408540

85418541
auto *proto = conformance->getProtocol();
8542-
PrettyStackTraceConformance trace(SwiftContext, "completing import of",
8543-
conformance);
8542+
PrettyStackTraceConformance trace("completing import of", conformance);
85448543

85458544
finishTypeWitnesses(conformance);
85468545
conformance->finishSignatureConformances();

lib/IRGen/GenProto.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2147,7 +2147,7 @@ void IRGenModule::emitSILWitnessTable(SILWitnessTable *wt) {
21472147
IRGen.ensureRelativeSymbolCollocation(*wt);
21482148

21492149
auto conf = wt->getConformance();
2150-
PrettyStackTraceConformance _st(Context, "emitting witness table for", conf);
2150+
PrettyStackTraceConformance _st("emitting witness table for", conf);
21512151

21522152
unsigned tableSize = 0;
21532153
llvm::GlobalVariable *global = nullptr;

lib/IRGen/GenReflection.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ getTypeRefImpl(IRGenModule &IGM,
308308
}
309309

310310
IRGenMangler Mangler;
311-
auto SymbolicName = Mangler.mangleTypeForReflection(IGM, type);
311+
auto SymbolicName = Mangler.mangleTypeForReflection(IGM, sig, type);
312312
return {IGM.getAddrOfStringForTypeRef(SymbolicName, role),
313313
SymbolicName.runtimeSizeInBytes()};
314314
}
@@ -628,25 +628,21 @@ class AssociatedTypeMetadataBuilder : public ReflectionMetadataBuilder {
628628
ArrayRef<std::pair<StringRef, CanType>> AssociatedTypes;
629629

630630
void layout() override {
631-
// If the conforming type is generic, we just want to emit the
632-
// unbound generic type here.
633-
auto *Nominal = Conformance->getType()->getAnyNominal();
634-
assert(Nominal && "Structural conformance?");
631+
PrettyStackTraceConformance DebugStack("emitting associated type metadata",
632+
Conformance);
635633

636-
PrettyStackTraceDecl DebugStack("emitting associated type metadata",
637-
Nominal);
638-
639-
addNominalRef(Nominal);
634+
auto *DC = Conformance->getDeclContext();
635+
addNominalRef(DC->getSelfNominalTypeDecl());
640636
addNominalRef(Conformance->getProtocol());
641637

642638
B.addInt32(AssociatedTypes.size());
643639
B.addInt32(AssociatedTypeRecordSize);
644640

641+
auto genericSig = DC->getGenericSignatureOfContext().getCanonicalSignature();
645642
for (auto AssocTy : AssociatedTypes) {
646643
auto NameGlobal = IGM.getAddrOfFieldName(AssocTy.first);
647644
B.addRelativeAddress(NameGlobal);
648-
addTypeRef(AssocTy.second,
649-
Nominal->getGenericSignature().getCanonicalSignature());
645+
addTypeRef(AssocTy.second, genericSig);
650646
}
651647
}
652648

lib/IRGen/IRGenMangler.cpp

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,10 @@ IRGenMangler::withSymbolicReferences(IRGenModule &IGM,
144144

145145
SymbolicMangling
146146
IRGenMangler::mangleTypeForReflection(IRGenModule &IGM,
147-
Type Ty) {
147+
CanGenericSignature Sig,
148+
CanType Ty) {
148149
return withSymbolicReferences(IGM, [&]{
150+
bindGenericParameters(Sig);
149151
appendType(Ty);
150152
});
151153
}
@@ -181,20 +183,6 @@ std::string IRGenMangler::mangleProtocolConformanceInstantiationCache(
181183
return finalize();
182184
}
183185

184-
SymbolicMangling
185-
IRGenMangler::mangleProtocolConformanceForReflection(IRGenModule &IGM,
186-
Type ty, ProtocolConformanceRef conformance) {
187-
return withSymbolicReferences(IGM, [&]{
188-
if (conformance.isConcrete()) {
189-
appendProtocolConformance(conformance.getConcrete());
190-
} else {
191-
// Use a special mangling for abstract conformances.
192-
appendType(ty);
193-
appendProtocolName(conformance.getAbstract());
194-
}
195-
});
196-
}
197-
198186
std::string IRGenMangler::mangleTypeForLLVMTypeName(CanType Ty) {
199187
// To make LLVM IR more readable we always add a 'T' prefix so that type names
200188
// don't start with a digit and don't need to be quoted.

lib/IRGen/IRGenMangler.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,7 @@ class IRGenMangler : public Mangle::ASTMangler {
483483
std::string mangleOutlinedCopyFunction(CanType ty,
484484
CanGenericSignature sig) {
485485
beginMangling();
486+
bindGenericParameters(sig);
486487
appendType(ty);
487488
if (sig)
488489
appendGenericSignature(sig);
@@ -492,6 +493,7 @@ class IRGenMangler : public Mangle::ASTMangler {
492493
std::string mangleOutlinedConsumeFunction(CanType ty,
493494
CanGenericSignature sig) {
494495
beginMangling();
496+
bindGenericParameters(sig);
495497
appendType(ty);
496498
if (sig)
497499
appendGenericSignature(sig);
@@ -502,6 +504,7 @@ class IRGenMangler : public Mangle::ASTMangler {
502504
std::string mangleOutlinedRetainFunction(CanType t,
503505
CanGenericSignature sig) {
504506
beginMangling();
507+
bindGenericParameters(sig);
505508
appendType(t);
506509
if (sig)
507510
appendGenericSignature(sig);
@@ -511,6 +514,7 @@ class IRGenMangler : public Mangle::ASTMangler {
511514
std::string mangleOutlinedReleaseFunction(CanType t,
512515
CanGenericSignature sig) {
513516
beginMangling();
517+
bindGenericParameters(sig);
514518
appendType(t);
515519
if (sig)
516520
appendGenericSignature(sig);
@@ -521,6 +525,7 @@ class IRGenMangler : public Mangle::ASTMangler {
521525
std::string mangleOutlinedInitializeWithTakeFunction(CanType t,
522526
CanGenericSignature sig) {
523527
beginMangling();
528+
bindGenericParameters(sig);
524529
appendType(t);
525530
if (sig)
526531
appendGenericSignature(sig);
@@ -530,6 +535,7 @@ class IRGenMangler : public Mangle::ASTMangler {
530535
std::string mangleOutlinedInitializeWithCopyFunction(CanType t,
531536
CanGenericSignature sig) {
532537
beginMangling();
538+
bindGenericParameters(sig);
533539
appendType(t);
534540
if (sig)
535541
appendGenericSignature(sig);
@@ -539,6 +545,7 @@ class IRGenMangler : public Mangle::ASTMangler {
539545
std::string mangleOutlinedAssignWithTakeFunction(CanType t,
540546
CanGenericSignature sig) {
541547
beginMangling();
548+
bindGenericParameters(sig);
542549
appendType(t);
543550
if (sig)
544551
appendGenericSignature(sig);
@@ -548,6 +555,7 @@ class IRGenMangler : public Mangle::ASTMangler {
548555
std::string mangleOutlinedAssignWithCopyFunction(CanType t,
549556
CanGenericSignature sig) {
550557
beginMangling();
558+
bindGenericParameters(sig);
551559
appendType(t);
552560
if (sig)
553561
appendGenericSignature(sig);
@@ -557,6 +565,7 @@ class IRGenMangler : public Mangle::ASTMangler {
557565
std::string mangleOutlinedDestroyFunction(CanType t,
558566
CanGenericSignature sig) {
559567
beginMangling();
568+
bindGenericParameters(sig);
560569
appendType(t);
561570
if (sig)
562571
appendGenericSignature(sig);
@@ -571,11 +580,8 @@ class IRGenMangler : public Mangle::ASTMangler {
571580
}
572581

573582
SymbolicMangling mangleTypeForReflection(IRGenModule &IGM,
574-
Type Ty);
575-
576-
SymbolicMangling mangleProtocolConformanceForReflection(IRGenModule &IGM,
577-
Type Ty,
578-
ProtocolConformanceRef conformance);
583+
CanGenericSignature genericSig,
584+
CanType Ty);
579585

580586
std::string mangleTypeForLLVMTypeName(CanType Ty);
581587

lib/SILGen/SILGenType.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -498,8 +498,7 @@ class SILGenConformance : public SILGenWitnessTable<SILGenConformance> {
498498
if (!Conformance)
499499
return nullptr;
500500

501-
PrettyStackTraceConformance trace(SGM.getASTContext(),
502-
"generating SIL witness table",
501+
PrettyStackTraceConformance trace("generating SIL witness table",
503502
Conformance);
504503

505504
auto *proto = Conformance->getProtocol();
@@ -886,8 +885,7 @@ class SILGenSelfConformanceWitnessTable
886885
}
887886

888887
void emit() {
889-
PrettyStackTraceConformance trace(SGM.getASTContext(),
890-
"generating SIL witness table",
888+
PrettyStackTraceConformance trace("generating SIL witness table",
891889
conformance);
892890

893891
// Add entries for all the requirements.

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1813,8 +1813,7 @@ static void diagnoseConformanceImpliedByConditionalConformance(
18131813
ProtocolConformance *MultiConformanceChecker::
18141814
checkIndividualConformance(NormalProtocolConformance *conformance,
18151815
bool issueFixit) {
1816-
PrettyStackTraceConformance trace(getASTContext(), "type-checking",
1817-
conformance);
1816+
PrettyStackTraceConformance trace("type-checking", conformance);
18181817

18191818
std::vector<MissingWitness> revivedMissingWitnesses;
18201819
switch (conformance->getState()) {

lib/Serialization/Deserialization.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6209,8 +6209,7 @@ void ModuleFile::finishNormalConformance(NormalProtocolConformance *conformance,
62096209
using namespace decls_block;
62106210

62116211
PrettyStackTraceModuleFile traceModule("While reading from", *this);
6212-
PrettyStackTraceConformance trace(getAssociatedModule()->getASTContext(),
6213-
"finishing conformance for",
6212+
PrettyStackTraceConformance trace("finishing conformance for",
62146213
conformance);
62156214
++NumNormalProtocolConformancesCompleted;
62166215

0 commit comments

Comments
 (0)