Skip to content

Commit f4d333d

Browse files
committed
Sink a bunch of semantic options into TypeCheckerOptions
Sink - DebugConstraintSolver - DebugConstraintSolverAttempt - DebugConstraintSolverOnLines - DebugGenericSignatures - DebugForbidTypecheckPrefix - SolverMemoryThreshold - SolverBindingThreshold - SolverShrinkUnsolvedThreshold - SolverDisableShrink - EnableOperatorDesignatedTypes - DisableConstraintSolverPerformanceHacks - SolverEnableOperatorDesignatedTypes
1 parent 0cd4fd9 commit f4d333d

20 files changed

+237
-229
lines changed

Diff for: include/swift/Basic/LangOptions.h

+54-50
Original file line numberDiff line numberDiff line change
@@ -160,64 +160,19 @@ namespace swift {
160160
/// Flags for developers
161161
///
162162

163-
/// Whether we are debugging the constraint solver.
164-
///
165-
/// This option enables verbose debugging output from the constraint
166-
/// solver.
167-
bool DebugConstraintSolver = false;
168-
169-
/// Specific solution attempt for which the constraint
170-
/// solver should be debugged.
171-
unsigned DebugConstraintSolverAttempt = 0;
172-
173-
/// Line numbers to activate the constraint solver debugger.
174-
/// Should be stored sorted.
175-
llvm::SmallVector<unsigned, 4> DebugConstraintSolverOnLines;
176-
177163
/// Enable named lazy member loading.
178164
bool NamedLazyMemberLoading = true;
179-
180-
/// Debug the generic signatures computed by the generic signature builder.
181-
bool DebugGenericSignatures = false;
182-
183-
/// Triggers llvm fatal_error if typechecker tries to typecheck a decl or an
184-
/// identifier reference with the provided prefix name.
185-
/// This is for testing purposes.
186-
std::string DebugForbidTypecheckPrefix;
187-
188-
/// Whether to dump debug info for request evaluator cycles.
189-
bool DebugDumpCycles = false;
190-
165+
191166
/// The path to which we should emit GraphViz output for the complete
192167
/// request-evaluator graph.
193168
std::string RequestEvaluatorGraphVizPath;
194-
195-
/// The upper bound, in bytes, of temporary data that can be
196-
/// allocated by the constraint solver.
197-
unsigned SolverMemoryThreshold = 512 * 1024 * 1024;
198-
199-
unsigned SolverBindingThreshold = 1024 * 1024;
200-
201-
/// The upper bound to number of sub-expressions unsolved
202-
/// before termination of the shrink phrase of the constraint solver.
203-
unsigned SolverShrinkUnsolvedThreshold = 10;
204-
205-
/// Disable the shrink phase of the expression type checker.
206-
bool SolverDisableShrink = false;
207-
208-
/// Disable constraint system performance hacks.
209-
bool DisableConstraintSolverPerformanceHacks = false;
210-
211-
/// Enable experimental operator designated types feature.
212-
bool EnableOperatorDesignatedTypes = false;
213-
169+
170+
/// Whether to dump debug info for request evaluator cycles.
171+
bool DebugDumpCycles = false;
172+
214173
/// Enable SIL type lowering
215174
bool EnableSubstSILFunctionTypesForFunctionValues = false;
216175

217-
/// Enable constraint solver support for experimental
218-
/// operator protocol designator feature.
219-
bool SolverEnableOperatorDesignatedTypes = false;
220-
221176
/// Whether to diagnose an ephemeral to non-ephemeral conversion as an
222177
/// error.
223178
bool DiagnoseInvalidEphemeralnessAsError = false;
@@ -503,6 +458,55 @@ namespace swift {
503458
/// Indicate that the type checker should skip type-checking non-inlinable
504459
/// function bodies.
505460
bool SkipNonInlinableFunctionBodies = false;
461+
462+
///
463+
/// Flags for developers
464+
///
465+
466+
/// Whether we are debugging the constraint solver.
467+
///
468+
/// This option enables verbose debugging output from the constraint
469+
/// solver.
470+
bool DebugConstraintSolver = false;
471+
472+
/// Specific solution attempt for which the constraint
473+
/// solver should be debugged.
474+
unsigned DebugConstraintSolverAttempt = 0;
475+
476+
/// Line numbers to activate the constraint solver debugger.
477+
/// Should be stored sorted.
478+
llvm::SmallVector<unsigned, 4> DebugConstraintSolverOnLines;
479+
480+
/// Debug the generic signatures computed by the generic signature builder.
481+
bool DebugGenericSignatures = false;
482+
483+
/// Triggers llvm fatal_error if typechecker tries to typecheck a decl or an
484+
/// identifier reference with the provided prefix name.
485+
/// This is for testing purposes.
486+
std::string DebugForbidTypecheckPrefix;
487+
488+
/// The upper bound, in bytes, of temporary data that can be
489+
/// allocated by the constraint solver.
490+
unsigned SolverMemoryThreshold = 512 * 1024 * 1024;
491+
492+
unsigned SolverBindingThreshold = 1024 * 1024;
493+
494+
/// The upper bound to number of sub-expressions unsolved
495+
/// before termination of the shrink phrase of the constraint solver.
496+
unsigned SolverShrinkUnsolvedThreshold = 10;
497+
498+
/// Disable the shrink phase of the expression type checker.
499+
bool SolverDisableShrink = false;
500+
501+
/// Enable experimental operator designated types feature.
502+
bool EnableOperatorDesignatedTypes = false;
503+
504+
/// Disable constraint system performance hacks.
505+
bool DisableConstraintSolverPerformanceHacks = false;
506+
507+
/// Enable constraint solver support for experimental
508+
/// operator protocol designator feature.
509+
bool SolverEnableOperatorDesignatedTypes = false;
506510
};
507511
} // end namespace swift
508512

