@@ -1186,7 +1186,7 @@ class Solution {
11861186 llvm::DenseMap<ASTNode, Type> nodeTypes;
11871187
11881188 // / The key path component types introduced by this solution.
1189- llvm::DenseMap<std::pair<const KeyPathExpr *, unsigned >, TypeBase * >
1189+ llvm::DenseMap<std::pair<const KeyPathExpr *, unsigned >, Type >
11901190 keyPathComponentTypes;
11911191
11921192 // / Contextual types introduced by this solution.
@@ -2183,9 +2183,23 @@ class ConstraintSystem {
21832183 // / run through various diagnostics passes without actually mutating
21842184 // / the types on the nodes.
21852185 llvm::MapVector<ASTNode, Type> NodeTypes;
2186- llvm::DenseMap<std::pair<const KeyPathExpr *, unsigned >, TypeBase *>
2186+
2187+ // / The nodes for which we have produced types, along with the prior type
2188+ // / each node had before introducing this type.
2189+ llvm::SmallVector<std::pair<ASTNode, Type>, 8 > addedNodeTypes;
2190+
2191+ // / Maps components in a key path expression to their type. Needed because
2192+ // / KeyPathExpr + Index isn't an \c ASTNode and thus can't be stored in \c
2193+ // / NodeTypes.
2194+ llvm::DenseMap<std::pair<const KeyPathExpr *, /* component index=*/ unsigned >,
2195+ Type>
21872196 KeyPathComponentTypes;
21882197
2198+ // / Same as \c addedNodeTypes for \c KeyPathComponentTypes.
2199+ llvm::SmallVector<
2200+ std::tuple<const KeyPathExpr *, /* component index=*/ unsigned , Type>>
2201+ addedKeyPathComponentTypes;
2202+
21892203 // / Maps AST entries to their solution application targets.
21902204 llvm::MapVector<SolutionApplicationTargetsKey, SolutionApplicationTarget>
21912205 solutionApplicationTargets;
@@ -2266,10 +2280,6 @@ class ConstraintSystem {
22662280 SmallVector<std::pair<ConstraintLocator *, OpenedArchetypeType *>, 4 >
22672281 OpenedExistentialTypes;
22682282
2269- // / The nodes for which we have produced types, along with the prior type
2270- // / each node had before introducing this type.
2271- llvm::SmallVector<std::pair<ASTNode, Type>, 8 > addedNodeTypes;
2272-
22732283 // / The set of functions that have been transformed by a result builder.
22742284 std::vector<std::pair<AnyFunctionRef, AppliedBuilderTransform>>
22752285 resultBuilderTransformed;
@@ -2739,6 +2749,8 @@ class ConstraintSystem {
27392749
27402750 unsigned numAddedNodeTypes;
27412751
2752+ unsigned numAddedKeyPathComponentTypes;
2753+
27422754 unsigned numDisabledConstraints;
27432755
27442756 unsigned numFavoredConstraints;
@@ -2954,10 +2966,15 @@ class ConstraintSystem {
29542966 // / map is used throughout the expression type checker in order to
29552967 // / avoid mutating expressions until we know we have successfully
29562968 // / type-checked them.
2957- void setType (KeyPathExpr *KP, unsigned I, Type T) {
2969+ void setType (const KeyPathExpr *KP, unsigned I, Type T) {
29582970 assert (KP && " Expected non-null key path parameter!" );
29592971 assert (T && " Expected non-null type!" );
2960- KeyPathComponentTypes[std::make_pair (KP, I)] = T.getPointer ();
2972+
2973+ Type &entry = KeyPathComponentTypes[{KP, I}];
2974+ Type oldType = entry;
2975+ entry = T;
2976+
2977+ addedKeyPathComponentTypes.push_back (std::make_tuple (KP, I, oldType));
29612978 }
29622979
29632980 // / Check to see if we have a type for a node.
0 commit comments