Skip to content

Commit e64241c

Browse files
authored
Merge pull request #84426 from hamishknight/wallsocket
2 parents 90a5a0f + 0bfbe98 commit e64241c

32 files changed

+166
-204
lines changed

include/swift/AST/PrintOptions.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,13 @@ struct PrintOptions {
694694
return result;
695695
}
696696

697+
/// Print options suitable for debug printing.
698+
static PrintOptions forDebugging() {
699+
PrintOptions result;
700+
result.PrintTypesForDebugging = true;
701+
return result;
702+
}
703+
697704
/// Retrieve the set of options suitable for diagnostics printing.
698705
static PrintOptions printForDiagnostics(AccessLevel accessFilter,
699706
bool printFullConvention) {

include/swift/IDE/Utils.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,8 @@ struct ResolvedRangeInfo {
402402
/*Single entry*/true, /*UnhandledEffects*/{},
403403
OrphanKind::None, {}, {}, {}) {}
404404
ResolvedRangeInfo(): ResolvedRangeInfo(ArrayRef<Token>()) {}
405-
void print(llvm::raw_ostream &OS) const;
405+
void print(llvm::raw_ostream &OS,
406+
const PrintOptions &PO = PrintOptions()) const;
406407
ExitState exit() const { return ExitInfo.Exit; }
407408
Type getType() const { return ExitInfo.ReturnType; }
408409

include/swift/Sema/ConstraintSystem.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6223,8 +6223,7 @@ class TypeVariableBinding {
62236223
fixForHole(ConstraintSystem &cs) const;
62246224

62256225
void print(llvm::raw_ostream &Out, SourceManager *, unsigned indent) const {
6226-
PrintOptions PO;
6227-
PO.PrintTypesForDebugging = true;
6226+
PrintOptions PO = PrintOptions::forDebugging();
62286227
Out << "type variable binding " << TypeVar->getString(PO)
62296228
<< " := " << Binding.BindingType->getString(PO);
62306229
}

lib/AST/ASTDumper.cpp

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3398,13 +3398,11 @@ class PrintExpr : public ExprVisitor<PrintExpr, void, Label>,
33983398
/// FIXME: This should use ExprWalker to print children.
33993399

34003400
void printCommon(Expr *E, const char *C, Label label) {
3401-
PrintOptions PO;
3402-
PO.PrintTypesForDebugging = true;
3403-
34043401
printHead(C, ExprColor, label);
34053402

34063403
printFlag(E->isImplicit(), "implicit", ExprModifierColor);
3407-
printTypeField(GetTypeOfExpr(E), Label::always("type"), PO, TypeColor);
3404+
printTypeField(GetTypeOfExpr(E), Label::always("type"),
3405+
PrintOptions::forDebugging(), TypeColor);
34083406

34093407
// If we have a source range and an ASTContext, print the source range.
34103408
if (auto Ty = GetTypeOfExpr(E)) {
@@ -4054,10 +4052,8 @@ class PrintExpr : public ExprVisitor<PrintExpr, void, Label>,
40544052
void visitForceTryExpr(ForceTryExpr *E, Label label) {
40554053
printCommon(E, "force_try_expr", label);
40564054

4057-
PrintOptions PO;
4058-
PO.PrintTypesForDebugging = true;
4059-
printTypeField(E->getThrownError(), Label::always("thrown_error"), PO,
4060-
TypeColor);
4055+
printTypeField(E->getThrownError(), Label::always("thrown_error"),
4056+
PrintOptions::forDebugging(), TypeColor);
40614057

40624058
printRec(E->getSubExpr(), Label::optional("sub_expr"));
40634059
printFoot();
@@ -4066,10 +4062,8 @@ class PrintExpr : public ExprVisitor<PrintExpr, void, Label>,
40664062
void visitOptionalTryExpr(OptionalTryExpr *E, Label label) {
40674063
printCommon(E, "optional_try_expr", label);
40684064

4069-
PrintOptions PO;
4070-
PO.PrintTypesForDebugging = true;
4071-
printTypeField(E->getThrownError(), Label::always("thrown_error"), PO,
4072-
TypeColor);
4065+
printTypeField(E->getThrownError(), Label::always("thrown_error"),
4066+
PrintOptions::forDebugging(), TypeColor);
40734067

40744068
printRec(E->getSubExpr(), Label::optional("sub_expr"));
40754069
printFoot();
@@ -4553,10 +4547,8 @@ class PrintExpr : public ExprVisitor<PrintExpr, void, Label>,
45534547
void visitTypeValueExpr(TypeValueExpr *E, Label label) {
45544548
printCommon(E, "type_value_expr", label);
45554549

4556-
PrintOptions PO;
4557-
PO.PrintTypesForDebugging = true;
4558-
printTypeField(E->getParamType(), Label::always("param_type"), PO,
4559-
TypeColor);
4550+
printTypeField(E->getParamType(), Label::always("param_type"),
4551+
PrintOptions::forDebugging(), TypeColor);
45604552

45614553
printFoot();
45624554
}
@@ -6828,7 +6820,7 @@ void RequirementRepr::dump() const {
68286820
}
68296821

68306822
void GenericParamList::dump() const {
6831-
print(llvm::errs());
6823+
print(llvm::errs(), PrintOptions::forDebugging());
68326824
llvm::errs() << '\n';
68336825
}
68346826

@@ -6837,11 +6829,11 @@ void LayoutConstraint::dump() const {
68376829
llvm::errs() << "(null)\n";
68386830
return;
68396831
}
6840-
getPointer()->print(llvm::errs());
6832+
getPointer()->print(llvm::errs(), PrintOptions::forDebugging());
68416833
}
68426834

68436835
void GenericSignature::dump() const {
6844-
print(llvm::errs());
6836+
print(llvm::errs(), PrintOptions::forDebugging());
68456837
llvm::errs() << '\n';
68466838
}
68476839

@@ -6876,7 +6868,7 @@ void InheritedEntry::dump(llvm::raw_ostream &os) const {
68766868
os << '@' << getDumpString(getExplicitSafety()) << ' ';
68776869
if (isSuppressed())
68786870
os << "~";
6879-
getType().print(os);
6871+
getType().print(os, PrintOptions::forDebugging());
68806872
}
68816873

68826874
void InheritedEntry::dump() const { dump(llvm::errs()); }

lib/AST/ASTPrinter.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6198,9 +6198,11 @@ class TypePrinter : public TypeVisitor<TypePrinter, void, NonRecursivePrintOptio
61986198
if (Options.PrintTypesForDebugging || Options.PrintInSILBody)
61996199
Printer << "@error_type ";
62006200
visit(originalType);
6201-
}
6202-
else
6201+
} else if (Options.PrintTypesForDebugging) {
62036202
Printer << "<<error type>>";
6203+
} else {
6204+
Printer << "_";
6205+
}
62046206
}
62056207

62066208
void visitUnresolvedType(UnresolvedType *T,

lib/IDE/SwiftSourceDocInfo.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ void XMLEscapingPrinter::printXML(StringRef Text) {
7070
OS << Text;
7171
}
7272

73-
void ResolvedRangeInfo::print(llvm::raw_ostream &OS) const {
73+
void ResolvedRangeInfo::print(llvm::raw_ostream &OS,
74+
const PrintOptions &PO) const {
7475
OS << "<Kind>";
7576
switch (Kind) {
7677
case RangeKind::SingleExpression: OS << "SingleExpression"; break;
@@ -87,7 +88,7 @@ void ResolvedRangeInfo::print(llvm::raw_ostream &OS) const {
8788

8889
if (auto Ty = getType()) {
8990
OS << "<Type>";
90-
Ty->print(OS);
91+
Ty->print(OS, PO);
9192
OS << "</Type>";
9293
switch(exit()) {
9394
case ExitState::Positive: OS << "<Exit>true</Exit>"; break;
@@ -147,7 +148,7 @@ void ResolvedRangeInfo::print(llvm::raw_ostream &OS) const {
147148
for (auto &RD : ReferencedDecls) {
148149
OS << "<Referenced>" << RD.VD->getBaseName() << "</Referenced>";
149150
OS << "<Type>";
150-
RD.Ty->print(OS);
151+
RD.Ty->print(OS, PO);
151152
OS << "</Type>\n";
152153
}
153154

lib/Sema/CSBindings.cpp

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2174,13 +2174,8 @@ void PotentialBindings::reset() {
21742174
AssociatedCodeCompletionToken = ASTNode();
21752175
}
21762176

2177-
void PotentialBindings::dump(ConstraintSystem &cs,
2178-
TypeVariableType *typeVar,
2179-
llvm::raw_ostream &out,
2180-
unsigned indent) const {
2181-
PrintOptions PO;
2182-
PO.PrintTypesForDebugging = true;
2183-
2177+
void PotentialBindings::dump(ConstraintSystem &cs, TypeVariableType *typeVar,
2178+
llvm::raw_ostream &out, unsigned indent) const {
21842179
out << "Potential bindings for ";
21852180
typeVar->getImpl().print(out);
21862181
out << "\n";
@@ -2202,16 +2197,17 @@ void PotentialBindings::dump(ConstraintSystem &cs,
22022197
[](auto lhs, auto rhs) {
22032198
return lhs.first->getID() < rhs.first->getID();
22042199
});
2205-
interleave(adjacentVars,
2206-
[&](std::pair<TypeVariableType *, Constraint *> pair) {
2207-
out << pair.first->getString(PO);
2208-
if (pair.first->getImpl().getFixedType(/*record=*/nullptr))
2209-
out << " (fixed)";
2210-
out << " via ";
2211-
pair.second->print(out, &cs.getASTContext().SourceMgr, indent,
2212-
/*skipLocator=*/true);
2213-
},
2214-
[&out]() { out << ", "; });
2200+
interleave(
2201+
adjacentVars,
2202+
[&](std::pair<TypeVariableType *, Constraint *> pair) {
2203+
out << pair.first->getString(PrintOptions::forDebugging());
2204+
if (pair.first->getImpl().getFixedType(/*record=*/nullptr))
2205+
out << " (fixed)";
2206+
out << " via ";
2207+
pair.second->print(out, &cs.getASTContext().SourceMgr, indent,
2208+
/*skipLocator=*/true);
2209+
},
2210+
[&out]() { out << ", "; });
22152211
out << "] ";
22162212
}
22172213
}
@@ -2295,8 +2291,7 @@ static std::string getCollectionLiteralAsString(KnownProtocolKind KPK) {
22952291
}
22962292

22972293
void BindingSet::dump(llvm::raw_ostream &out, unsigned indent) const {
2298-
PrintOptions PO;
2299-
PO.PrintTypesForDebugging = true;
2294+
PrintOptions PO = PrintOptions::forDebugging();
23002295

23012296
if (auto typeVar = getTypeVariable()) {
23022297
typeVar->getImpl().print(out);
@@ -2991,8 +2986,7 @@ bool TypeVariableBinding::attempt(ConstraintSystem &cs) const {
29912986

29922987
if (result.isFailure()) {
29932988
if (cs.isDebugMode()) {
2994-
PrintOptions PO;
2995-
PO.PrintTypesForDebugging = true;
2989+
PrintOptions PO = PrintOptions::forDebugging();
29962990

29972991
llvm::errs().indent(cs.solverState->getCurrentIndent())
29982992
<< "(failed to establish binding " << TypeVar->getString(PO)

lib/Sema/CSOptimizer.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1738,13 +1738,11 @@ static void determineBestChoicesInContext(
17381738
});
17391739

17401740
if (cs.isDebugMode()) {
1741-
PrintOptions PO;
1742-
PO.PrintTypesForDebugging = true;
17431741

17441742
llvm::errs().indent(cs.solverState->getCurrentIndent())
17451743
<< "<<< Disjunction "
17461744
<< disjunction->getNestedConstraints()[0]->getFirstType()->getString(
1747-
PO)
1745+
PrintOptions::forDebugging())
17481746
<< " with score " << bestScore << "\n";
17491747
}
17501748

@@ -1774,8 +1772,7 @@ static void determineBestChoicesInContext(
17741772
}
17751773

17761774
if (cs.isDebugMode() && bestOverallScore > 0) {
1777-
PrintOptions PO;
1778-
PO.PrintTypesForDebugging = true;
1775+
PrintOptions PO = PrintOptions::forDebugging();
17791776

17801777
auto getLogger = [&](unsigned extraIndent = 0) -> llvm::raw_ostream & {
17811778
return llvm::errs().indent(cs.solverState->getCurrentIndent() +

lib/Sema/CSSimplify.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13439,12 +13439,9 @@ bool ConstraintSystem::simplifyAppliedOverloadsImpl(
1343913439
// If we have a common result type, bind the expected result type to it.
1344013440
if (commonResultType && !commonResultType->is<ErrorType>()) {
1344113441
if (isDebugMode()) {
13442-
PrintOptions PO;
13443-
PO.PrintTypesForDebugging = true;
1344413442
llvm::errs().indent(solverState ? solverState->getCurrentIndent() : 0)
13445-
<< "(common result type for $T" << fnTypeVar->getID() << " is "
13446-
<< commonResultType.getString(PO)
13447-
<< ")\n";
13443+
<< "(common result type for $T" << fnTypeVar->getID() << " is "
13444+
<< commonResultType.getString(PrintOptions::forDebugging()) << ")\n";
1344813445
}
1344913446

1345013447
// Introduction of a `Bind` constraint here could result in the disconnect

lib/Sema/CSStep.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -280,13 +280,11 @@ StepResult ComponentStep::take(bool prevFailed) {
280280
CS.collectDisjunctions(disjunctions);
281281
std::vector<std::string> overloadDisjunctions;
282282
for (const auto &disjunction : disjunctions) {
283-
PrintOptions PO;
284-
PO.PrintTypesForDebugging = true;
285-
286283
auto constraints = disjunction->getNestedConstraints();
287284
if (constraints[0]->getKind() == ConstraintKind::BindOverload)
288285
overloadDisjunctions.push_back(
289-
constraints[0]->getFirstType()->getString(PO));
286+
constraints[0]->getFirstType()->getString(
287+
PrintOptions::forDebugging()));
290288
}
291289

292290
if (!potentialBindings.empty() || !overloadDisjunctions.empty()) {
@@ -357,14 +355,11 @@ StepResult ComponentStep::take(bool prevFailed) {
357355
// we can't solve this system unless we have free type variables
358356
// allowed in the solution.
359357
if (CS.isDebugMode()) {
360-
PrintOptions PO;
361-
PO.PrintTypesForDebugging = true;
362-
363358
auto &log = getDebugLogger();
364359
log << "(failed due to free variables:";
365360
for (auto *typeVar : CS.getTypeVariables()) {
366361
if (!typeVar->getImpl().hasRepresentativeOrFixed()) {
367-
log << " " << typeVar->getString(PO);
362+
log << " " << typeVar->getString(PrintOptions::forDebugging());
368363
}
369364
}
370365
log << ")\n";

0 commit comments

Comments
 (0)