Skip to content

Commit d1816ae

Browse files
authored
Merge pull request swiftlang#31880 from CodaFi/setup-assistant
[NFC] Drop TypeCheckerDebugConsumer
2 parents ac704ea + afe8f2b commit d1816ae

16 files changed

+82
-199
lines changed

include/swift/AST/ASTContext.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ namespace swift {
111111
class SourceManager;
112112
class ValueDecl;
113113
class DiagnosticEngine;
114-
class TypeCheckerDebugConsumer;
115114
struct RawComment;
116115
class DocComment;
117116
class SILBoxType;
@@ -276,9 +275,6 @@ class ASTContext final {
276275
#define IDENTIFIER_WITH_NAME(Name, IdStr) Identifier Id_##Name;
277276
#include "swift/AST/KnownIdentifiers.def"
278277

279-
/// A consumer of type checker debug output.
280-
std::unique_ptr<TypeCheckerDebugConsumer> TypeCheckerDebug;
281-
282278
/// Cache for names of canonical GenericTypeParamTypes.
283279
mutable llvm::DenseMap<unsigned, Identifier>
284280
CanonicalGenericTypeParamTypeNames;

include/swift/AST/TypeCheckerDebugConsumer.h

Lines changed: 0 additions & 55 deletions
This file was deleted.

lib/AST/ASTContext.cpp

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
#include "swift/AST/SubstitutionMap.h"
4545
#include "swift/AST/SILLayout.h"
4646
#include "swift/AST/TypeCheckRequests.h"
47-
#include "swift/AST/TypeCheckerDebugConsumer.h"
4847
#include "swift/Basic/Compiler.h"
4948
#include "swift/Basic/SourceManager.h"
5049
#include "swift/Basic/Statistic.h"
@@ -557,7 +556,6 @@ ASTContext::ASTContext(LangOptions &langOpts, TypeCheckerOptions &typeckOpts,
557556
TheBuiltinModule(createBuiltinModule(*this)),
558557
StdlibModuleName(getIdentifier(STDLIB_NAME)),
559558
SwiftShimsModuleName(getIdentifier(SWIFT_SHIMS_NAME)),
560-
TypeCheckerDebug(new StderrTypeCheckerDebugConsumer()),
561559
TheErrorType(
562560
new (*this, AllocationArena::Permanent)
563561
ErrorType(*this, Type(), RecursiveTypeProperties::HasError)),
@@ -3833,45 +3831,6 @@ void TypeLoc::setInvalidType(ASTContext &C) {
38333831
Ty = ErrorType::get(C);
38343832
}
38353833

3836-
namespace {
3837-
class raw_capturing_ostream : public raw_ostream {
3838-
std::string Message;
3839-
uint64_t Pos;
3840-
CapturingTypeCheckerDebugConsumer &Listener;
3841-
3842-
public:
3843-
raw_capturing_ostream(CapturingTypeCheckerDebugConsumer &Listener)
3844-
: Listener(Listener) {}
3845-
3846-
~raw_capturing_ostream() override {
3847-
flush();
3848-
}
3849-
3850-
void write_impl(const char *Ptr, size_t Size) override {
3851-
Message.append(Ptr, Size);
3852-
Pos += Size;
3853-
3854-
// Check if we have at least one complete line.
3855-
size_t LastNewline = StringRef(Message).rfind('\n');
3856-
if (LastNewline == StringRef::npos)
3857-
return;
3858-
Listener.handleMessage(StringRef(Message.data(), LastNewline + 1));
3859-
Message.erase(0, LastNewline + 1);
3860-
}
3861-
3862-
uint64_t current_pos() const override {
3863-
return Pos;
3864-
}
3865-
};
3866-
} // unnamed namespace
3867-
3868-
TypeCheckerDebugConsumer::~TypeCheckerDebugConsumer() { }
3869-
3870-
CapturingTypeCheckerDebugConsumer::CapturingTypeCheckerDebugConsumer()
3871-
: Log(new raw_capturing_ostream(*this)) {
3872-
Log->SetUnbuffered();
3873-
}
3874-
38753834
void SubstitutionMap::Storage::Profile(
38763835
llvm::FoldingSetNodeID &id,
38773836
GenericSignature genericSig,

lib/Frontend/CompilerInvocation.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,23 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
634634
Opts.VerifySyntaxTree = true;
635635
}
636636

637+
// If we are asked to emit a module documentation file, configure lexing and
638+
// parsing to remember comments.
639+
if (FrontendOpts.InputsAndOutputs.hasModuleDocOutputPath()) {
640+
Opts.AttachCommentsToDecls = true;
641+
}
642+
643+
// If we are doing index-while-building, configure lexing and parsing to
644+
// remember comments.
645+
if (!FrontendOpts.IndexStorePath.empty()) {
646+
Opts.AttachCommentsToDecls = true;
647+
}
648+
649+
// If we're parsing SIL, access control doesn't make sense to enforce.
650+
if (FrontendOpts.InputKind == InputFileKind::SIL) {
651+
Opts.EnableAccessControl = false;
652+
}
653+
637654
return HadError || UnsupportedOS || UnsupportedArch;
638655
}
639656

lib/Frontend/Frontend.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -298,24 +298,8 @@ bool CompilerInstance::setup(const CompilerInvocation &Invok) {
298298
setUpLLVMArguments();
299299
setUpDiagnosticOptions();
300300

301-
const auto &frontendOpts = Invocation.getFrontendOptions();
302-
303-
// If we are asked to emit a module documentation file, configure lexing and
304-
// parsing to remember comments.
305-
if (frontendOpts.InputsAndOutputs.hasModuleDocOutputPath())
306-
Invocation.getLangOptions().AttachCommentsToDecls = true;
307-
308-
// If we are doing index-while-building, configure lexing and parsing to
309-
// remember comments.
310-
if (!frontendOpts.IndexStorePath.empty()) {
311-
Invocation.getLangOptions().AttachCommentsToDecls = true;
312-
}
313-
314301
assert(Lexer::isIdentifier(Invocation.getModuleName()));
315302

316-
if (isInSILMode())
317-
Invocation.getLangOptions().EnableAccessControl = false;
318-
319303
if (setUpInputs())
320304
return true;
321305

lib/Sema/CSApply.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8320,9 +8320,8 @@ ExprWalker::rewriteTarget(SolutionApplicationTarget target) {
83208320
solution.setExprTypes(resultExpr);
83218321
result.setExpr(resultExpr);
83228322

8323-
auto &ctx = cs.getASTContext();
83248323
if (cs.isDebugMode()) {
8325-
auto &log = ctx.TypeCheckerDebug->getStream();
8324+
auto &log = llvm::errs();
83268325
log << "---Type-checked expression---\n";
83278326
resultExpr->dump(log);
83288327
log << "\n";

lib/Sema/CSBindings.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,7 @@ ConstraintSystem::determineBestBindings() {
108108
inferTransitiveSupertypeBindings(cache, bindings);
109109

110110
if (isDebugMode()) {
111-
auto &log = getASTContext().TypeCheckerDebug->getStream();
112-
bindings.dump(typeVar, log, solverState->depth * 2);
111+
bindings.dump(typeVar, llvm::errs(), solverState->depth * 2);
113112
}
114113

115114
// If these are the first bindings, or they are better than what

lib/Sema/CSGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4405,7 +4405,7 @@ bool ConstraintSystem::generateConstraints(
44054405
}
44064406

44074407
if (isDebugMode()) {
4408-
auto &log = getASTContext().TypeCheckerDebug->getStream();
4408+
auto &log = llvm::errs();
44094409
log << "---Initial constraints for the given expression---\n";
44104410
print(log, expr);
44114411
log << "\n";

lib/Sema/CSRanking.cpp

Lines changed: 33 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -36,61 +36,60 @@ void ConstraintSystem::increaseScore(ScoreKind kind, unsigned value) {
3636
CurrentScore.Data[index] += value;
3737

3838
if (isDebugMode() && value > 0) {
39-
auto &log = getASTContext().TypeCheckerDebug->getStream();
4039
if (solverState)
41-
log.indent(solverState->depth * 2);
42-
log << "(increasing score due to ";
40+
llvm::errs().indent(solverState->depth * 2);
41+
llvm::errs() << "(increasing score due to ";
4342
switch (kind) {
4443
case SK_Hole:
45-
log << "hole in the constraint system";
44+
llvm::errs() << "hole in the constraint system";
4645
break;
4746

4847
case SK_Unavailable:
49-
log << "use of an unavailable declaration";
48+
llvm::errs() << "use of an unavailable declaration";
5049
break;
5150

5251
case SK_Fix:
53-
log << "attempting to fix the source";
52+
llvm::errs() << "attempting to fix the source";
5453
break;
5554

5655
case SK_DisfavoredOverload:
57-
log << "disfavored overload";
56+
llvm::errs() << "disfavored overload";
5857
break;
5958

6059
case SK_ForceUnchecked:
61-
log << "force of an implicitly unwrapped optional";
60+
llvm::errs() << "force of an implicitly unwrapped optional";
6261
break;
6362

6463
case SK_UserConversion:
65-
log << "user conversion";
64+
llvm::errs() << "user conversion";
6665
break;
6766

6867
case SK_FunctionConversion:
69-
log << "function conversion";
68+
llvm::errs() << "function conversion";
7069
break;
7170

7271
case SK_NonDefaultLiteral:
73-
log << "non-default literal";
72+
llvm::errs() << "non-default literal";
7473
break;
7574

7675
case SK_CollectionUpcastConversion:
77-
log << "collection upcast conversion";
76+
llvm::errs() << "collection upcast conversion";
7877
break;
7978

8079
case SK_ValueToOptional:
81-
log << "value to optional";
80+
llvm::errs() << "value to optional";
8281
break;
8382
case SK_EmptyExistentialConversion:
84-
log << "empty-existential conversion";
83+
llvm::errs() << "empty-existential conversion";
8584
break;
8685
case SK_KeyPathSubscript:
87-
log << "key path subscript";
86+
llvm::errs() << "key path subscript";
8887
break;
8988
case SK_ValueToPointerConversion:
90-
log << "value-to-pointer conversion";
89+
llvm::errs() << "value-to-pointer conversion";
9190
break;
9291
}
93-
log << ")\n";
92+
llvm::errs() << ")\n";
9493
}
9594
}
9695

@@ -103,8 +102,7 @@ bool ConstraintSystem::worseThanBestSolution() const {
103102
return false;
104103

105104
if (isDebugMode()) {
106-
auto &log = getASTContext().TypeCheckerDebug->getStream();
107-
log.indent(solverState->depth * 2)
105+
llvm::errs().indent(solverState->depth * 2)
108106
<< "(solution is worse than the best solution)\n";
109107
}
110108

@@ -389,21 +387,20 @@ bool CompareDeclSpecializationRequest::evaluate(
389387
// Construct a constraint system to compare the two declarations.
390388
ConstraintSystem cs(dc, ConstraintSystemOptions());
391389
if (cs.isDebugMode()) {
392-
auto &log = C.TypeCheckerDebug->getStream();
393-
log << "Comparing declarations\n";
394-
decl1->print(log);
395-
log << "\nand\n";
396-
decl2->print(log);
397-
log << "\n(isDynamicOverloadComparison: ";
398-
log << isDynamicOverloadComparison;
399-
log << ")\n";
390+
llvm::errs() << "Comparing declarations\n";
391+
decl1->print(llvm::errs());
392+
llvm::errs() << "\nand\n";
393+
decl2->print(llvm::errs());
394+
llvm::errs() << "\n(isDynamicOverloadComparison: ";
395+
llvm::errs() << isDynamicOverloadComparison;
396+
llvm::errs() << ")\n";
400397
}
401398

402-
auto completeResult = [&C, &cs](bool result) {
399+
auto completeResult = [&cs](bool result) {
403400
if (cs.isDebugMode()) {
404-
auto &log = C.TypeCheckerDebug->getStream();
405-
log << "comparison result: " << (result ? "better" : "not better")
406-
<< "\n";
401+
llvm::errs() << "comparison result: "
402+
<< (result ? "better" : "not better")
403+
<< "\n";
407404
}
408405
return result;
409406
};
@@ -738,8 +735,7 @@ SolutionCompareResult ConstraintSystem::compareSolutions(
738735
ConstraintSystem &cs, ArrayRef<Solution> solutions,
739736
const SolutionDiff &diff, unsigned idx1, unsigned idx2) {
740737
if (cs.isDebugMode()) {
741-
auto &log = cs.getASTContext().TypeCheckerDebug->getStream();
742-
log.indent(cs.solverState->depth * 2)
738+
llvm::errs().indent(cs.solverState->depth * 2)
743739
<< "comparing solutions " << idx1 << " and " << idx2 <<"\n";
744740
}
745741

@@ -1262,13 +1258,13 @@ ConstraintSystem::findBestSolution(SmallVectorImpl<Solution> &viable,
12621258
return 0;
12631259

12641260
if (isDebugMode()) {
1265-
auto &log = getASTContext().TypeCheckerDebug->getStream();
1266-
log.indent(solverState->depth * 2)
1261+
llvm::errs().indent(solverState->depth * 2)
12671262
<< "Comparing " << viable.size() << " viable solutions\n";
12681263

12691264
for (unsigned i = 0, n = viable.size(); i != n; ++i) {
1270-
log.indent(solverState->depth * 2) << "--- Solution #" << i << " ---\n";
1271-
viable[i].dump(log.indent(solverState->depth * 2));
1265+
llvm::errs().indent(solverState->depth * 2)
1266+
<< "--- Solution #" << i << " ---\n";
1267+
viable[i].dump(llvm::errs().indent(solverState->depth * 2));
12721268
}
12731269
}
12741270

lib/Sema/CSSimplify.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8144,10 +8144,8 @@ bool ConstraintSystem::simplifyAppliedOverloadsImpl(
81448144

81458145
// If we have a common result type, bind the expected result type to it.
81468146
if (commonResultType && !commonResultType->is<ErrorType>()) {
8147-
ASTContext &ctx = getASTContext();
81488147
if (isDebugMode()) {
8149-
auto &log = ctx.TypeCheckerDebug->getStream();
8150-
log.indent(solverState ? solverState->depth * 2 : 0)
8148+
llvm::errs().indent(solverState ? solverState->depth * 2 : 0)
81518149
<< "(common result type for $T" << fnTypeVar->getID() << " is "
81528150
<< commonResultType.getString()
81538151
<< ")\n";
@@ -9286,9 +9284,8 @@ static bool isAugmentingFix(ConstraintFix *fix) {
92869284
}
92879285

92889286
bool ConstraintSystem::recordFix(ConstraintFix *fix, unsigned impact) {
9289-
auto &ctx = getASTContext();
92909287
if (isDebugMode()) {
9291-
auto &log = ctx.TypeCheckerDebug->getStream();
9288+
auto &log = llvm::errs();
92929289
log.indent(solverState ? solverState->depth * 2 : 0)
92939290
<< "(attempting fix ";
92949291
fix->print(log);

0 commit comments

Comments
 (0)