Skip to content

Commit aa798e2

Browse files
authored
Merge pull request #4304 from akyrtzi/prefer-typerepr-requirements-sil
[ASTPrinter] Prefer TypeReprs for printing generic requirements for SIL printing
2 parents b01c723 + 434b61f commit aa798e2

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,6 +1460,25 @@ void PrintAST::printWhereClause(ArrayRef<RequirementRepr> requirements) {
14601460
if (requirements.empty())
14611461
return;
14621462

1463+
// FIXME: Type objects do not preserve info to print requirements accurately.
1464+
// SIL printing cares about semantics so \c PrevPreferTypeRepr is false but
1465+
// we need to set it to true for printing requirements.
1466+
struct PrefTypeReprForSILRAII {
1467+
PrintOptions &Opts;
1468+
bool PrevPreferTypeRepr;
1469+
PrefTypeReprForSILRAII(PrintOptions &opts) : Opts(opts) {
1470+
if (Opts.PrintForSIL) {
1471+
PrevPreferTypeRepr = Opts.PreferTypeRepr;
1472+
Opts.PreferTypeRepr = true;
1473+
}
1474+
}
1475+
~PrefTypeReprForSILRAII() {
1476+
if (Opts.PrintForSIL) {
1477+
Opts.PreferTypeRepr = PrevPreferTypeRepr;
1478+
}
1479+
}
1480+
} PrefTypeReprForSILRAII(Options);
1481+
14631482
std::vector<std::tuple<StringRef, StringRef, RequirementReprKind>> Elements;
14641483
llvm::SmallString<64> Output;
14651484
bool Handled = true;

0 commit comments

Comments
 (0)