Diff for: lib/Frontend/CompilerInvocation.cpp

+72-69
Original file line numberDiff line numberDiff line change
@@ -284,18 +284,9 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
284284
Opts.EnableSubstSILFunctionTypesForFunctionValues |=
285285
Args.hasArg(OPT_enable_subst_sil_function_types_for_function_values);
286286

287-
Opts.EnableOperatorDesignatedTypes |=
288-
Args.hasArg(OPT_enable_operator_designated_types);
289-
290287
Opts.DiagnoseInvalidEphemeralnessAsError |=
291288
Args.hasArg(OPT_enable_invalid_ephemeralness_as_error);
292289

293-
// Always enable operator designated types for the standard library.
294-
Opts.EnableOperatorDesignatedTypes |= FrontendOpts.ParseStdlib;
295-
296-
Opts.SolverEnableOperatorDesignatedTypes |=
297-
Args.hasArg(OPT_solver_enable_operator_designated_types);
298-
299290
if (auto A = Args.getLastArg(OPT_enable_deserialization_recovery,
300291
OPT_disable_deserialization_recovery)) {
301292
Opts.EnableDeserializationRecovery
@@ -353,9 +344,7 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
353344
Opts.WarnIfASTScopeLookup |= Args.hasArg(OPT_warn_if_astscope_lookup);
354345
Opts.LazyASTScopes |= Args.hasArg(OPT_lazy_astscopes);
355346

356-
Opts.DebugConstraintSolver |= Args.hasArg(OPT_debug_constraints);
357347
Opts.NamedLazyMemberLoading &= !Args.hasArg(OPT_disable_named_lazy_member_loading);
358-
Opts.DebugGenericSignatures |= Args.hasArg(OPT_debug_generic_signatures);
359348

360349
if (Args.hasArg(OPT_verify_syntax_tree)) {
361350
Opts.BuildSyntaxTree = true;
@@ -390,34 +379,7 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
390379
Opts.EnableTestableAttrRequiresTestableModule
391380
= A->getOption().matches(OPT_enable_testable_attr_requires_testable_module);
392381
}
393-
394-
if (const Arg *A = Args.getLastArg(OPT_debug_constraints_attempt)) {
395-
unsigned attempt;
396-
if (StringRef(A->getValue()).getAsInteger(10, attempt)) {
397-
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
398-
A->getAsString(Args), A->getValue());
399-
HadError = true;
400-
} else {
401-
Opts.DebugConstraintSolverAttempt = attempt;
402-
}
403-
}
404-
405-
for (const Arg *A : Args.filtered(OPT_debug_constraints_on_line)) {
406-
unsigned line;
407-
if (StringRef(A->getValue()).getAsInteger(10, line)) {
408-
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
409-
A->getAsString(Args), A->getValue());
410-
HadError = true;
411-
} else {
412-
Opts.DebugConstraintSolverOnLines.push_back(line);
413-
}
414-
}
415-
llvm::sort(Opts.DebugConstraintSolverOnLines);
416382

