@@ -488,6 +488,14 @@ class TypeVariableType::Implementation {
488
488
// / literal (represented by `ArrayExpr` and `DictionaryExpr` in AST).
489
489
bool isCollectionLiteralType () const ;
490
490
491
+ // / Determine whether this type variable represents a literal such
492
+ // / as an integer value, a floating-point value with and without a sign.
493
+ bool isNumberLiteralType () const ;
494
+
495
+ // / Determine whether this type variable represents a result type of a
496
+ // / function call.
497
+ bool isFunctionResult () const ;
498
+
491
499
// / Retrieve the representative of the equivalence class to which this
492
500
// / type variable belongs.
493
501
// /
@@ -2242,10 +2250,6 @@ class ConstraintSystem {
2242
2250
2243
2251
llvm::SetVector<TypeVariableType *> TypeVariables;
2244
2252
2245
- // / Maps expressions to types for choosing a favored overload
2246
- // / type in a disjunction constraint.
2247
- llvm::DenseMap<Expr *, TypeBase *> FavoredTypes;
2248
-
2249
2253
// / Maps discovered closures to their types inferred
2250
2254
// / from declared parameters/result and body.
2251
2255
// /
@@ -2458,74 +2462,6 @@ class ConstraintSystem {
2458
2462
SynthesizedConformances;
2459
2463
2460
2464
private:
2461
- // / Describe the candidate expression for partial solving.
2462
- // / This class used by shrink & solve methods which apply
2463
- // / variation of directional path consistency algorithm in attempt
2464
- // / to reduce scopes of the overload sets (disjunctions) in the system.
2465
- class Candidate {
2466
- Expr *E;
2467
- DeclContext *DC;
2468
- llvm::BumpPtrAllocator &Allocator;
2469
-
2470
- // Contextual Information.
2471
- Type CT;
2472
- ContextualTypePurpose CTP;
2473
-
2474
- public:
2475
- Candidate (ConstraintSystem &cs, Expr *expr, Type ct = Type(),
2476
- ContextualTypePurpose ctp = ContextualTypePurpose::CTP_Unused)
2477
- : E(expr), DC(cs.DC), Allocator(cs.Allocator), CT(ct), CTP(ctp) {}
2478
-
2479
- // / Return underlying expression.
2480
- Expr *getExpr () const { return E; }
2481
-
2482
- // / Try to solve this candidate sub-expression
2483
- // / and re-write it's OSR domains afterwards.
2484
- // /
2485
- // / \param shrunkExprs The set of expressions which
2486
- // / domains have been successfully shrunk so far.
2487
- // /
2488
- // / \returns true on solver failure, false otherwise.
2489
- bool solve (llvm::SmallSetVector<OverloadSetRefExpr *, 4 > &shrunkExprs);
2490
-
2491
- // / Apply solutions found by solver as reduced OSR sets for
2492
- // / for current and all of it's sub-expressions.
2493
- // /
2494
- // / \param solutions The solutions found by running solver on the
2495
- // / this candidate expression.
2496
- // /
2497
- // / \param shrunkExprs The set of expressions which
2498
- // / domains have been successfully shrunk so far.
2499
- void applySolutions (
2500
- llvm::SmallVectorImpl<Solution> &solutions,
2501
- llvm::SmallSetVector<OverloadSetRefExpr *, 4 > &shrunkExprs) const ;
2502
-
2503
- // / Check if attempt at solving of the candidate makes sense given
2504
- // / the current conditions - number of shrunk domains which is related
2505
- // / to the given candidate over the total number of disjunctions present.
2506
- static bool
2507
- isTooComplexGiven (ConstraintSystem *const cs,
2508
- llvm::SmallSetVector<OverloadSetRefExpr *, 4 > &shrunkExprs) {
2509
- SmallVector<Constraint *, 8 > disjunctions;
2510
- cs->collectDisjunctions (disjunctions);
2511
-
2512
- unsigned unsolvedDisjunctions = disjunctions.size ();
2513
- for (auto *disjunction : disjunctions) {
2514
- auto *locator = disjunction->getLocator ();
2515
- if (!locator)
2516
- continue ;
2517
-
2518
- if (auto *OSR = getAsExpr<OverloadSetRefExpr>(locator->getAnchor ())) {
2519
- if (shrunkExprs.count (OSR) > 0 )
2520
- --unsolvedDisjunctions;
2521
- }
2522
- }
2523
-
2524
- // The threshold used to be `TypeCheckerOpts.SolverShrinkUnsolvedThreshold`
2525
- return unsolvedDisjunctions >= 10 ;
2526
- }
2527
- };
2528
-
2529
2465
// / Describes the current solver state.
2530
2466
struct SolverState {
2531
2467
SolverState (ConstraintSystem &cs,
@@ -3049,15 +2985,6 @@ class ConstraintSystem {
3049
2985
return nullptr ;
3050
2986
}
3051
2987
3052
- TypeBase* getFavoredType (Expr *E) {
3053
- assert (E != nullptr );
3054
- return this ->FavoredTypes [E];
3055
- }
3056
- void setFavoredType (Expr *E, TypeBase *T) {
3057
- assert (E != nullptr );
3058
- this ->FavoredTypes [E] = T;
3059
- }
3060
-
3061
2988
// / Set the type in our type map for the given node, and record the change
3062
2989
// / in the trail.
3063
2990
// /
@@ -5318,19 +5245,11 @@ class ConstraintSystem {
5318
5245
// / \returns true if an error occurred, false otherwise.
5319
5246
bool solveSimplified (SmallVectorImpl<Solution> &solutions);
5320
5247
5321
- // / Find reduced domains of disjunction constraints for given
5322
- // / expression, this is achieved to solving individual sub-expressions
5323
- // / and combining resolving types. Such algorithm is called directional
5324
- // / path consistency because it goes from children to parents for all
5325
- // / related sub-expressions taking union of their domains.
5326
- // /
5327
- // / \param expr The expression to find reductions for.
5328
- void shrink (Expr *expr);
5329
-
5330
5248
// / Pick a disjunction from the InactiveConstraints list.
5331
5249
// /
5332
- // / \returns The selected disjunction.
5333
- Constraint *selectDisjunction ();
5250
+ // / \returns The selected disjunction and a set of it's favored choices.
5251
+ std::optional<std::pair<Constraint *, llvm::TinyPtrVector<Constraint *>>>
5252
+ selectDisjunction ();
5334
5253
5335
5254
// / Pick a conjunction from the InactiveConstraints list.
5336
5255
// /
@@ -5519,11 +5438,6 @@ class ConstraintSystem {
5519
5438
bool applySolutionToBody (TapExpr *tapExpr,
5520
5439
SyntacticElementTargetRewriter &rewriter);
5521
5440
5522
- // / Reorder the disjunctive clauses for a given expression to
5523
- // / increase the likelihood that a favored constraint will be successfully
5524
- // / resolved before any others.
5525
- void optimizeConstraints (Expr *e);
5526
-
5527
5441
void startExpressionTimer (ExpressionTimer::AnchorType anchor);
5528
5442
5529
5443
// / Determine if we've already explored too many paths in an
@@ -6264,7 +6178,8 @@ class DisjunctionChoiceProducer : public BindingProducer<DisjunctionChoice> {
6264
6178
public:
6265
6179
using Element = DisjunctionChoice;
6266
6180
6267
- DisjunctionChoiceProducer (ConstraintSystem &cs, Constraint *disjunction)
6181
+ DisjunctionChoiceProducer (ConstraintSystem &cs, Constraint *disjunction,
6182
+ llvm::TinyPtrVector<Constraint *> &favorites)
6268
6183
: BindingProducer(cs, disjunction->shouldRememberChoice ()
6269
6184
? disjunction->getLocator()
6270
6185
: nullptr),
@@ -6274,6 +6189,11 @@ class DisjunctionChoiceProducer : public BindingProducer<DisjunctionChoice> {
6274
6189
assert (disjunction->getKind () == ConstraintKind::Disjunction);
6275
6190
assert (!disjunction->shouldRememberChoice () || disjunction->getLocator ());
6276
6191
6192
+ // Mark constraints as favored. This information
6193
+ // is going to be used by partitioner.
6194
+ for (auto *choice : favorites)
6195
+ cs.favorConstraint (choice);
6196
+
6277
6197
// Order and partition the disjunction choices.
6278
6198
partitionDisjunction (Ordering, PartitionBeginning);
6279
6199
}
@@ -6318,8 +6238,9 @@ class DisjunctionChoiceProducer : public BindingProducer<DisjunctionChoice> {
6318
6238
// Partition the choices in the disjunction into groups that we will
6319
6239
// iterate over in an order appropriate to attempt to stop before we
6320
6240
// have to visit all of the options.
6321
- void partitionDisjunction (SmallVectorImpl<unsigned > &Ordering,
6322
- SmallVectorImpl<unsigned > &PartitionBeginning);
6241
+ void
6242
+ partitionDisjunction (SmallVectorImpl<unsigned > &Ordering,
6243
+ SmallVectorImpl<unsigned > &PartitionBeginning);
6323
6244
6324
6245
// / Partition the choices in the range \c first to \c last into groups and
6325
6246
// / order the groups in the best order to attempt based on the argument
0 commit comments