@@ -497,6 +497,14 @@ class TypeVariableType::Implementation {
497
497
// / literal (represented by `ArrayExpr` and `DictionaryExpr` in AST).
498
498
bool isCollectionLiteralType () const ;
499
499
500
+ // / Determine whether this type variable represents a literal such
501
+ // / as an integer value, a floating-point value with and without a sign.
502
+ bool isNumberLiteralType () const ;
503
+
504
+ // / Determine whether this type variable represents a result type of a
505
+ // / function call.
506
+ bool isFunctionResult () const ;
507
+
500
508
// / Retrieve the representative of the equivalence class to which this
501
509
// / type variable belongs.
502
510
// /
@@ -2203,10 +2211,6 @@ class ConstraintSystem {
2203
2211
2204
2212
llvm::SetVector<TypeVariableType *> TypeVariables;
2205
2213
2206
- // / Maps expressions to types for choosing a favored overload
2207
- // / type in a disjunction constraint.
2208
- llvm::DenseMap<Expr *, TypeBase *> FavoredTypes;
2209
-
2210
2214
// / Maps discovered closures to their types inferred
2211
2215
// / from declared parameters/result and body.
2212
2216
// /
@@ -2424,75 +2428,6 @@ class ConstraintSystem {
2424
2428
SynthesizedConformances;
2425
2429
2426
2430
private:
2427
- // / Describe the candidate expression for partial solving.
2428
- // / This class used by shrink & solve methods which apply
2429
- // / variation of directional path consistency algorithm in attempt
2430
- // / to reduce scopes of the overload sets (disjunctions) in the system.
2431
- class Candidate {
2432
- Expr *E;
2433
- DeclContext *DC;
2434
- llvm::BumpPtrAllocator &Allocator;
2435
-
2436
- // Contextual Information.
2437
- Type CT;
2438
- ContextualTypePurpose CTP;
2439
-
2440
- public:
2441
- Candidate (ConstraintSystem &cs, Expr *expr, Type ct = Type(),
2442
- ContextualTypePurpose ctp = ContextualTypePurpose::CTP_Unused)
2443
- : E(expr), DC(cs.DC), Allocator(cs.Allocator), CT(ct), CTP(ctp) {}
2444
-
2445
- // / Return underlying expression.
2446
- Expr *getExpr () const { return E; }
2447
-
2448
- // / Try to solve this candidate sub-expression
2449
- // / and re-write it's OSR domains afterwards.
2450
- // /
2451
- // / \param shrunkExprs The set of expressions which
2452
- // / domains have been successfully shrunk so far.
2453
- // /
2454
- // / \returns true on solver failure, false otherwise.
2455
- bool solve (llvm::SmallSetVector<OverloadSetRefExpr *, 4 > &shrunkExprs);
2456
-
2457
- // / Apply solutions found by solver as reduced OSR sets for
2458
- // / for current and all of it's sub-expressions.
2459
- // /
2460
- // / \param solutions The solutions found by running solver on the
2461
- // / this candidate expression.
2462
- // /
2463
- // / \param shrunkExprs The set of expressions which
2464
- // / domains have been successfully shrunk so far.
2465
- void applySolutions (
2466
- llvm::SmallVectorImpl<Solution> &solutions,
2467
- llvm::SmallSetVector<OverloadSetRefExpr *, 4 > &shrunkExprs) const ;
2468
-
2469
- // / Check if attempt at solving of the candidate makes sense given
2470
- // / the current conditions - number of shrunk domains which is related
2471
- // / to the given candidate over the total number of disjunctions present.
2472
- static bool
2473
- isTooComplexGiven (ConstraintSystem *const cs,
2474
- llvm::SmallSetVector<OverloadSetRefExpr *, 4 > &shrunkExprs) {
2475
- SmallVector<Constraint *, 8 > disjunctions;
2476
- cs->collectDisjunctions (disjunctions);
2477
-
2478
- unsigned unsolvedDisjunctions = disjunctions.size ();
2479
- for (auto *disjunction : disjunctions) {
2480
- auto *locator = disjunction->getLocator ();
2481
- if (!locator)
2482
- continue ;
2483
-
2484
- if (auto *OSR = getAsExpr<OverloadSetRefExpr>(locator->getAnchor ())) {
2485
- if (shrunkExprs.count (OSR) > 0 )
2486
- --unsolvedDisjunctions;
2487
- }
2488
- }
2489
-
2490
- unsigned threshold =
2491
- cs->getASTContext ().TypeCheckerOpts .SolverShrinkUnsolvedThreshold ;
2492
- return unsolvedDisjunctions >= threshold;
2493
- }
2494
- };
2495
-
2496
2431
// / Describes the current solver state.
2497
2432
struct SolverState {
2498
2433
SolverState (ConstraintSystem &cs,
@@ -3016,15 +2951,6 @@ class ConstraintSystem {
3016
2951
return nullptr ;
3017
2952
}
3018
2953
3019
- TypeBase* getFavoredType (Expr *E) {
3020
- assert (E != nullptr );
3021
- return this ->FavoredTypes [E];
3022
- }
3023
- void setFavoredType (Expr *E, TypeBase *T) {
3024
- assert (E != nullptr );
3025
- this ->FavoredTypes [E] = T;
3026
- }
3027
-
3028
2954
// / Set the type in our type map for the given node, and record the change
3029
2955
// / in the trail.
3030
2956
// /
@@ -5280,19 +5206,11 @@ class ConstraintSystem {
5280
5206
// / \returns true if an error occurred, false otherwise.
5281
5207
bool solveSimplified (SmallVectorImpl<Solution> &solutions);
5282
5208
5283
- // / Find reduced domains of disjunction constraints for given
5284
- // / expression, this is achieved to solving individual sub-expressions
5285
- // / and combining resolving types. Such algorithm is called directional
5286
- // / path consistency because it goes from children to parents for all
5287
- // / related sub-expressions taking union of their domains.
5288
- // /
5289
- // / \param expr The expression to find reductions for.
5290
- void shrink (Expr *expr);
5291
-
5292
5209
// / Pick a disjunction from the InactiveConstraints list.
5293
5210
// /
5294
- // / \returns The selected disjunction.
5295
- Constraint *selectDisjunction ();
5211
+ // / \returns The selected disjunction and a set of it's favored choices.
5212
+ std::optional<std::pair<Constraint *, llvm::TinyPtrVector<Constraint *>>>
5213
+ selectDisjunction ();
5296
5214
5297
5215
// / Pick a conjunction from the InactiveConstraints list.
5298
5216
// /
@@ -5481,11 +5399,6 @@ class ConstraintSystem {
5481
5399
bool applySolutionToBody (TapExpr *tapExpr,
5482
5400
SyntacticElementTargetRewriter &rewriter);
5483
5401
5484
- // / Reorder the disjunctive clauses for a given expression to
5485
- // / increase the likelihood that a favored constraint will be successfully
5486
- // / resolved before any others.
5487
- void optimizeConstraints (Expr *e);
5488
-
5489
5402
void startExpressionTimer (ExpressionTimer::AnchorType anchor);
5490
5403
5491
5404
// / Determine if we've already explored too many paths in an
@@ -6226,7 +6139,8 @@ class DisjunctionChoiceProducer : public BindingProducer<DisjunctionChoice> {
6226
6139
public:
6227
6140
using Element = DisjunctionChoice;
6228
6141
6229
- DisjunctionChoiceProducer (ConstraintSystem &cs, Constraint *disjunction)
6142
+ DisjunctionChoiceProducer (ConstraintSystem &cs, Constraint *disjunction,
6143
+ llvm::TinyPtrVector<Constraint *> &favorites)
6230
6144
: BindingProducer(cs, disjunction->shouldRememberChoice ()
6231
6145
? disjunction->getLocator()
6232
6146
: nullptr),
@@ -6236,6 +6150,11 @@ class DisjunctionChoiceProducer : public BindingProducer<DisjunctionChoice> {
6236
6150
assert (disjunction->getKind () == ConstraintKind::Disjunction);
6237
6151
assert (!disjunction->shouldRememberChoice () || disjunction->getLocator ());
6238
6152
6153
+ // Mark constraints as favored. This information
6154
+ // is going to be used by partitioner.
6155
+ for (auto *choice : favorites)
6156
+ cs.favorConstraint (choice);
6157
+
6239
6158
// Order and partition the disjunction choices.
6240
6159
partitionDisjunction (Ordering, PartitionBeginning);
6241
6160
}
@@ -6280,8 +6199,9 @@ class DisjunctionChoiceProducer : public BindingProducer<DisjunctionChoice> {
6280
6199
// Partition the choices in the disjunction into groups that we will
6281
6200
// iterate over in an order appropriate to attempt to stop before we
6282
6201
// have to visit all of the options.
6283
- void partitionDisjunction (SmallVectorImpl<unsigned > &Ordering,
6284
- SmallVectorImpl<unsigned > &PartitionBeginning);
6202
+ void
6203
+ partitionDisjunction (SmallVectorImpl<unsigned > &Ordering,
6204
+ SmallVectorImpl<unsigned > &PartitionBeginning);
6285
6205
6286
6206
// / Partition the choices in the range \c first to \c last into groups and
6287
6207
// / order the groups in the best order to attempt based on the argument
0 commit comments