@@ -1440,6 +1440,34 @@ struct MatchCallArgumentResult {
1440
1440
}
1441
1441
};
1442
1442
1443
+ // / Describes a potential throw site in the constraint system.
1444
+ // /
1445
+ // / For example, given `try f() + a[b] + x.y`, each of `f()`, `a[b]`, `x`, and
1446
+ // / `x.y` is a potential throw site.
1447
+ struct PotentialThrowSite {
1448
+ enum Kind {
1449
+ // / The application of a function or subscript.
1450
+ Application,
1451
+
1452
+ // / An explicit 'throw'.
1453
+ ExplicitThrow,
1454
+
1455
+ // / A non-exhaustive do...catch, which rethrows whatever is thrown from
1456
+ // / inside it's `do` block.
1457
+ NonExhaustiveDoCatch,
1458
+
1459
+ // / A property access that can throw an error.
1460
+ PropertyAccess,
1461
+ } kind;
1462
+
1463
+ // / The type that describes the potential throw site, such as the type of the
1464
+ // / function being called or type being thrown.
1465
+ Type type;
1466
+
1467
+ // / The locator that specifies where the throwing operation occurs.
1468
+ ConstraintLocator *locator;
1469
+ };
1470
+
1443
1471
// / A complete solution to a constraint system.
1444
1472
// /
1445
1473
// / A solution to a constraint system consists of type variable bindings to
@@ -1547,6 +1575,13 @@ class Solution {
1547
1575
llvm::MapVector<const CaseLabelItem *, CaseLabelItemInfo>
1548
1576
caseLabelItems;
1549
1577
1578
+ // / Maps catch nodes to the set of potential throw sites that will be caught
1579
+ // / at that location.
1580
+
1581
+ // / The set of opened types for a given locator.
1582
+ std::vector<std::pair<CatchNode, PotentialThrowSite>>
1583
+ potentialThrowSites;
1584
+
1550
1585
// / A map of expressions to the ExprPatterns that they are being solved as
1551
1586
// / a part of.
1552
1587
llvm::MapVector<Expr *, ExprPattern *> exprPatterns;
@@ -2038,6 +2073,9 @@ struct DeclReferenceType {
2038
2073
// / (e.g.) applying the base of a member access. This is the type of the
2039
2074
// / expression used to form the declaration reference.
2040
2075
Type adjustedReferenceType;
2076
+
2077
+ // / The type that could be thrown by accessing this declaration.
2078
+ Type thrownErrorTypeOnAccess;
2041
2079
};
2042
2080
2043
2081
// / Describes a system of constraints on type variables, the
@@ -2210,6 +2248,11 @@ class ConstraintSystem {
2210
2248
llvm::SmallMapVector<const CaseLabelItem *, CaseLabelItemInfo, 4 >
2211
2249
caseLabelItems;
2212
2250
2251
+ // / Keep track of all of the potential throw sites.
2252
+ // / FIXME: This data structure should be replaced with something that
2253
+ // / is, in effect, a multimap-vector.
2254
+ std::vector<std::pair<CatchNode, PotentialThrowSite>> potentialThrowSites;
2255
+
2213
2256
// / A map of expressions to the ExprPatterns that they are being solved as
2214
2257
// / a part of.
2215
2258
llvm::SmallMapVector<Expr *, ExprPattern *, 2 > exprPatterns;
@@ -2821,6 +2864,9 @@ class ConstraintSystem {
2821
2864
// / The length of \c caseLabelItems.
2822
2865
unsigned numCaseLabelItems;
2823
2866
2867
+ // / The length of \c potentialThrowSites.
2868
+ unsigned numPotentialThrowSites;
2869
+
2824
2870
// / The length of \c exprPatterns.
2825
2871
unsigned numExprPatterns;
2826
2872
@@ -3293,6 +3339,14 @@ class ConstraintSystem {
3293
3339
return known->second ;
3294
3340
}
3295
3341
3342
+ // / Note that there is a potential throw site at the given location.
3343
+ void recordPotentialThrowSite (
3344
+ PotentialThrowSite::Kind kind, Type type,
3345
+ ConstraintLocatorBuilder locator);
3346
+
3347
+ // / Determine the caught error type for the given catch node.
3348
+ Type getCaughtErrorType (CatchNode node);
3349
+
3296
3350
// / Retrieve the constraint locator for the given anchor and
3297
3351
// / path, uniqued.
3298
3352
ConstraintLocator *
0 commit comments