@@ -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
// /
@@ -2260,10 +2268,6 @@ class ConstraintSystem {
2260
2268
2261
2269
llvm::SetVector<TypeVariableType *> TypeVariables;
2262
2270
2263
- // / Maps expressions to types for choosing a favored overload
2264
- // / type in a disjunction constraint.
2265
- llvm::DenseMap<Expr *, TypeBase *> FavoredTypes;
2266
-
2267
2271
// / Maps discovered closures to their types inferred
2268
2272
// / from declared parameters/result and body.
2269
2273
// /
@@ -2474,74 +2478,6 @@ class ConstraintSystem {
2474
2478
SynthesizedConformances;
2475
2479
2476
2480
private:
2477
- // / Describe the candidate expression for partial solving.
2478
- // / This class used by shrink & solve methods which apply
2479
- // / variation of directional path consistency algorithm in attempt
2480
- // / to reduce scopes of the overload sets (disjunctions) in the system.
2481
- class Candidate {
2482
- Expr *E;
2483
- DeclContext *DC;
2484
- llvm::BumpPtrAllocator &Allocator;
2485
-
2486
- // Contextual Information.
2487
- Type CT;
2488
- ContextualTypePurpose CTP;
2489
-
2490
- public:
2491
- Candidate (ConstraintSystem &cs, Expr *expr, Type ct = Type(),
2492
- ContextualTypePurpose ctp = ContextualTypePurpose::CTP_Unused)
2493
- : E(expr), DC(cs.DC), Allocator(cs.Allocator), CT(ct), CTP(ctp) {}
2494
-
2495
- // / Return underlying expression.
2496
- Expr *getExpr () const { return E; }
2497
-
2498
- // / Try to solve this candidate sub-expression
2499
- // / and re-write it's OSR domains afterwards.
2500
- // /
2501
- // / \param shrunkExprs The set of expressions which
2502
- // / domains have been successfully shrunk so far.
2503
- // /
2504
- // / \returns true on solver failure, false otherwise.
2505
- bool solve (llvm::SmallSetVector<OverloadSetRefExpr *, 4 > &shrunkExprs);
2506
-
2507
- // / Apply solutions found by solver as reduced OSR sets for
2508
- // / for current and all of it's sub-expressions.
2509
- // /
2510
- // / \param solutions The solutions found by running solver on the
2511
- // / this candidate expression.
2512
- // /
2513
- // / \param shrunkExprs The set of expressions which
2514
- // / domains have been successfully shrunk so far.
2515
- void applySolutions (
2516
- llvm::SmallVectorImpl<Solution> &solutions,
2517
- llvm::SmallSetVector<OverloadSetRefExpr *, 4 > &shrunkExprs) const ;
2518
-
2519
- // / Check if attempt at solving of the candidate makes sense given
2520
- // / the current conditions - number of shrunk domains which is related
2521
- // / to the given candidate over the total number of disjunctions present.
2522
- static bool
2523
- isTooComplexGiven (ConstraintSystem *const cs,
2524
- llvm::SmallSetVector<OverloadSetRefExpr *, 4 > &shrunkExprs) {
2525
- SmallVector<Constraint *, 8 > disjunctions;
2526
- cs->collectDisjunctions (disjunctions);
2527
-
2528
- unsigned unsolvedDisjunctions = disjunctions.size ();
2529
- for (auto *disjunction : disjunctions) {
2530
- auto *locator = disjunction->getLocator ();
2531
- if (!locator)
2532
- continue ;
2533
-
2534
- if (auto *OSR = getAsExpr<OverloadSetRefExpr>(locator->getAnchor ())) {
2535
- if (shrunkExprs.count (OSR) > 0 )
2536
- --unsolvedDisjunctions;
2537
- }
2538
- }
2539
-
2540
- // The threshold used to be `TypeCheckerOpts.SolverShrinkUnsolvedThreshold`
2541
- return unsolvedDisjunctions >= 10 ;
2542
- }
2543
- };
2544
-
2545
2481
// / Describes the current solver state.
2546
2482
struct SolverState {
2547
2483
SolverState (ConstraintSystem &cs,
@@ -3065,15 +3001,6 @@ class ConstraintSystem {
3065
3001
return nullptr ;
3066
3002
}
3067
3003
3068
- TypeBase* getFavoredType (Expr *E) {
3069
- assert (E != nullptr );
3070
- return this ->FavoredTypes [E];
3071
- }
3072
- void setFavoredType (Expr *E, TypeBase *T) {
3073
- assert (E != nullptr );
3074
- this ->FavoredTypes [E] = T;
3075
- }
3076
-
3077
3004
// / Set the type in our type map for the given node, and record the change
3078
3005
// / in the trail.
3079
3006
// /
@@ -5367,19 +5294,11 @@ class ConstraintSystem {
5367
5294
// / \returns true if an error occurred, false otherwise.
5368
5295
bool solveSimplified (SmallVectorImpl<Solution> &solutions);
5369
5296
5370
- // / Find reduced domains of disjunction constraints for given
5371
- // / expression, this is achieved to solving individual sub-expressions
5372
- // / and combining resolving types. Such algorithm is called directional
5373
- // / path consistency because it goes from children to parents for all
5374
- // / related sub-expressions taking union of their domains.
5375
- // /
5376
- // / \param expr The expression to find reductions for.
5377
- void shrink (Expr *expr);
5378
-
5379
5297
// / Pick a disjunction from the InactiveConstraints list.
5380
5298
// /
5381
- // / \returns The selected disjunction.
5382
- Constraint *selectDisjunction ();
5299
+ // / \returns The selected disjunction and a set of it's favored choices.
5300
+ std::optional<std::pair<Constraint *, llvm::TinyPtrVector<Constraint *>>>
5301
+ selectDisjunction ();
5383
5302
5384
5303
// / Pick a conjunction from the InactiveConstraints list.
5385
5304
// /
@@ -5568,11 +5487,6 @@ class ConstraintSystem {
5568
5487
bool applySolutionToBody (TapExpr *tapExpr,
5569
5488
SyntacticElementTargetRewriter &rewriter);
5570
5489
5571
- // / Reorder the disjunctive clauses for a given expression to
5572
- // / increase the likelihood that a favored constraint will be successfully
5573
- // / resolved before any others.
5574
- void optimizeConstraints (Expr *e);
5575
-
5576
5490
void startExpressionTimer (ExpressionTimer::AnchorType anchor);
5577
5491
5578
5492
// / Determine if we've already explored too many paths in an
@@ -6313,7 +6227,8 @@ class DisjunctionChoiceProducer : public BindingProducer<DisjunctionChoice> {
6313
6227
public:
6314
6228
using Element = DisjunctionChoice;
6315
6229
6316
- DisjunctionChoiceProducer (ConstraintSystem &cs, Constraint *disjunction)
6230
+ DisjunctionChoiceProducer (ConstraintSystem &cs, Constraint *disjunction,
6231
+ llvm::TinyPtrVector<Constraint *> &favorites)
6317
6232
: BindingProducer(cs, disjunction->shouldRememberChoice ()
6318
6233
? disjunction->getLocator()
6319
6234
: nullptr),
@@ -6323,6 +6238,11 @@ class DisjunctionChoiceProducer : public BindingProducer<DisjunctionChoice> {
6323
6238
assert (disjunction->getKind () == ConstraintKind::Disjunction);
6324
6239
assert (!disjunction->shouldRememberChoice () || disjunction->getLocator ());
6325
6240
6241
+ // Mark constraints as favored. This information
6242
+ // is going to be used by partitioner.
6243
+ for (auto *choice : favorites)
6244
+ cs.favorConstraint (choice);
6245
+
6326
6246
// Order and partition the disjunction choices.
6327
6247
partitionDisjunction (Ordering, PartitionBeginning);
6328
6248
}
@@ -6367,8 +6287,9 @@ class DisjunctionChoiceProducer : public BindingProducer<DisjunctionChoice> {
6367
6287
// Partition the choices in the disjunction into groups that we will
6368
6288
// iterate over in an order appropriate to attempt to stop before we
6369
6289
// have to visit all of the options.
6370
- void partitionDisjunction (SmallVectorImpl<unsigned > &Ordering,
6371
- SmallVectorImpl<unsigned > &PartitionBeginning);
6290
+ void
6291
+ partitionDisjunction (SmallVectorImpl<unsigned > &Ordering,
6292
+ SmallVectorImpl<unsigned > &PartitionBeginning);
6372
6293
6373
6294
// / Partition the choices in the range \c first to \c last into groups and
6374
6295
// / order the groups in the best order to attempt based on the argument
0 commit comments