Skip to content

Commit 0977267

Browse files
committed
Absorb the TypeCheckerFlags into the Frontend
De-duplicate TypeCheckingFlags, TypeChecker's Options, and the TypeChecker-Oriented FrontendOptions into a dedicated TypeCheckerOptions type. This moves a bunch of configuration state out of the type checker and into the ASTContext where it belongs.
1 parent 631305f commit 0977267

File tree

5 files changed

+51
-196
lines changed

5 files changed

+51
-196
lines changed

include/swift/Basic/LangOptions.h

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ namespace swift {
5656

5757
/// A collection of options that affect the language dialect and
5858
/// provide compiler debugging facilities.
59-
class LangOptions {
59+
class LangOptions final {
6060
public:
6161

6262
/// The target we are building for.
@@ -456,6 +456,54 @@ namespace swift {
456456
PlatformConditionValues;
457457
llvm::SmallVector<std::string, 2> CustomConditionalCompilationFlags;
458458
};
459+
460+
class TypeCheckerOptions final {
461+
public:
462+
/// If non-zero, warn when a function body takes longer than this many
463+
/// milliseconds to type-check.
464+
///
465+
/// Intended for debugging purposes only.
466+
unsigned WarnLongFunctionBodies = 0;
467+
468+
/// If non-zero, warn when type-checking an expression takes longer
469+
/// than this many milliseconds.
470+
///
471+
/// Intended for debugging purposes only.
472+
unsigned WarnLongExpressionTypeChecking = 0;
473+
474+
/// If non-zero, abort the expression type checker if it takes more
475+
/// than this many seconds.
476+
unsigned ExpressionTimeoutThreshold = 600;
477+
478+
/// If non-zero, abort the switch statement exhaustiveness checker if
479+
/// the Space::minus function is called more than this many times.
480+
///
481+
/// Why this number? Times out in about a second on a 2017 iMac, Retina 5K,
482+
/// 4.2 GHz Intel Core i7.
483+
/// (It's arbitrary, but will keep the compiler from taking too much time.)
484+
unsigned SwitchCheckingInvocationThreshold = 200000;
485+
486+
/// Whether to delay checking that benefits from having the entire
487+
/// module parsed, e.g., Objective-C method override checking.
488+
bool DelayWholeModuleChecking = false;
489+
490+
/// If true, the time it takes to type-check each function will be dumped
491+
/// to llvm::errs().
492+
bool DebugTimeFunctionBodies = false;
493+
494+
/// If true, the time it takes to type-check each expression will be
495+
/// dumped to llvm::errs().
496+
bool DebugTimeExpressions = false;
497+
498+
/// Indicate that the type checker is checking code that will be
499+
/// immediately executed. This will suppress certain warnings
500+
/// when executing scripts.
501+
bool InImmediateMode = false;
502+
503+
/// Indicate that the type checker should skip type-checking non-inlinable
504+
/// function bodies.
505+
bool SkipNonInlinableFunctionBodies = false;
506+
};
459507
} // end namespace swift
460508

461509
#endif // SWIFT_BASIC_LANGOPTIONS_H

include/swift/Frontend/FrontendOptions.h

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -82,28 +82,6 @@ class FrontendOptions {
8282
/// Emit index data for imported serialized swift system modules.
8383
bool IndexSystemModules = false;
8484

85-
/// If non-zero, warn when a function body takes longer than this many
86-
/// milliseconds to type-check.
87-
///
88-
/// Intended for debugging purposes only.
89-
unsigned WarnLongFunctionBodies = 0;
90-
91-
/// If non-zero, warn when type-checking an expression takes longer
92-
/// than this many milliseconds.
93-
///
94-
/// Intended for debugging purposes only.
95-
unsigned WarnLongExpressionTypeChecking = 0;
96-
97-
/// If non-zero, overrides the default threshold for how long we let
98-
/// the expression type checker run before we consider an expression
99-
/// too complex.
100-
unsigned SolverExpressionTimeThreshold = 0;
101-
102-
/// If non-zero, overrides the default threshold for how many times
103-
/// the Space::minus function is called before we consider switch statement
104-
/// exhaustiveness checking to be too complex.
105-
unsigned SwitchCheckingInvocationThreshold = 0;
106-
10785
/// The module for which we should verify all of the generic signatures.
10886
std::string VerifyGenericSignaturesInModule;
10987

@@ -183,8 +161,6 @@ class FrontendOptions {
183161
/// \sa swift::SharedTimer
184162
bool DebugTimeCompilation = false;
185163

186-
bool SkipNonInlinableFunctionBodies = false;
187-
188164
/// The path to which we should output statistics files.
189165
std::string StatsOutputDir;
190166

include/swift/Subsystems.h

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -168,30 +168,6 @@ namespace swift {
168168
/// to add calls to externally provided functions that simulate
169169
/// "program counter"-like debugging events.
170170
void performPCMacro(SourceFile &SF, TopLevelContext &TLC);
171-
172-
/// Flags used to control type checking.
173-
enum class TypeCheckingFlags : unsigned {
174-
/// Whether to delay checking that benefits from having the entire
175-
/// module parsed, e.g., Objective-C method override checking.
176-
DelayWholeModuleChecking = 1 << 0,
177-
178-
/// If set, dumps wall time taken to check each function body to
179-
/// llvm::errs().
180-
DebugTimeFunctionBodies = 1 << 1,
181-
182-
/// Indicates that the type checker is checking code that will be
183-
/// immediately executed.
184-
ForImmediateMode = 1 << 2,
185-
186-
/// If set, dumps wall time taken to type check each expression to
187-
/// llvm::errs().
188-
DebugTimeExpressions = 1 << 3,
189-
190-
/// If set, the typechecker will skip typechecking non-inlinable function
191-
/// bodies. Set this if you're trying to quickly emit a module or module
192-
/// interface without a full compilation.
193-
SkipNonInlinableFunctionBodies = 1 << 4,
194-
};
195171

196172
/// Creates a type checker instance on the given AST context, if it
197173
/// doesn't already have one.
@@ -372,7 +348,8 @@ namespace swift {
372348
class ParserUnit {
373349
public:
374350
ParserUnit(SourceManager &SM, SourceFileKind SFKind, unsigned BufferID,
375-
const LangOptions &LangOpts, StringRef ModuleName,
351+
const LangOptions &LangOpts, const TypeCheckerOptions &TyOpts,
352+
StringRef ModuleName,
376353
std::shared_ptr<SyntaxParseActions> spActions = nullptr,
377354
SyntaxParsingCache *SyntaxCache = nullptr);
378355
ParserUnit(SourceManager &SM, SourceFileKind SFKind, unsigned BufferID);

lib/Frontend/Frontend.cpp

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -912,27 +912,6 @@ void CompilerInstance::parseLibraryFile(
912912
performNameBinding(*NextInput);
913913
}
914914

915-
OptionSet<TypeCheckingFlags> CompilerInstance::computeTypeCheckingOptions() {
916-
OptionSet<TypeCheckingFlags> TypeCheckOptions;
917-
if (isWholeModuleCompilation()) {
918-
TypeCheckOptions |= TypeCheckingFlags::DelayWholeModuleChecking;
919-
}
920-
const auto &options = Invocation.getFrontendOptions();
921-
if (options.DebugTimeFunctionBodies) {
922-
TypeCheckOptions |= TypeCheckingFlags::DebugTimeFunctionBodies;
923-
}
924-
if (FrontendOptions::isActionImmediate(options.RequestedAction)) {
925-
TypeCheckOptions |= TypeCheckingFlags::ForImmediateMode;
926-
}
927-
if (options.DebugTimeExpressionTypeChecking) {
928-
TypeCheckOptions |= TypeCheckingFlags::DebugTimeExpressions;
929-
}
930-
if (options.SkipNonInlinableFunctionBodies) {
931-
TypeCheckOptions |= TypeCheckingFlags::SkipNonInlinableFunctionBodies;
932-
}
933-
return TypeCheckOptions;
934-
}
935-
936915
bool CompilerInstance::parsePartialModulesAndLibraryFiles(
937916
const ImplicitImports &implicitImports) {
938917
FrontendStatsTracer tracer(Context->Stats,

lib/Sema/TypeChecker.h

Lines changed: 0 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -544,47 +544,6 @@ class TypeChecker final {
544544
private:
545545
ASTContext &Context;
546546

547-
/// If non-zero, warn when a function body takes longer than this many
548-
/// milliseconds to type-check.
549-
///
550-
/// Intended for debugging purposes only.
551-
unsigned WarnLongFunctionBodies = 0;
552-
553-
/// If non-zero, warn when type-checking an expression takes longer
554-
/// than this many milliseconds.
555-
///
556-
/// Intended for debugging purposes only.
557-
unsigned WarnLongExpressionTypeChecking = 0;
558-
559-
/// If non-zero, abort the expression type checker if it takes more
560-
/// than this many seconds.
561-
unsigned ExpressionTimeoutThreshold = 600;
562-
563-
/// If non-zero, abort the switch statement exhaustiveness checker if
564-
/// the Space::minus function is called more than this many times.
565-
///
566-
/// Why this number? Times out in about a second on a 2017 iMac, Retina 5K,
567-
// 4.2 GHz Intel Core i7.
568-
// (It's arbitrary, but will keep the compiler from taking too much time.)
569-
unsigned SwitchCheckingInvocationThreshold = 200000;
570-
571-
/// If true, the time it takes to type-check each function will be dumped
572-
/// to llvm::errs().
573-
bool DebugTimeFunctionBodies = false;
574-
575-
/// If true, the time it takes to type-check each expression will be
576-
/// dumped to llvm::errs().
577-
bool DebugTimeExpressions = false;
578-
579-
/// Indicate that the type checker is checking code that will be
580-
/// immediately executed. This will suppress certain warnings
581-
/// when executing scripts.
582-
bool InImmediateMode = false;
583-
584-
/// Indicate that the type checker should skip type-checking non-inlinable
585-
/// function bodies.
586-
bool SkipNonInlinableFunctionBodies = false;
587-
588547
TypeChecker(ASTContext &Ctx);
589548
friend class ASTContext;
590549
friend class constraints::ConstraintSystem;
@@ -604,90 +563,6 @@ class TypeChecker final {
604563

605564
LangOptions &getLangOpts() const { return Context.LangOpts; }
606565

607-
/// Dump the time it takes to type-check each function to llvm::errs().
608-
void enableDebugTimeFunctionBodies() {
609-
DebugTimeFunctionBodies = true;
610-
}
611-
612-
/// Dump the time it takes to type-check each function to llvm::errs().
613-
void enableDebugTimeExpressions() {
614-
DebugTimeExpressions = true;
615-
}
616-
617-
bool getDebugTimeExpressions() {
618-
return DebugTimeExpressions;
619-
}
620-
621-
/// If \p timeInMS is non-zero, warn when a function body takes longer than
622-
/// this many milliseconds to type-check.
623-
///
624-
/// Intended for debugging purposes only.
625-
void setWarnLongFunctionBodies(unsigned timeInMS) {
626-
WarnLongFunctionBodies = timeInMS;
627-
}
628-
629-
/// If \p timeInMS is non-zero, warn when type-checking an expression
630-
/// takes longer than this many milliseconds.
631-
///
632-
/// Intended for debugging purposes only.
633-
void setWarnLongExpressionTypeChecking(unsigned timeInMS) {
634-
WarnLongExpressionTypeChecking = timeInMS;
635-
}
636-
637-
/// Return the current setting for the number of milliseconds
638-
/// threshold we use to determine whether to warn about an
639-
/// expression taking a long time.
640-
unsigned getWarnLongExpressionTypeChecking() {
641-
return WarnLongExpressionTypeChecking;
642-
}
643-
644-
/// Set the threshold that determines the upper bound for the number
645-
/// of seconds we'll let the expression type checker run before
646-
/// considering an expression "too complex".
647-
void setExpressionTimeoutThreshold(unsigned timeInSeconds) {
648-
ExpressionTimeoutThreshold = timeInSeconds;
649-
}
650-
651-
/// Return the current setting for the threshold that determines
652-
/// the upper bound for the number of seconds we'll let the
653-
/// expression type checker run before considering an expression
654-
/// "too complex".
655-
/// If zero, do not limit the checking.
656-
unsigned getExpressionTimeoutThresholdInSeconds() {
657-
return ExpressionTimeoutThreshold;
658-
}
659-
660-
/// Get the threshold that determines the upper bound for the number
661-
/// of times we'll let the Space::minus routine run before
662-
/// considering a switch statement "too complex".
663-
/// If zero, do not limit the checking.
664-
unsigned getSwitchCheckingInvocationThreshold() const {
665-
return SwitchCheckingInvocationThreshold;
666-
}
667-
668-
/// Set the threshold that determines the upper bound for the number
669-
/// of times we'll let the Space::minus routine run before
670-
/// considering a switch statement "too complex".
671-
void setSwitchCheckingInvocationThreshold(unsigned invocationCount) {
672-
SwitchCheckingInvocationThreshold = invocationCount;
673-
}
674-
675-
void setSkipNonInlinableBodies(bool skip) {
676-
SkipNonInlinableFunctionBodies = skip;
677-
}
678-
679-
bool canSkipNonInlinableBodies() const {
680-
return SkipNonInlinableFunctionBodies;
681-
}
682-
683-
bool getInImmediateMode() {
684-
return InImmediateMode;
685-
}
686-
687-
void setInImmediateMode(bool InImmediateMode) {
688-
this->InImmediateMode = InImmediateMode;
689-
}
690-
691566
static Type getArraySliceType(SourceLoc loc, Type elementType);
692567
static Type getDictionaryType(SourceLoc loc, Type keyType, Type valueType);
693568
static Type getOptionalType(SourceLoc loc, Type elementType);

0 commit comments

Comments
 (0)