Skip to content

Commit 411d396

Browse files
authored
Merge pull request #86695 from xedin/remove-old-perf-hacks
[ConstraintSystem] Remove old performance hacks from the solver and related flags
2 parents 974c2e7 + 1e77e79 commit 411d396

File tree

14 files changed

+44
-1771
lines changed

14 files changed

+44
-1771
lines changed

include/swift/AST/TypeCheckRequests.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5532,22 +5532,6 @@ class BindExtensionsRequest
55325532
bool isCached() const { return true; }
55335533
};
55345534

5535-
class ModuleHasTypeCheckerPerformanceHacksEnabledRequest
5536-
: public SimpleRequest<ModuleHasTypeCheckerPerformanceHacksEnabledRequest,
5537-
bool(const ModuleDecl *),
5538-
RequestFlags::Cached> {
5539-
public:
5540-
using SimpleRequest::SimpleRequest;
5541-
5542-
private:
5543-
friend SimpleRequest;
5544-
5545-
bool evaluate(Evaluator &evaluator, const ModuleDecl *module) const;
5546-
5547-
public:
5548-
bool isCached() const { return true; }
5549-
};
5550-
55515535
class AvailabilityDomainForDeclRequest
55525536
: public SimpleRequest<AvailabilityDomainForDeclRequest,
55535537
std::optional<AvailabilityDomain>(ValueDecl *),

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -659,10 +659,6 @@ SWIFT_REQUEST(TypeChecker, BindExtensionsRequest,
659659
evaluator::SideEffect(ModuleDecl *),
660660
Cached, NoLocationInfo)
661661

662-
SWIFT_REQUEST(TypeChecker, ModuleHasTypeCheckerPerformanceHacksEnabledRequest,
663-
bool(const ModuleDecl *),
664-
Cached, NoLocationInfo)
665-
666662
SWIFT_REQUEST(TypeChecker, AvailabilityDomainForDeclRequest,
667663
std::optional<AvailabilityDomain>(ValueDecl *),
668664
Cached | SplitCached, NoLocationInfo)

include/swift/Basic/BlockListAction.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ BLOCKLIST_ACTION(ShouldUseLayoutStringValueWitnesses)
2626
BLOCKLIST_ACTION(ShouldDisableOwnershipVerification)
2727
BLOCKLIST_ACTION(SkipEmittingFineModuleTrace)
2828
BLOCKLIST_ACTION(SkipIndexingModule)
29-
BLOCKLIST_ACTION(ShouldUseTypeCheckerPerfHacks)
3029
BLOCKLIST_ACTION(DisableModuleSelectorsInModuleInterface)
3130

3231
#undef BLOCKLIST_ACTION

