@@ -787,6 +787,15 @@ using OpenedType = std::pair<GenericTypeParamType *, TypeVariableType *>;
787
787
using OpenedTypeMap =
788
788
llvm::DenseMap<GenericTypeParamType *, TypeVariableType *>;
789
789
790
+ // / Describes contextual type information about a particular expression
791
+ // / within a constraint system.
792
+ struct ContextualTypeInfo {
793
+ TypeLoc typeLoc;
794
+ ContextualTypePurpose purpose;
795
+
796
+ Type getType () const { return typeLoc.getType (); }
797
+ };
798
+
790
799
// / A complete solution to a constraint system.
791
800
// /
792
801
// / A solution to a constraint system consists of type variable bindings to
@@ -849,6 +858,9 @@ class Solution {
849
858
// / The node -> type mappings introduced by this solution.
850
859
llvm::MapVector<TypedNode, Type> addedNodeTypes;
851
860
861
+ // / Contextual types introduced by this solution.
862
+ std::vector<std::pair<const Expr *, ContextualTypeInfo>> contextualTypes;
863
+
852
864
std::vector<std::pair<ConstraintLocator *, ProtocolConformanceRef>>
853
865
Conformances;
854
866
@@ -1300,13 +1312,6 @@ class ConstraintSystem {
1300
1312
llvm::DenseMap<std::pair<const KeyPathExpr *, unsigned >, TypeBase *>
1301
1313
KeyPathComponentTypes;
1302
1314
1303
- struct ContextualTypeInfo {
1304
- TypeLoc typeLoc;
1305
- ContextualTypePurpose purpose;
1306
-
1307
- Type getType () const { return typeLoc.getType (); }
1308
- };
1309
-
1310
1315
// / Contextual type information for expressions that are part of this
1311
1316
// / constraint system.
1312
1317
llvm::MapVector<const Expr *, ContextualTypeInfo> contextualTypes;
@@ -2174,35 +2179,36 @@ class ConstraintSystem {
2174
2179
return E;
2175
2180
}
2176
2181
2177
- void setContextualType (Expr *expr, TypeLoc T, ContextualTypePurpose purpose) {
2182
+ void setContextualType (
2183
+ const Expr *expr, TypeLoc T, ContextualTypePurpose purpose) {
2178
2184
assert (expr != nullptr && " Expected non-null expression!" );
2179
2185
assert (contextualTypes.count (expr) == 0 &&
2180
2186
" Already set this contextual type" );
2181
2187
contextualTypes[expr] = { T, purpose };
2182
2188
}
2183
2189
2184
- Optional<ContextualTypeInfo> getContextualTypeInfo (Expr *expr) const {
2190
+ Optional<ContextualTypeInfo> getContextualTypeInfo (const Expr *expr) const {
2185
2191
auto known = contextualTypes.find (expr);
2186
2192
if (known == contextualTypes.end ())
2187
2193
return None;
2188
2194
return known->second ;
2189
2195
}
2190
2196
2191
- Type getContextualType (Expr *expr) const {
2197
+ Type getContextualType (const Expr *expr) const {
2192
2198
auto result = getContextualTypeInfo (expr);
2193
2199
if (result)
2194
2200
return result->typeLoc .getType ();
2195
2201
return Type ();
2196
2202
}
2197
2203
2198
- TypeLoc getContextualTypeLoc (Expr *expr) const {
2204
+ TypeLoc getContextualTypeLoc (const Expr *expr) const {
2199
2205
auto result = getContextualTypeInfo (expr);
2200
2206
if (result)
2201
2207
return result->typeLoc ;
2202
2208
return TypeLoc ();
2203
2209
}
2204
2210
2205
- ContextualTypePurpose getContextualTypePurpose (Expr *expr) const {
2211
+ ContextualTypePurpose getContextualTypePurpose (const Expr *expr) const {
2206
2212
auto result = getContextualTypeInfo (expr);
2207
2213
if (result)
2208
2214
return result->purpose ;
0 commit comments