Skip to content

Commit 417c82f

Browse files
committed
Strip TypeChecker of its ASTContext
If you can get a TypeChecker at this point, you had one all along. Its constructor and destructor are now defaultable.
1 parent bed7f23 commit 417c82f

File tree

4 files changed

+14
-19
lines changed

4 files changed

+14
-19
lines changed

lib/Sema/CSSolver.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ ConstraintSystem::SolverState::SolverState(
362362

363363
// If we're supposed to debug a specific constraint solver attempt,
364364
// turn on debugging now.
365-
ASTContext &ctx = CS.getTypeChecker().Context;
365+
ASTContext &ctx = CS.getASTContext();
366366
auto &tyOpts = ctx.TypeCheckerOpts;
367367
OldDebugConstraintSolver = tyOpts.DebugConstraintSolver;
368368
if (tyOpts.DebugConstraintSolverAttempt &&
@@ -409,7 +409,7 @@ ConstraintSystem::SolverState::~SolverState() {
409409
}
410410

411411
// Restore debugging state.
412-
TypeCheckerOptions &tyOpts = CS.getTypeChecker().Context.TypeCheckerOpts;
412+
TypeCheckerOptions &tyOpts = CS.getASTContext().TypeCheckerOpts;
413413
tyOpts.DebugConstraintSolver = OldDebugConstraintSolver;
414414

415415
// Write our local statistics back to the overall statistics.

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2172,6 +2172,7 @@ Type TypeChecker::typeCheckExpressionImpl(Expr *&expr, DeclContext *dc,
21722172
TypeCheckExprOptions options,
21732173
ExprTypeCheckListener &listener,
21742174
ConstraintSystem *baseCS) {
2175+
auto &Context = dc->getASTContext();
21752176
FrontendStatsTracer StatsTracer(Context.Stats, "typecheck-expr", expr);
21762177
PrettyStackTraceExpr stackTrace(Context, "type-checking", expr);
21772178

@@ -3717,22 +3718,22 @@ void ConstraintSystem::print(raw_ostream &out) const {
37173718
out << "\nActive Constraints:\n";
37183719
for (auto &constraint : ActiveConstraints) {
37193720
out.indent(2);
3720-
constraint.print(out, &getTypeChecker().Context.SourceMgr);
3721+
constraint.print(out, &getASTContext().SourceMgr);
37213722
out << "\n";
37223723
}
37233724

37243725
out << "\nInactive Constraints:\n";
37253726
for (auto &constraint : InactiveConstraints) {
37263727
out.indent(2);
3727-
constraint.print(out, &getTypeChecker().Context.SourceMgr);
3728+
constraint.print(out, &getASTContext().SourceMgr);
37283729
out << "\n";
37293730
}
37303731

37313732
if (solverState && !solverState->hasRetiredConstraints()) {
37323733
out << "\nRetired Constraints:\n";
37333734
solverState->forEachRetired([&](Constraint &constraint) {
37343735
out.indent(2);
3735-
constraint.print(out, &getTypeChecker().Context.SourceMgr);
3736+
constraint.print(out, &getASTContext().SourceMgr);
37363737
out << "\n";
37373738
});
37383739
}
@@ -3786,7 +3787,7 @@ void ConstraintSystem::print(raw_ostream &out) const {
37863787
out << "\nDisjunction choices:\n";
37873788
for (auto &choice : DisjunctionChoices) {
37883789
out.indent(2);
3789-
choice.first->dump(&getTypeChecker().Context.SourceMgr, out);
3790+
choice.first->dump(&getASTContext().SourceMgr, out);
37903791
out << " is #" << choice.second << "\n";
37913792
}
37923793
}
@@ -3795,7 +3796,7 @@ void ConstraintSystem::print(raw_ostream &out) const {
37953796
out << "\nOpened types:\n";
37963797
for (const auto &opened : OpenedTypes) {
37973798
out.indent(2);
3798-
opened.first->dump(&getTypeChecker().Context.SourceMgr, out);
3799+
opened.first->dump(&getASTContext().SourceMgr, out);
37993800
out << " opens ";
38003801
interleave(opened.second.begin(), opened.second.end(),
38013802
[&](OpenedType opened) {
@@ -3814,7 +3815,7 @@ void ConstraintSystem::print(raw_ostream &out) const {
38143815
out << "\nOpened existential types:\n";
38153816
for (const auto &openedExistential : OpenedExistentialTypes) {
38163817
out.indent(2);
3817-
openedExistential.first->dump(&getTypeChecker().Context.SourceMgr, out);
3818+
openedExistential.first->dump(&getASTContext().SourceMgr, out);
38183819
out << " opens to " << openedExistential.second->getString(PO);
38193820
out << "\n";
38203821
}
@@ -3823,7 +3824,7 @@ void ConstraintSystem::print(raw_ostream &out) const {
38233824
if (!DefaultedConstraints.empty()) {
38243825
out << "\nDefaulted constraints: ";
38253826
interleave(DefaultedConstraints, [&](ConstraintLocator *locator) {
3826-
locator->dump(&getTypeChecker().Context.SourceMgr, out);
3827+
locator->dump(&getASTContext().SourceMgr, out);
38273828
}, [&] {
38283829
out << ", ";
38293830
});
@@ -3832,7 +3833,7 @@ void ConstraintSystem::print(raw_ostream &out) const {
38323833
if (failedConstraint) {
38333834
out << "\nFailed constraint:\n";
38343835
out.indent(2);
3835-
failedConstraint->print(out, &getTypeChecker().Context.SourceMgr);
3836+
failedConstraint->print(out, &getASTContext().SourceMgr);
38363837
out << "\n";
38373838
}
38383839

lib/Sema/TypeChecker.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,12 @@ using namespace swift;
5555
TypeChecker &TypeChecker::createForContext(ASTContext &ctx) {
5656
assert(!ctx.getLegacyGlobalTypeChecker() &&
5757
"Cannot install more than one instance of the global type checker!");
58-
auto *TC = new TypeChecker(ctx);
58+
auto *TC = new TypeChecker();
5959
ctx.installGlobalTypeChecker(TC);
6060
ctx.addCleanup([=](){ delete TC; });
6161
return *ctx.getLegacyGlobalTypeChecker();
6262
}
6363

64-
TypeChecker::TypeChecker(ASTContext &Ctx)
65-
: Context(Ctx) {}
66-
67-
TypeChecker::~TypeChecker() {}
68-
6964
ProtocolDecl *TypeChecker::getProtocol(ASTContext &Context, SourceLoc loc,
7065
KnownProtocolKind kind) {
7166
auto protocol = Context.getProtocol(kind);

lib/Sema/TypeChecker.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -542,9 +542,9 @@ class TypeChecker final {
542542
std::vector<AbstractClosureExpr *> ClosuresWithUncomputedCaptures;
543543

544544
private:
545-
ASTContext &Context;
545+
TypeChecker() = default;
546+
~TypeChecker() = default;
546547

547-
TypeChecker(ASTContext &Ctx);
548548
friend class ASTContext;
549549
friend class constraints::ConstraintSystem;
550550
friend class TypeCheckFunctionBodyUntilRequest;
@@ -559,7 +559,6 @@ class TypeChecker final {
559559
public:
560560
TypeChecker(const TypeChecker&) = delete;
561561
TypeChecker& operator=(const TypeChecker&) = delete;
562-
~TypeChecker();
563562

564563
static Type getArraySliceType(SourceLoc loc, Type elementType);
565564
static Type getDictionaryType(SourceLoc loc, Type keyType, Type valueType);

0 commit comments

Comments
 (0)