Skip to content

Commit 99993a9

Browse files
authored
Merge pull request #30859 from atrick/print-conformances
Make -emit-verbose-sil print conformances for existential insts.
2 parents 9d6ae4c + 8da6b72 commit 99993a9

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

include/swift/AST/ProtocolConformanceRef.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ class ProtocolConformanceRef {
131131
ProtocolDecl *requirement) const;
132132

133133
SWIFT_DEBUG_DUMP;
134-
void dump(llvm::raw_ostream &out, unsigned indent = 0) const;
134+
void dump(llvm::raw_ostream &out, unsigned indent = 0,
135+
bool details = true) const;
135136

136137
bool operator==(ProtocolConformanceRef other) const {
137138
return Union == other.Union;

lib/AST/ASTDumper.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3286,9 +3286,12 @@ void ProtocolConformanceRef::dump() const {
32863286
llvm::errs() << '\n';
32873287
}
32883288

3289-
void ProtocolConformanceRef::dump(llvm::raw_ostream &out,
3290-
unsigned indent) const {
3289+
void ProtocolConformanceRef::dump(llvm::raw_ostream &out, unsigned indent,
3290+
bool details) const {
32913291
llvm::SmallPtrSet<const ProtocolConformance *, 8> visited;
3292+
if (!details && isConcrete())
3293+
visited.insert(getConcrete());
3294+
32923295
dumpProtocolConformanceRefRec(*this, out, indent, visited);
32933296
}
32943297
void ProtocolConformance::dump() const {

lib/SIL/IR/SILPrinter.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,16 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
789789
return true;
790790
}
791791

792+
void printConformances(ArrayRef<ProtocolConformanceRef> conformances) {
793+
// FIXME: conformances should always be printed and parsed!
794+
if (!Ctx.printVerbose()) {
795+
return;
796+
}
797+
*this << " // ";
798+
for (ProtocolConformanceRef conformance : conformances)
799+
conformance.dump(PrintState.OS, /*indent*/ 0, /*details*/ false);
800+
}
801+
792802
void printDebugLocRef(SILLocation Loc, const SourceManager &SM,
793803
bool PrintComma = true) {
794804
auto DL = Loc.decodeDebugLoc(SM);
@@ -1797,6 +1807,7 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
17971807
*this << getIDAndType(WMI->getTypeDependentOperands()[0].get());
17981808
}
17991809
*this << " : " << WMI->getType();
1810+
printConformances({WMI->getConformance()});
18001811
}
18011812
void visitOpenExistentialAddrInst(OpenExistentialAddrInst *OI) {
18021813
if (OI->getAccessKind() == OpenedExistentialAccess::Immutable)
@@ -1823,21 +1834,26 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
18231834
void visitInitExistentialAddrInst(InitExistentialAddrInst *AEI) {
18241835
*this << getIDAndType(AEI->getOperand()) << ", $"
18251836
<< AEI->getFormalConcreteType();
1837+
printConformances(AEI->getConformances());
18261838
}
18271839
void visitInitExistentialValueInst(InitExistentialValueInst *AEI) {
18281840
*this << getIDAndType(AEI->getOperand()) << ", $"
18291841
<< AEI->getFormalConcreteType() << ", " << AEI->getType();
1842+
printConformances(AEI->getConformances());
18301843
}
18311844
void visitInitExistentialRefInst(InitExistentialRefInst *AEI) {
18321845
*this << getIDAndType(AEI->getOperand()) << " : $"
18331846
<< AEI->getFormalConcreteType() << ", " << AEI->getType();
1847+
printConformances(AEI->getConformances());
18341848
}
1835-
void visitInitExistentialMetatypeInst(InitExistentialMetatypeInst *AEI) {
1836-
*this << getIDAndType(AEI->getOperand()) << ", " << AEI->getType();
1849+
void visitInitExistentialMetatypeInst(InitExistentialMetatypeInst *EMI) {
1850+
*this << getIDAndType(EMI->getOperand()) << ", " << EMI->getType();
1851+
printConformances(EMI->getConformances());
18371852
}
18381853
void visitAllocExistentialBoxInst(AllocExistentialBoxInst *AEBI) {
18391854
*this << AEBI->getExistentialType() << ", $"
18401855
<< AEBI->getFormalConcreteType();
1856+
printConformances(AEBI->getConformances());
18411857
}
18421858
void visitDeinitExistentialAddrInst(DeinitExistentialAddrInst *DEI) {
18431859
*this << getIDAndType(DEI->getOperand());

0 commit comments

Comments
 (0)