417-
if (const Arg *A = Args.getLastArg(OPT_debug_forbid_typecheck_prefix)) {
418-
Opts.DebugForbidTypecheckPrefix = A->getValue();
419-
}
420-
421383
if (Args.getLastArg(OPT_debug_cycles))
422384
Opts.DebugDumpCycles = true;
423385

@@ -432,31 +394,6 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
432394
}
433395
}
434396

435-
if (const Arg *A = Args.getLastArg(OPT_solver_memory_threshold)) {
436-
unsigned threshold;
437-
if (StringRef(A->getValue()).getAsInteger(10, threshold)) {
438-
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
439-
A->getAsString(Args), A->getValue());
440-
HadError = true;
441-
} else {
442-
Opts.SolverMemoryThreshold = threshold;
443-
}
444-
}
445-
446-
if (const Arg *A = Args.getLastArg(OPT_solver_shrink_unsolved_threshold)) {
447-
unsigned threshold;
448-
if (StringRef(A->getValue()).getAsInteger(10, threshold)) {
449-
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
450-
A->getAsString(Args), A->getValue());
451-
HadError = true;
452-
} else {
453-
Opts.SolverShrinkUnsolvedThreshold = threshold;
454-
}
455-
}
456-
457-
if (Args.getLastArg(OPT_solver_disable_shrink))
458-
Opts.SolverDisableShrink = true;
459-
460397
if (const Arg *A = Args.getLastArg(OPT_value_recursion_threshold)) {
461398
unsigned threshold;
462399
if (StringRef(A->getValue()).getAsInteger(10, threshold)) {
@@ -528,9 +465,6 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
528465
(Target.isTvOS() && Target.isOSVersionLT(12, 2)) ||
529466
(Target.isWatchOS() && Target.isOSVersionLT(5, 2));
530467

531-
Opts.DisableConstraintSolverPerformanceHacks |=
532-
Args.hasArg(OPT_disable_constraint_solver_performance_hacks);
533-
534468
// Must be processed after any other language options that could affect
535469
// platform conditions.
536470
bool UnsupportedOS, UnsupportedArch;
@@ -557,8 +491,9 @@ static bool ParseTypeCheckerArgs(TypeCheckerOptions &Opts, ArgList &Args,
557491
const FrontendOptions &FrontendOpts) {
558492
using namespace options;
559493

560-
auto setUnsignedIntegerArgument = [&Args, &Diags](
561-
options::ID optionID, unsigned radix, unsigned &valueToSet) {
494+
auto setUnsignedIntegerArgument = [&Args, &Diags](options::ID optionID,
495+
unsigned radix,
496+
unsigned &valueToSet) {
562497
if (const Arg *A = Args.getLastArg(optionID)) {
563498
unsigned attempt;
564499
if (StringRef(A->getValue()).getAsInteger(radix, attempt)) {
@@ -589,7 +524,75 @@ static bool ParseTypeCheckerArgs(TypeCheckerOptions &Opts, ArgList &Args,
589524
// body skipping.
590525
Opts.SkipNonInlinableFunctionBodies |= Args.hasArg(OPT_tbd_is_installapi);
591526

592-
return false;
527+
Opts.DisableConstraintSolverPerformanceHacks |=
528+
Args.hasArg(OPT_disable_constraint_solver_performance_hacks);
529+
530+
Opts.EnableOperatorDesignatedTypes |=
531+
Args.hasArg(OPT_enable_operator_designated_types);
532+
533+
// Always enable operator designated types for the standard library.
534+
Opts.EnableOperatorDesignatedTypes |= FrontendOpts.ParseStdlib;
535+
536+
Opts.SolverEnableOperatorDesignatedTypes |=
537+
Args.hasArg(OPT_solver_enable_operator_designated_types);
538+
539+
Opts.DebugConstraintSolver |= Args.hasArg(OPT_debug_constraints);
540+
Opts.DebugGenericSignatures |= Args.hasArg(OPT_debug_generic_signatures);
541+
542+
bool HadError = false;
543+
if (const Arg *A = Args.getLastArg(OPT_debug_constraints_attempt)) {
544+
unsigned attempt;
545+
if (StringRef(A->getValue()).getAsInteger(10, attempt)) {
546+
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
547+
A->getAsString(Args), A->getValue());
548+
HadError = true;
549+
} else {
550+
Opts.DebugConstraintSolverAttempt = attempt;
551+
}
552+
}
553+
554+
for (const Arg *A : Args.filtered(OPT_debug_constraints_on_line)) {
555+
unsigned line;
556+
if (StringRef(A->getValue()).getAsInteger(10, line)) {
557+
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
558+
A->getAsString(Args), A->getValue());
559+
HadError = true;
560+
} else {
561+
Opts.DebugConstraintSolverOnLines.push_back(line);
562+
}
563+
}
564+
llvm::sort(Opts.DebugConstraintSolverOnLines);
565+
566+
if (const Arg *A = Args.getLastArg(OPT_debug_forbid_typecheck_prefix)) {
567+
Opts.DebugForbidTypecheckPrefix = A->getValue();
568+
}
569+
570+
if (const Arg *A = Args.getLastArg(OPT_solver_memory_threshold)) {
571+
unsigned threshold;
572+
if (StringRef(A->getValue()).getAsInteger(10, threshold)) {
573+
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
574+
A->getAsString(Args), A->getValue());
575+
HadError = true;
576+
} else {
577+
Opts.SolverMemoryThreshold = threshold;
578+
}
579+
}
580+
581+
if (const Arg *A = Args.getLastArg(OPT_solver_shrink_unsolved_threshold)) {
582+
unsigned threshold;
583+
if (StringRef(A->getValue()).getAsInteger(10, threshold)) {
584+
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
585+
A->getAsString(Args), A->getValue());
586+
HadError = true;
587+
} else {
588+
Opts.SolverShrinkUnsolvedThreshold = threshold;
589+
}
590+
}
591+
592+
if (Args.getLastArg(OPT_solver_disable_shrink))
593+
Opts.SolverDisableShrink = true;
594+
595+
return HadError;
593596
}
594597

595598
static bool ParseClangImporterArgs(ClangImporterOptions &Opts,

Diff for: lib/Immediate/REPL.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1162,9 +1162,9 @@ class REPLEnvironment {
11621162
if (Tok.getText() == "debug") {
11631163
L.lex(Tok);
11641164
if (Tok.getText() == "on") {
1165-
CI.getASTContext().LangOpts.DebugConstraintSolver = true;
1165+
CI.getASTContext().TypeCheckerOpts.DebugConstraintSolver = true;
11661166
} else if (Tok.getText() == "off") {
1167-
CI.getASTContext().LangOpts.DebugConstraintSolver = false;
1167+
CI.getASTContext().TypeCheckerOpts.DebugConstraintSolver = false;
11681168
} else {
11691169
llvm::outs() << "Unknown :constraints debug command; try :help\n";
11701170
}

Diff for: lib/Parse/ParseDecl.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -6927,7 +6927,7 @@ Parser::parseDeclOperatorImpl(SourceLoc OperatorLoc, Identifier Name,
69276927
return makeParserCodeCompletionResult<OperatorDecl>();
69286928
}
69296929

6930-
if (Context.LangOpts.EnableOperatorDesignatedTypes) {
6930+
if (Context.TypeCheckerOpts.EnableOperatorDesignatedTypes) {
69316931
if (Tok.is(tok::identifier)) {
69326932
SyntaxParsingContext GroupCtxt(SyntaxContext,
69336933
SyntaxKind::IdentifierList);

Diff for: lib/Sema/CSBindings.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ ConstraintSystem::determineBestBindings() {
8585
}
8686
}
8787

88-
if (getASTContext().LangOpts.DebugConstraintSolver) {
88+
if (getASTContext().TypeCheckerOpts.DebugConstraintSolver) {
8989
auto &log = getASTContext().TypeCheckerDebug->getStream();
9090
bindings.dump(typeVar, log, solverState->depth * 2);
9191
}

Diff for: lib/Sema/CSGen.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -3776,7 +3776,7 @@ Type ConstraintSystem::generateConstraints(Pattern *pattern,
37763776
}
37773777

37783778
void ConstraintSystem::optimizeConstraints(Expr *e) {
3779-
if (getASTContext().LangOpts.DisableConstraintSolverPerformanceHacks)
3779+
if (getASTContext().TypeCheckerOpts.DisableConstraintSolverPerformanceHacks)
37803780
return;
37813781

37823782
SmallVector<Expr *, 16> linkedExprs;

0 commit comments

Comments
 (0)