@@ -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
// /
@@ -5376,19 +5303,11 @@ class ConstraintSystem {
5376
5303
// / \returns true if an error occurred, false otherwise.
5377
5304
bool solveSimplified (SmallVectorImpl<Solution> &solutions);
5378
5305
5379
- // / Find reduced domains of disjunction constraints for given
5380
- // / expression, this is achieved to solving individual sub-expressions
5381
- // / and combining resolving types. Such algorithm is called directional
5382
- // / path consistency because it goes from children to parents for all
5383
- // / related sub-expressions taking union of their domains.
5384
- // /
5385
- // / \param expr The expression to find reductions for.
5386
- void shrink (Expr *expr);
5387
-
5388
5306
// / Pick a disjunction from the InactiveConstraints list.
5389
5307
// /
5390
- // / \returns The selected disjunction.
5391
- Constraint *selectDisjunction ();
5308
+ // / \returns The selected disjunction and a set of it's favored choices.
5309
+ std::optional<std::pair<Constraint *, llvm::TinyPtrVector<Constraint *>>>
5310
+ selectDisjunction ();
5392
5311
5393
5312
// / Pick a conjunction from the InactiveConstraints list.
5394
5313
// /
@@ -5577,11 +5496,6 @@ class ConstraintSystem {
5577
5496
bool applySolutionToBody (TapExpr *tapExpr,
5578
5497
SyntacticElementTargetRewriter &rewriter);
5579
5498
5580
- // / Reorder the disjunctive clauses for a given expression to
5581
- // / increase the likelihood that a favored constraint will be successfully
5582
- // / resolved before any others.
5583
- void optimizeConstraints (Expr *e);
5584
-
5585
5499
void startExpressionTimer (ExpressionTimer::AnchorType anchor);
5586
5500
5587
5501
// / Determine if we've already explored too many paths in an
@@ -6322,7 +6236,8 @@ class DisjunctionChoiceProducer : public BindingProducer<DisjunctionChoice> {
6322
6236
public:
6323
6237
using Element = DisjunctionChoice;
6324
6238
6325
- DisjunctionChoiceProducer (ConstraintSystem &cs, Constraint *disjunction)
6239
+ DisjunctionChoiceProducer (ConstraintSystem &cs, Constraint *disjunction,
6240
+ llvm::TinyPtrVector<Constraint *> &favorites)
6326
6241
: BindingProducer(cs, disjunction->shouldRememberChoice ()
6327
6242
? disjunction->getLocator()
6328
6243
: nullptr),
@@ -6332,6 +6247,11 @@ class DisjunctionChoiceProducer : public BindingProducer<DisjunctionChoice> {
6332
6247
assert (disjunction->getKind () == ConstraintKind::Disjunction);
6333
6248
assert (!disjunction->shouldRememberChoice () || disjunction->getLocator ());
6334
6249
6250
+ // Mark constraints as favored. This information
6251
+ // is going to be used by partitioner.
6252
+ for (auto *choice : favorites)
6253
+ cs.favorConstraint (choice);
6254
+
6335
6255
// Order and partition the disjunction choices.
6336
6256
partitionDisjunction (Ordering, PartitionBeginning);
6337
6257
}
@@ -6376,8 +6296,9 @@ class DisjunctionChoiceProducer : public BindingProducer<DisjunctionChoice> {
6376
6296
// Partition the choices in the disjunction into groups that we will
6377
6297
// iterate over in an order appropriate to attempt to stop before we
6378
6298
// have to visit all of the options.
6379
- void partitionDisjunction (SmallVectorImpl<unsigned > &Ordering,
6380
- SmallVectorImpl<unsigned > &PartitionBeginning);
6299
+ void
6300
+ partitionDisjunction (SmallVectorImpl<unsigned > &Ordering,
6301
+ SmallVectorImpl<unsigned > &PartitionBeginning);
6381
6302
6382
6303
// / Partition the choices in the range \c first to \c last into groups and
6383
6304
// / order the groups in the best order to attempt based on the argument
0 commit comments