@@ -1440,6 +1440,34 @@ struct MatchCallArgumentResult {
14401440 }
14411441};
14421442
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+
14431471// / A complete solution to a constraint system.
14441472// /
14451473// / A solution to a constraint system consists of type variable bindings to
@@ -1547,6 +1575,13 @@ class Solution {
15471575 llvm::MapVector<const CaseLabelItem *, CaseLabelItemInfo>
15481576 caseLabelItems;
15491577
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+
15501585 // / A map of expressions to the ExprPatterns that they are being solved as
15511586 // / a part of.
15521587 llvm::MapVector<Expr *, ExprPattern *> exprPatterns;
@@ -2038,6 +2073,9 @@ struct DeclReferenceType {
20382073 // / (e.g.) applying the base of a member access. This is the type of the
20392074 // / expression used to form the declaration reference.
20402075 Type adjustedReferenceType;
2076+
2077+ // / The type that could be thrown by accessing this declaration.
2078+ Type thrownErrorTypeOnAccess;
20412079};
20422080
20432081// / Describes a system of constraints on type variables, the
@@ -2210,6 +2248,11 @@ class ConstraintSystem {
22102248 llvm::SmallMapVector<const CaseLabelItem *, CaseLabelItemInfo, 4 >
22112249 caseLabelItems;
22122250
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+
22132256 // / A map of expressions to the ExprPatterns that they are being solved as
22142257 // / a part of.
22152258 llvm::SmallMapVector<Expr *, ExprPattern *, 2 > exprPatterns;
@@ -2821,6 +2864,9 @@ class ConstraintSystem {
28212864 // / The length of \c caseLabelItems.
28222865 unsigned numCaseLabelItems;
28232866
2867+ // / The length of \c potentialThrowSites.
2868+ unsigned numPotentialThrowSites;
2869+
28242870 // / The length of \c exprPatterns.
28252871 unsigned numExprPatterns;
28262872
@@ -3293,6 +3339,14 @@ class ConstraintSystem {
32933339 return known->second ;
32943340 }
32953341
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+
32963350 // / Retrieve the constraint locator for the given anchor and
32973351 // / path, uniqued.
32983352 ConstraintLocator *
0 commit comments