@@ -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
// /
@@ -5355,19 +5282,11 @@ class ConstraintSystem {
5355
5282
// / \returns true if an error occurred, false otherwise.
5356
5283
bool solveSimplified (SmallVectorImpl<Solution> &solutions);
5357
5284
5358
- // / Find reduced domains of disjunction constraints for given
5359
- // / expression, this is achieved to solving individual sub-expressions
5360
- // / and combining resolving types. Such algorithm is called directional
5361
- // / path consistency because it goes from children to parents for all
5362
- // / related sub-expressions taking union of their domains.
5363
- // /
5364
- // / \param expr The expression to find reductions for.
5365
- void shrink (Expr *expr);
5366
-
5367
5285
// / Pick a disjunction from the InactiveConstraints list.
5368
5286
// /
5369
- // / \returns The selected disjunction.
5370
- Constraint *selectDisjunction ();
5287
+ // / \returns The selected disjunction and a set of it's favored choices.
5288
+ std::optional<std::pair<Constraint *, llvm::TinyPtrVector<Constraint *>>>
5289
+ selectDisjunction ();
5371
5290
5372
5291
// / Pick a conjunction from the InactiveConstraints list.
5373
5292
// /
@@ -5556,11 +5475,6 @@ class ConstraintSystem {
5556
5475
bool applySolutionToBody (TapExpr *tapExpr,
5557
5476
SyntacticElementTargetRewriter &rewriter);
5558
5477
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
-
5564
5478
void startExpressionTimer (ExpressionTimer::AnchorType anchor);
5565
5479
5566
5480
// / Determine if we've already explored too many paths in an
@@ -6301,7 +6215,8 @@ class DisjunctionChoiceProducer : public BindingProducer<DisjunctionChoice> {
6301
6215
public:
6302
6216
using Element = DisjunctionChoice;
6303
6217
6304
- DisjunctionChoiceProducer (ConstraintSystem &cs, Constraint *disjunction)
6218
+ DisjunctionChoiceProducer (ConstraintSystem &cs, Constraint *disjunction,
6219
+ llvm::TinyPtrVector<Constraint *> &favorites)
6305
6220
: BindingProducer(cs, disjunction->shouldRememberChoice ()
6306
6221
? disjunction->getLocator()
6307
6222
: nullptr),
@@ -6311,6 +6226,11 @@ class DisjunctionChoiceProducer : public BindingProducer<DisjunctionChoice> {
6311
6226
assert (disjunction->getKind () == ConstraintKind::Disjunction);
6312
6227
assert (!disjunction->shouldRememberChoice () || disjunction->getLocator ());
6313
6228
6229
+ // Mark constraints as favored. This information
6230
+ // is going to be used by partitioner.
6231
+ for (auto *choice : favorites)
6232
+ cs.favorConstraint (choice);
6233
+
6314
6234
// Order and partition the disjunction choices.
6315
6235
partitionDisjunction (Ordering, PartitionBeginning);
6316
6236
}
@@ -6355,8 +6275,9 @@ class DisjunctionChoiceProducer : public BindingProducer<DisjunctionChoice> {
6355
6275
// Partition the choices in the disjunction into groups that we will
6356
6276
// iterate over in an order appropriate to attempt to stop before we
6357
6277
// have to visit all of the options.
6358
- void partitionDisjunction (SmallVectorImpl<unsigned > &Ordering,
6359
- SmallVectorImpl<unsigned > &PartitionBeginning);
6278
+ void
6279
+ partitionDisjunction (SmallVectorImpl<unsigned > &Ordering,
6280
+ SmallVectorImpl<unsigned > &PartitionBeginning);
6360
6281
6361
6282
// / Partition the choices in the range \c first to \c last into groups and
6362
6283
// / order the groups in the best order to attempt based on the argument
0 commit comments