Skip to content

Commit 422bb37

Browse files
committed
Teach the frontend how to parse TypeCheckerOptions
1 parent 0977267 commit 422bb37

File tree

4 files changed

+53
-41
lines changed

4 files changed

+53
-41
lines changed

include/swift/Frontend/Frontend.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ struct ModuleBuffers {
8383
/// which manages the actual compiler execution.
8484
class CompilerInvocation {
8585
LangOptions LangOpts;
86+
TypeCheckerOptions TypeCheckerOpts;
8687
FrontendOptions FrontendOpts;
8788
ClangImporterOptions ClangImporterOpts;
8889
SearchPathOptions SearchPathOpts;
@@ -215,6 +216,11 @@ class CompilerInvocation {
215216
return LangOpts;
216217
}
217218

219+
TypeCheckerOptions &getTypeCheckerOptions() { return TypeCheckerOpts; }
220+
const TypeCheckerOptions &getTypeCheckerOptions() const {
221+
return TypeCheckerOpts;
222+
}
223+
218224
FrontendOptions &getFrontendOptions() { return FrontendOpts; }
219225
const FrontendOptions &getFrontendOptions() const { return FrontendOpts; }
220226

@@ -648,14 +654,11 @@ class CompilerInstance {
648654
bool
649655
parsePartialModulesAndLibraryFiles(const ImplicitImports &implicitImports);
650656

651-
OptionSet<TypeCheckingFlags> computeTypeCheckingOptions();
652-
653657
void forEachFileToTypeCheck(llvm::function_ref<void(SourceFile &)> fn);
654658

655-
void parseAndTypeCheckMainFileUpTo(SourceFile::ASTStage_t LimitStage,
656-
OptionSet<TypeCheckingFlags> TypeCheckOptions);
659+
void parseAndTypeCheckMainFileUpTo(SourceFile::ASTStage_t LimitStage);
657660

658-
void finishTypeChecking(OptionSet<TypeCheckingFlags> TypeCheckOptions);
661+
void finishTypeChecking();
659662

660663
public:
661664
const PrimarySpecificPaths &

lib/Frontend/ArgsToFrontendOptionsConverter.cpp

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,6 @@ bool ArgsToFrontendOptionsConverter::convert(
9090
computeDebugTimeOptions();
9191
computeTBDOptions();
9292

93-
setUnsignedIntegerArgument(OPT_warn_long_function_bodies, 10,
94-
Opts.WarnLongFunctionBodies);
95-
setUnsignedIntegerArgument(OPT_warn_long_expression_type_checking, 10,
96-
Opts.WarnLongExpressionTypeChecking);
97-
setUnsignedIntegerArgument(OPT_solver_expression_time_threshold_EQ, 10,
98-
Opts.SolverExpressionTimeThreshold);
99-
setUnsignedIntegerArgument(OPT_switch_checking_invocation_threshold_EQ, 10,
100-
Opts.SwitchCheckingInvocationThreshold);
101-
10293
Opts.CheckOnoneSupportCompleteness = Args.hasArg(OPT_check_onone_completeness);
10394

10495
Opts.DebuggerTestingTransform = Args.hasArg(OPT_debugger_testing_transform);
@@ -163,7 +154,7 @@ bool ArgsToFrontendOptionsConverter::convert(
163154
return true;
164155

165156
if (FrontendOptions::doesActionGenerateIR(Opts.RequestedAction)
166-
&& Opts.SkipNonInlinableFunctionBodies) {
157+
&& Args.hasArg(OPT_experimental_skip_non_inlinable_function_bodies)) {
167158
Diags.diagnose(SourceLoc(), diag::cannot_emit_ir_skipping_function_bodies);
168159
return true;
169160
}
@@ -222,17 +213,7 @@ void ArgsToFrontendOptionsConverter::computePrintStatsOptions() {
222213

223214
void ArgsToFrontendOptionsConverter::computeDebugTimeOptions() {
224215
using namespace options;
225-
Opts.DebugTimeFunctionBodies |= Args.hasArg(OPT_debug_time_function_bodies);
226-
Opts.DebugTimeExpressionTypeChecking |=
227-
Args.hasArg(OPT_debug_time_expression_type_checking);
228216
Opts.DebugTimeCompilation |= Args.hasArg(OPT_debug_time_compilation);
229-
Opts.SkipNonInlinableFunctionBodies |=
230-
Args.hasArg(OPT_experimental_skip_non_inlinable_function_bodies);
231-
232-
// If asked to perform InstallAPI, go ahead and enable non-inlinable function
233-
// body skipping.
234-
Opts.SkipNonInlinableFunctionBodies |=
235-
Args.hasArg(OPT_tbd_is_installapi);
236217

237218
if (const Arg *A = Args.getLastArg(OPT_stats_output_dir)) {
238219
Opts.StatsOutputDir = A->getValue();
@@ -266,19 +247,6 @@ void ArgsToFrontendOptionsConverter::computeTBDOptions() {
266247
}
267248
}
268249

269-
void ArgsToFrontendOptionsConverter::setUnsignedIntegerArgument(
270-
options::ID optionID, unsigned radix, unsigned &valueToSet) {
271-
if (const Arg *A = Args.getLastArg(optionID)) {
272-
unsigned attempt;
273-
if (StringRef(A->getValue()).getAsInteger(radix, attempt)) {
274-
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
275-
A->getAsString(Args), A->getValue());
276-
} else {
277-
valueToSet = attempt;
278-
}
279-
}
280-
}
281-
282250
void ArgsToFrontendOptionsConverter::computePlaygroundOptions() {
283251
using namespace options;
284252
Opts.PlaygroundTransform |= Args.hasArg(OPT_playground);

lib/Frontend/ArgsToFrontendOptionsConverter.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@ class ArgsToFrontendOptionsConverter {
4747
void computePrintStatsOptions();
4848
void computeTBDOptions();
4949

50-
void setUnsignedIntegerArgument(options::ID optionID, unsigned radix,
51-
unsigned &valueToSet);
52-
5350
bool setUpInputKindAndImmediateArgs();
5451

5552
bool checkUnusedSupplementaryOutputPaths() const;

lib/Frontend/CompilerInvocation.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,46 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
552552
return HadError || UnsupportedOS || UnsupportedArch;
553553
}
554554

555+
static bool ParseTypeCheckerArgs(TypeCheckerOptions &Opts, ArgList &Args,
556+
DiagnosticEngine &Diags,
557+
const FrontendOptions &FrontendOpts) {
558+
using namespace options;
559+
560+
auto setUnsignedIntegerArgument = [&Args, &Diags](
561+
options::ID optionID, unsigned radix, unsigned &valueToSet) {
562+
if (const Arg *A = Args.getLastArg(optionID)) {
563+
unsigned attempt;
564+
if (StringRef(A->getValue()).getAsInteger(radix, attempt)) {
565+
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
566+
A->getAsString(Args), A->getValue());
567+
} else {
568+
valueToSet = attempt;
569+
}
570+
}
571+
};
572+
573+
setUnsignedIntegerArgument(OPT_warn_long_function_bodies, 10,
574+
Opts.WarnLongFunctionBodies);
575+
setUnsignedIntegerArgument(OPT_warn_long_expression_type_checking, 10,
576+
Opts.WarnLongExpressionTypeChecking);
577+
setUnsignedIntegerArgument(OPT_solver_expression_time_threshold_EQ, 10,
578+
Opts.ExpressionTimeoutThreshold);
579+
setUnsignedIntegerArgument(OPT_switch_checking_invocation_threshold_EQ, 10,
580+
Opts.SwitchCheckingInvocationThreshold);
581+
582+
Opts.DebugTimeFunctionBodies |= Args.hasArg(OPT_debug_time_function_bodies);
583+
Opts.DebugTimeExpressions |=
584+
Args.hasArg(OPT_debug_time_expression_type_checking);
585+
Opts.SkipNonInlinableFunctionBodies |=
586+
Args.hasArg(OPT_experimental_skip_non_inlinable_function_bodies);
587+
588+
// If asked to perform InstallAPI, go ahead and enable non-inlinable function
589+
// body skipping.
590+
Opts.SkipNonInlinableFunctionBodies |= Args.hasArg(OPT_tbd_is_installapi);
591+
592+
return false;
593+
}
594+
555595
static bool ParseClangImporterArgs(ClangImporterOptions &Opts,
556596
ArgList &Args,
557597
DiagnosticEngine &Diags,
@@ -1384,6 +1424,10 @@ bool CompilerInvocation::parseArgs(
13841424
return true;
13851425
}
13861426

1427+
if (ParseTypeCheckerArgs(TypeCheckerOpts, ParsedArgs, Diags, FrontendOpts)) {
1428+
return true;
1429+
}
1430+
13871431
if (ParseClangImporterArgs(ClangImporterOpts, ParsedArgs, Diags,
13881432
workingDirectory)) {
13891433
return true;

0 commit comments

Comments
 (0)