Skip to content

[NFC] Drop More Type Checkers #28104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Nov 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/IDE/ExprContextAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void typeCheckContextImpl(DeclContext *DC, SourceLoc Loc) {

case DeclContextKind::AbstractFunctionDecl: {
auto *AFD = cast<AbstractFunctionDecl>(DC);
typeCheckAbstractFunctionBodyUntil(AFD, Loc);
swift::typeCheckAbstractFunctionBodyUntil(AFD, Loc);
break;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/Sema/CSApply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5604,7 +5604,7 @@ ClosureExpr *ExprRewriter::coerceClosureExprToVoid(ClosureExpr *closureExpr) {
cs.getType(singleExpr)->getWithoutSpecifierType());

cs.setExprTypes(singleExpr);
tc.checkIgnoredExpr(singleExpr);
TypeChecker::checkIgnoredExpr(singleExpr);

SmallVector<ASTNode, 2> elements;
elements.push_back(singleExpr);
Expand Down Expand Up @@ -5643,7 +5643,7 @@ ClosureExpr *ExprRewriter::coerceClosureExprFromNever(ClosureExpr *closureExpr)
auto singleExpr = returnStmt->getResult();

cs.setExprTypes(singleExpr);
tc.checkIgnoredExpr(singleExpr);
TypeChecker::checkIgnoredExpr(singleExpr);

SmallVector<ASTNode, 1> elements;
elements.push_back(singleExpr);
Expand Down
2 changes: 1 addition & 1 deletion lib/Sema/CSGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2298,7 +2298,7 @@ namespace {
// Okay, now it should be safe to coerce the pattern.
// Pull the top-level pattern back out.
pattern = clause->getErrorPattern();
Type exnType = CS.TC.getExceptionType(CS.DC, clause->getCatchLoc());
Type exnType = CS.getASTContext().getErrorDecl()->getDeclaredType();
if (!exnType)
return false;
if (CS.TC.coercePatternToType(pattern,
Expand Down
11 changes: 0 additions & 11 deletions lib/Sema/ResilienceDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,6 @@ TypeChecker::getFragileFunctionKind(const DeclContext *DC) {
llvm_unreachable("Context is not nested inside a fragile function");
}

void TypeChecker::diagnoseInlinableLocalType(const NominalTypeDecl *NTD) {
auto *DC = NTD->getDeclContext();
auto expansion = DC->getResilienceExpansion();
if (expansion == ResilienceExpansion::Minimal) {
auto kind = getFragileFunctionKind(DC);
diagnose(NTD, diag::local_type_in_inlinable_function,
NTD->getFullName(),
static_cast<unsigned>(kind.first));
}
}

/// A uniquely-typed boolean to reduce the chances of accidentally inverting
/// a check.
enum class DowngradeToWarning: bool {
Expand Down
43 changes: 14 additions & 29 deletions lib/Sema/TypeCheckCircularity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,7 @@ class Path {
};

/// A helper class for performing a circularity check.
class CircularityChecker {
TypeChecker &TC;

class CircularityChecker final {
/// The original type declaration we're starting with.
NominalTypeDecl *OriginalDecl;

Expand All @@ -111,9 +109,9 @@ class CircularityChecker {
SmallVector<WorkItem, 8> Workstack;

public:
CircularityChecker(TypeChecker &tc, NominalTypeDecl *typeDecl)
: TC(tc), OriginalDecl(typeDecl),
MaxDepth(tc.Context.LangOpts.MaxCircularityDepth) {}
CircularityChecker(NominalTypeDecl *typeDecl)
: OriginalDecl(typeDecl),
MaxDepth(typeDecl->getASTContext().LangOpts.MaxCircularityDepth) {}

void run();

Expand Down Expand Up @@ -178,7 +176,7 @@ class CircularityChecker {
} // end anonymous namespace

void TypeChecker::checkDeclCircularity(NominalTypeDecl *decl) {
CircularityChecker(*this, decl).run();
CircularityChecker(decl).run();
}

/// The main routine for performing circularity checks.
Expand Down Expand Up @@ -523,18 +521,12 @@ bool CircularityChecker::diagnoseCircularity(CanType parentType,

auto baseType = path[0].Ty;
if (cycleIndex != 0) {
TC.diagnose(OriginalDecl->getLoc(),
diag::unsupported_infinitely_sized_type,
baseType);
OriginalDecl->diagnose(diag::unsupported_infinitely_sized_type, baseType);
} else if (isa<StructDecl>(OriginalDecl)) {
TC.diagnose(path[1].Member->getLoc(),
diag::unsupported_recursive_struct,
baseType);
path[1].Member->diagnose(diag::unsupported_recursive_struct, baseType);
} else if (isa<EnumDecl>(OriginalDecl)) {
TC.diagnose(OriginalDecl->getLoc(),
diag::recursive_enum_not_indirect,
baseType)
.fixItInsert(OriginalDecl->getStartLoc(), "indirect ");
OriginalDecl->diagnose(diag::recursive_enum_not_indirect, baseType)
.fixItInsert(OriginalDecl->getStartLoc(), "indirect ");
} else {
llvm_unreachable("what kind of entity was this?");
}
Expand All @@ -545,12 +537,9 @@ bool CircularityChecker::diagnoseCircularity(CanType parentType,
llvm::raw_svector_ostream out(pathString);
path.printCycle(out, cycleIndex);
}
TC.diagnose(path[1].Member->getLoc(),
diag::note_type_cycle_starts_here,
pathString);
path[1].Member->diagnose(diag::note_type_cycle_starts_here, pathString);
} else if (isa<EnumDecl>(OriginalDecl)) {
TC.diagnose(path[1].Member->getLoc(),
diag::note_recursive_enum_case_here);
path[1].Member->diagnose(diag::note_recursive_enum_case_here);
}

return true;
Expand All @@ -573,19 +562,15 @@ bool CircularityChecker::diagnoseInfiniteRecursion(CanType parentType,
}

auto baseType = path[0].Ty;
TC.diagnose(OriginalDecl->getLoc(),
diag::unsupported_infinitely_sized_type,
baseType);
OriginalDecl->diagnose(diag::unsupported_infinitely_sized_type, baseType);

// Add a note about the start of the path.
llvm::SmallString<128> pathString; {
llvm::raw_svector_ostream out(pathString);
path.printInfinite(out);
}

TC.diagnose(path[1].Member->getLoc(),
diag::note_type_cycle_starts_here,
pathString);
path[1].Member->diagnose(diag::note_type_cycle_starts_here, pathString);

return true;
}
Expand Down Expand Up @@ -628,5 +613,5 @@ void CircularityChecker::diagnoseNonWellFoundedEnum(EnumDecl *E) {
};

if (isNonWellFounded())
TC.diagnose(E, diag::enum_non_well_founded);
E->getASTContext().Diags.diagnose(E, diag::enum_non_well_founded);
}
Loading