Skip to content

Commit b8dc4f0

Browse files
committed
Use TypeCheckerOptions to simplify FunctionBodyTimer
1 parent 54ff860 commit b8dc4f0

File tree

4 files changed

+19
-22
lines changed

4 files changed

+19
-22
lines changed

lib/Sema/TypeCheckStmt.cpp

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,9 @@ namespace {
178178
class FunctionBodyTimer {
179179
AnyFunctionRef Function;
180180
llvm::TimeRecord StartTime = llvm::TimeRecord::getCurrentTime();
181-
unsigned WarnLimit;
182-
bool ShouldDump;
183181

184182
public:
185-
FunctionBodyTimer(AnyFunctionRef Fn, bool shouldDump,
186-
unsigned warnLimit)
187-
: Function(Fn), WarnLimit(warnLimit), ShouldDump(shouldDump) {}
183+
FunctionBodyTimer(AnyFunctionRef Fn) : Function(Fn) {}
188184

189185
~FunctionBodyTimer() {
190186
llvm::TimeRecord endTime = llvm::TimeRecord::getCurrentTime(false);
@@ -195,7 +191,7 @@ namespace {
195191
ASTContext &ctx = Function.getAsDeclContext()->getASTContext();
196192
auto *AFD = Function.getAbstractFunctionDecl();
197193

198-
if (ShouldDump) {
194+
if (ctx.TypeCheckerOpts.WarnLongFunctionBodies) {
199195
// Round up to the nearest 100th of a millisecond.
200196
llvm::errs() << llvm::format("%0.2f", ceil(elapsed * 100000) / 100) << "ms\t";
201197
Function.getLoc().print(llvm::errs(), ctx.SourceMgr);
@@ -210,6 +206,7 @@ namespace {
210206
llvm::errs() << "\n";
211207
}
212208

209+
const auto WarnLimit = ctx.TypeCheckerOpts.DebugTimeFunctionBodies;
213210
if (WarnLimit != 0 && elapsedMS >= WarnLimit) {
214211
if (AFD) {
215212
ctx.Diags.diagnose(AFD, diag::debug_long_function_body,
@@ -1424,7 +1421,8 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
14241421
}
14251422

14261423
if (!switchStmt->isImplicit()) {
1427-
TC.checkSwitchExhaustiveness(switchStmt, DC, limitExhaustivityChecks);
1424+
TypeChecker::checkSwitchExhaustiveness(switchStmt, DC,
1425+
limitExhaustivityChecks);
14281426
}
14291427

14301428
return switchStmt;
@@ -2110,9 +2108,9 @@ TypeCheckFunctionBodyUntilRequest::evaluate(Evaluator &evaluator,
21102108
ctx.Stats->getFrontendCounters().NumFunctionsTypechecked++;
21112109

21122110
Optional<FunctionBodyTimer> timer;
2113-
TypeChecker &tc = *ctx.getLegacyGlobalTypeChecker();
2114-
if (tc.DebugTimeFunctionBodies || tc.WarnLongFunctionBodies)
2115-
timer.emplace(AFD, tc.DebugTimeFunctionBodies, tc.WarnLongFunctionBodies);
2111+
const auto &tyOpts = ctx.TypeCheckerOpts;
2112+
if (tyOpts.DebugTimeFunctionBodies || tyOpts.WarnLongFunctionBodies)
2113+
timer.emplace(AFD);
21162114

21172115
BraceStmt *body = AFD->getBody();
21182116
if (!body || AFD->isBodyTypeChecked())
@@ -2204,11 +2202,10 @@ bool TypeChecker::typeCheckClosureBody(ClosureExpr *closure) {
22042202

22052203
BraceStmt *body = closure->getBody();
22062204

2207-
auto *TC = closure->getASTContext().getLegacyGlobalTypeChecker();
22082205
Optional<FunctionBodyTimer> timer;
2209-
if (TC->DebugTimeFunctionBodies || TC->WarnLongFunctionBodies)
2210-
timer.emplace(closure, TC->DebugTimeFunctionBodies,
2211-
TC->WarnLongFunctionBodies);
2206+
const auto &tyOpts = closure->getASTContext().TypeCheckerOpts;
2207+
if (tyOpts.DebugTimeFunctionBodies || tyOpts.WarnLongFunctionBodies)
2208+
timer.emplace(closure);
22122209

22132210
bool HadError = StmtChecker(closure).typeCheckBody(body);
22142211
if (body) {

test/IRGen/objc_enum_multi_file.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %target-swift-frontend -module-name main -primary-file %s %S/Inputs/objc_enum_multi_file_helper.swift -emit-ir | %FileCheck %s
2+
// RUN: %target-swift-frontend -disable-objc-attr-requires-foundation-module -enable-objc-interop -module-name main -primary-file %s %S/Inputs/objc_enum_multi_file_helper.swift -emit-ir | %FileCheck %s
33

44
// RUN: %target-swift-frontend -disable-objc-attr-requires-foundation-module -enable-objc-interop -emit-module %S/Inputs/objc_enum_multi_file_helper.swift -o %t
55
// RUN: %target-swift-frontend -module-name main -primary-file %s -I %t -DIMPORT -emit-ir | %FileCheck %s

test/IRGen/objc_protocol_multi_file.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -primary-file %s %S/Inputs/objc_protocol_multi_file_helper.swift -g -emit-ir | %FileCheck %s
1+
// RUN: %target-swift-frontend -disable-objc-attr-requires-foundation-module -enable-objc-interop -primary-file %s %S/Inputs/objc_protocol_multi_file_helper.swift -g -emit-ir | %FileCheck %s
22

33
// This used to crash <rdar://problem/17929944>.
44
// To tickle the crash, SubProto must not be used elsewhere in this file.

test/decl/enum/objc_enum_multi_file.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
// RUN: not %target-swift-frontend -module-name main %s -primary-file %S/Inputs/objc_enum_multi_file_helper.swift -emit-ir -D NO_RAW_TYPE 2>&1 | %FileCheck -check-prefix=NO_RAW_TYPE %s
2-
// RUN: not %target-swift-frontend -module-name main %s -primary-file %S/Inputs/objc_enum_multi_file_helper.swift -emit-ir -D BAD_RAW_TYPE 2>&1 | %FileCheck -check-prefix=BAD_RAW_TYPE %s
3-
// RUN: not %target-swift-frontend -module-name main %s -primary-file %S/Inputs/objc_enum_multi_file_helper.swift -emit-ir -D NON_INT_RAW_TYPE 2>&1 | %FileCheck -check-prefix=NON_INT_RAW_TYPE %s
4-
// RUN: not %target-swift-frontend -module-name main %s -primary-file %S/Inputs/objc_enum_multi_file_helper.swift -emit-ir -D NON_INT_RAW_VALUE 2>&1 | %FileCheck -check-prefix=NON_INT_RAW_VALUE %s
5-
// RUN: not %target-swift-frontend -module-name main %s -primary-file %S/Inputs/objc_enum_multi_file_helper.swift -emit-ir -D NO_CASES 2>&1 | %FileCheck -check-prefix=NO_CASES %s
6-
// RUN: not %target-swift-frontend -module-name main %s -primary-file %S/Inputs/objc_enum_multi_file_helper.swift -emit-ir -D DUPLICATE_CASES 2>&1 | %FileCheck -check-prefix=DUPLICATE_CASES %s
1+
// RUN: not %target-swift-frontend -disable-objc-attr-requires-foundation-module -enable-objc-interop -module-name main %s -primary-file %S/Inputs/objc_enum_multi_file_helper.swift -emit-ir -D NO_RAW_TYPE 2>&1 | %FileCheck -check-prefix=NO_RAW_TYPE %s
2+
// RUN: not %target-swift-frontend -disable-objc-attr-requires-foundation-module -enable-objc-interop -module-name main %s -primary-file %S/Inputs/objc_enum_multi_file_helper.swift -emit-ir -D BAD_RAW_TYPE 2>&1 | %FileCheck -check-prefix=BAD_RAW_TYPE %s
3+
// RUN: not %target-swift-frontend -disable-objc-attr-requires-foundation-module -enable-objc-interop -module-name main %s -primary-file %S/Inputs/objc_enum_multi_file_helper.swift -emit-ir -D NON_INT_RAW_TYPE 2>&1 | %FileCheck -check-prefix=NON_INT_RAW_TYPE %s
4+
// RUN: not %target-swift-frontend -disable-objc-attr-requires-foundation-module -enable-objc-interop -module-name main %s -primary-file %S/Inputs/objc_enum_multi_file_helper.swift -emit-ir -D NON_INT_RAW_VALUE 2>&1 | %FileCheck -check-prefix=NON_INT_RAW_VALUE %s
5+
// RUN: not %target-swift-frontend -disable-objc-attr-requires-foundation-module -enable-objc-interop -module-name main %s -primary-file %S/Inputs/objc_enum_multi_file_helper.swift -emit-ir -D NO_CASES 2>&1 | %FileCheck -check-prefix=NO_CASES %s
6+
// RUN: not %target-swift-frontend -disable-objc-attr-requires-foundation-module -enable-objc-interop -module-name main %s -primary-file %S/Inputs/objc_enum_multi_file_helper.swift -emit-ir -D DUPLICATE_CASES 2>&1 | %FileCheck -check-prefix=DUPLICATE_CASES %s
77
// Note that the *other* file is the primary file in this test!
88

99
#if NO_RAW_TYPE

0 commit comments

Comments
 (0)