include/swift/Basic/LangOptions.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -990,9 +990,6 @@ namespace swift {
990990
/// Enable experimental operator designated types feature.
991991
bool EnableOperatorDesignatedTypes = false;
992992

993-
/// Enable old constraint system performance hacks.
994-
bool EnableConstraintSolverPerformanceHacks = false;
995-
996993
/// See \ref FrontendOptions.PrintFullConvention
997994
bool PrintFullConvention = false;
998995

include/swift/Option/FrontendOptions.td

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -919,9 +919,6 @@ def solver_enable_prepared_overloads : Flag<["-"], "solver-enable-prepared-overl
919919
def solver_disable_splitter : Flag<["-"], "solver-disable-splitter">,
920920
HelpText<"Disable the component splitter phase of expression type checking">;
921921

922-
def enable_constraint_solver_performance_hacks : Flag<["-"], "enable-constraint-solver-performance-hacks">,
923-
HelpText<"Enable all the old hacks in the constraint solver">;
924-
925922
def enable_operator_designated_types :
926923
Flag<["-"], "enable-operator-designated-types">,
927924
HelpText<"Enable operator designated types">;

include/swift/Sema/ConstraintSystem.h

Lines changed: 0 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1964,9 +1964,6 @@ enum class ConstraintSystemFlags {
19641964

19651965
/// Disable macro expansions.
19661966
DisableMacroExpansions = 0x40,
1967-
1968-
/// Enable old type-checker performance hacks.
1969-
EnablePerformanceHacks = 0x80,
19701967
};
19711968

19721969
/// Options that affect the constraint system as a whole.
@@ -2466,74 +2463,6 @@ class ConstraintSystem {
24662463
SynthesizedConformances;
24672464

24682465
private:
2469-
/// Describe the candidate expression for partial solving.
2470-
/// This class used by shrink & solve methods which apply
2471-
/// variation of directional path consistency algorithm in attempt
2472-
/// to reduce scopes of the overload sets (disjunctions) in the system.
2473-
class Candidate {
2474-
Expr *E;
2475-
DeclContext *DC;
2476-
llvm::BumpPtrAllocator &Allocator;
2477-
2478-
// Contextual Information.
2479-
Type CT;
2480-
ContextualTypePurpose CTP;
2481-
2482-
public:
2483-
Candidate(ConstraintSystem &cs, Expr *expr, Type ct = Type(),
2484-
ContextualTypePurpose ctp = ContextualTypePurpose::CTP_Unused)
2485-
: E(expr), DC(cs.DC), Allocator(cs.Allocator), CT(ct), CTP(ctp) {}
2486-
2487-
/// Return underlying expression.
2488-
Expr *getExpr() const { return E; }
2489-
2490-
/// Try to solve this candidate sub-expression
2491-
/// and re-write it's OSR domains afterwards.
2492-
///
2493-
/// \param shrunkExprs The set of expressions which
2494-
/// domains have been successfully shrunk so far.
2495-
///
2496-
/// \returns true on solver failure, false otherwise.
2497-
bool solve(llvm::SmallSetVector<OverloadSetRefExpr *, 4> &shrunkExprs);
2498-
2499-
/// Apply solutions found by solver as reduced OSR sets for
2500-
/// for current and all of it's sub-expressions.
2501-
///
2502-
/// \param solutions The solutions found by running solver on the
2503-
/// this candidate expression.
2504-
///
2505-
/// \param shrunkExprs The set of expressions which
2506-
/// domains have been successfully shrunk so far.
2507-
void applySolutions(
2508-
llvm::SmallVectorImpl<Solution> &solutions,
2509-
llvm::SmallSetVector<OverloadSetRefExpr *, 4> &shrunkExprs) const;
2510-
2511-
/// Check if attempt at solving of the candidate makes sense given
2512-
/// the current conditions - number of shrunk domains which is related
2513-
/// to the given candidate over the total number of disjunctions present.
2514-
static bool
2515-
isTooComplexGiven(ConstraintSystem *const cs,
2516-
llvm::SmallSetVector<OverloadSetRefExpr *, 4> &shrunkExprs) {
2517-
SmallVector<Constraint *, 8> disjunctions;
2518-
cs->collectDisjunctions(disjunctions);
2519-
2520-
unsigned unsolvedDisjunctions = disjunctions.size();
2521-
for (auto *disjunction : disjunctions) {
2522-
auto *locator = disjunction->getLocator();
2523-
if (!locator)
2524-
continue;
2525-
2526-
if (auto *OSR = getAsExpr<OverloadSetRefExpr>(locator->getAnchor())) {
2527-
if (shrunkExprs.count(OSR) > 0)
2528-
--unsolvedDisjunctions;
2529-
}
2530-
}
2531-
2532-
// The threshold used to be `TypeCheckerOpts.SolverShrinkUnsolvedThreshold`
2533-
return unsolvedDisjunctions >= 10;
2534-
}
2535-
};
2536-
25372466
/// Describes the current solver state.
25382467
struct SolverState {
25392468
SolverState(ConstraintSystem &cs,
@@ -3490,12 +3419,6 @@ class ConstraintSystem {
34903419
return Options.contains(ConstraintSystemFlags::ForCodeCompletion);
34913420
}
34923421

3493-
/// Check whether old type-checker performance hacks has been explicitly
3494-
/// enabled.
3495-
bool performanceHacksEnabled() const {
3496-
return Options.contains(ConstraintSystemFlags::EnablePerformanceHacks);
3497-
}
3498-
34993422
/// Log and record the application of the fix. Return true iff any
35003423
/// subsequent solution would be worse than the best known solution.
35013424
bool recordFix(ConstraintFix *fix, unsigned impact = 1,
@@ -5347,24 +5270,12 @@ class ConstraintSystem {
53475270
/// \returns true if an error occurred, false otherwise.
53485271
bool solveSimplified(SmallVectorImpl<Solution> &solutions);
53495272

5350-
/// Find reduced domains of disjunction constraints for given
5351-
/// expression, this is achieved to solving individual sub-expressions
5352-
/// and combining resolving types. Such algorithm is called directional
5353-
/// path consistency because it goes from children to parents for all
5354-
/// related sub-expressions taking union of their domains.
5355-
///
5356-
/// \param expr The expression to find reductions for.
5357-
void shrink(Expr *expr);
5358-
53595273
/// Pick a disjunction from the InactiveConstraints list.
53605274
///
53615275
/// \returns The selected disjunction and a set of it's favored choices.
53625276
std::optional<std::pair<Constraint *, llvm::TinyPtrVector<Constraint *>>>
53635277
selectDisjunction();
53645278

5365-
/// The old method that is only used when performance hacks are enabled.
5366-
Constraint *selectDisjunctionWithHacks();
5367-
53685279
/// Pick a conjunction from the InactiveConstraints list.
53695280
///
53705281
/// \returns The selected conjunction.
@@ -5556,11 +5467,6 @@ class ConstraintSystem {
55565467
bool applySolutionToBody(TapExpr *tapExpr,
55575468
SyntacticElementTargetRewriter &rewriter);
55585469

5559-
/// Reorder the disjunctive clauses for a given expression to
5560-
/// increase the likelihood that a favored constraint will be successfully
5561-
/// resolved before any others.
5562-
void optimizeConstraints(Expr *e);
5563-
55645470
/// Set the current sub-expression (of a multi-statement closure, etc) for
55655471
/// the purposes of diagnosing "reasonable time" errors.
55665472
void startExpression(ASTNode node);

lib/Frontend/CompilerInvocation.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2078,9 +2078,6 @@ static bool ParseTypeCheckerArgs(TypeCheckerOptions &Opts, ArgList &Args,
20782078
SWIFT_ONONE_SUPPORT);
20792079
}
20802080

2081-
Opts.EnableConstraintSolverPerformanceHacks |=
2082-
Args.hasArg(OPT_enable_constraint_solver_performance_hacks);
2083-
20842081
Opts.EnableOperatorDesignatedTypes |=
20852082
Args.hasArg(OPT_enable_operator_designated_types);
20862083

0 commit comments

Comments
 (0)