@@ -1203,8 +1203,7 @@ struct CaseLabelItemInfo {
12031203
12041204// / Key to the constraint solver's mapping from AST nodes to their corresponding
12051205// / target.
1206- class SyntacticElementTargetKey {
1207- public:
1206+ struct SyntacticElementTargetKey {
12081207 enum class Kind {
12091208 empty,
12101209 tombstone,
@@ -1218,72 +1217,75 @@ class SyntacticElementTargetKey {
12181217 functionRef,
12191218 };
12201219
1221- private:
12221220 Kind kind;
12231221
12241222 union {
1225- const StmtConditionElement *stmtCondElement;
1223+ StmtConditionElement *stmtCondElement;
12261224
1227- const Expr *expr;
1225+ Expr *expr;
12281226
1229- const Stmt *stmt;
1227+ Stmt *stmt;
12301228
1231- const Pattern *pattern;
1229+ Pattern *pattern;
12321230
12331231 struct PatternBindingEntry {
1234- const PatternBindingDecl *patternBinding;
1232+ PatternBindingDecl *patternBinding;
12351233 unsigned index;
12361234 } patternBindingEntry;
12371235
1238- const VarDecl *varDecl;
1236+ VarDecl *varDecl;
12391237
1240- const DeclContext *functionRef;
1238+ DeclContext *functionRef;
12411239 } storage;
12421240
1243- public:
12441241 SyntacticElementTargetKey (Kind kind) {
12451242 assert (kind == Kind::empty || kind == Kind::tombstone);
12461243 this ->kind = kind;
12471244 }
12481245
1249- SyntacticElementTargetKey (const StmtConditionElement *stmtCondElement) {
1246+ SyntacticElementTargetKey (StmtConditionElement *stmtCondElement) {
12501247 kind = Kind::stmtCondElement;
12511248 storage.stmtCondElement = stmtCondElement;
12521249 }
12531250
1254- SyntacticElementTargetKey (const Expr *expr) {
1251+ SyntacticElementTargetKey (Expr *expr) {
12551252 kind = Kind::expr;
12561253 storage.expr = expr;
12571254 }
12581255
1259- SyntacticElementTargetKey (const ClosureExpr *closure) {
1256+ SyntacticElementTargetKey (ClosureExpr *closure) {
12601257 kind = Kind::closure;
12611258 storage.expr = closure;
12621259 }
12631260
1264- SyntacticElementTargetKey (const Stmt *stmt) {
1261+ SyntacticElementTargetKey (Stmt *stmt) {
12651262 kind = Kind::stmt;
12661263 storage.stmt = stmt;
12671264 }
12681265
1269- SyntacticElementTargetKey (const Pattern *pattern) {
1266+ SyntacticElementTargetKey (Pattern *pattern) {
12701267 kind = Kind::pattern;
12711268 storage.pattern = pattern;
12721269 }
12731270
1274- SyntacticElementTargetKey (const PatternBindingDecl *patternBinding,
1271+ SyntacticElementTargetKey (PatternBindingDecl *patternBinding,
12751272 unsigned index) {
12761273 kind = Kind::patternBindingEntry;
12771274 storage.patternBindingEntry .patternBinding = patternBinding;
12781275 storage.patternBindingEntry .index = index;
12791276 }
12801277
1281- SyntacticElementTargetKey (const VarDecl *varDecl) {
1278+ SyntacticElementTargetKey (VarDecl *varDecl) {
12821279 kind = Kind::varDecl;
12831280 storage.varDecl = varDecl;
12841281 }
12851282
1286- SyntacticElementTargetKey (const AnyFunctionRef functionRef) {
1283+ SyntacticElementTargetKey (DeclContext *dc) {
1284+ kind = Kind::functionRef;
1285+ storage.functionRef = dc;
1286+ }
1287+
1288+ SyntacticElementTargetKey (AnyFunctionRef functionRef) {
12871289 kind = Kind::functionRef;
12881290 storage.functionRef = functionRef.getAsDeclContext ();
12891291 }
@@ -1574,7 +1576,7 @@ class Solution {
15741576 std::vector<std::pair<ASTNode, ContextualTypeInfo>> contextualTypes;
15751577
15761578 // / Maps AST nodes to their target.
1577- llvm::MapVector <SyntacticElementTargetKey, SyntacticElementTarget> targets;
1579+ llvm::DenseMap <SyntacticElementTargetKey, SyntacticElementTarget> targets;
15781580
15791581 // / Maps case label items to information tracked about them as they are
15801582 // / being solved.
@@ -1727,12 +1729,7 @@ class Solution {
17271729 }
17281730
17291731 std::optional<SyntacticElementTarget>
1730- getTargetFor (SyntacticElementTargetKey key) const {
1731- auto known = targets.find (key);
1732- if (known == targets.end ())
1733- return std::nullopt ;
1734- return known->second ;
1735- }
1732+ getTargetFor (SyntacticElementTargetKey key) const ;
17361733
17371734 ConstraintLocator *getCalleeLocator (ConstraintLocator *locator,
17381735 bool lookThroughApply = true ) const ;
@@ -2275,7 +2272,7 @@ class ConstraintSystem {
22752272 KeyPaths;
22762273
22772274 // / Maps AST entries to their targets.
2278- llvm::MapVector <SyntacticElementTargetKey, SyntacticElementTarget> targets;
2275+ llvm::DenseMap <SyntacticElementTargetKey, SyntacticElementTarget> targets;
22792276
22802277 // / Contextual type information for expressions that are part of this
22812278 // / constraint system. The second type, if valid, contains the type as it
@@ -2860,9 +2857,6 @@ class ConstraintSystem {
28602857 // / FIXME: Remove this.
28612858 unsigned numFixes;
28622859
2863- // / The length of \c targets.
2864- unsigned numTargets;
2865-
28662860 // / The length of \c caseLabelItems.
28672861 unsigned numCaseLabelItems;
28682862
@@ -3090,8 +3084,10 @@ class ConstraintSystem {
30903084 bool inserted = ClosureTypes.insert ({closure, type}).second ;
30913085 ASSERT (inserted);
30923086
3093- if (solverState)
3094- recordChange (SolverTrail::Change::RecordedClosureType (closure));
3087+ if (solverState) {
3088+ recordChange (SolverTrail::Change::RecordedClosureType (
3089+ const_cast <ClosureExpr *>(closure)));
3090+ }
30953091 }
30963092
30973093 void removeClosureType (const ClosureExpr *closure) {
@@ -3359,18 +3355,12 @@ class ConstraintSystem {
33593355 }
33603356
33613357 void setTargetFor (SyntacticElementTargetKey key,
3362- SyntacticElementTarget target) {
3363- assert (targets.count (key) == 0 && " Already set this target" );
3364- targets.insert ({key, target});
3365- }
3358+ SyntacticElementTarget target);
3359+
3360+ void removeTargetFor (SyntacticElementTargetKey key);
33663361
33673362 std::optional<SyntacticElementTarget>
3368- getTargetFor (SyntacticElementTargetKey key) const {
3369- auto known = targets.find (key);
3370- if (known == targets.end ())
3371- return std::nullopt ;
3372- return known->second ;
3373- }
3363+ getTargetFor (SyntacticElementTargetKey key) const ;
33743364
33753365 std::optional<AppliedBuilderTransform>
33763366 getAppliedResultBuilderTransform (AnyFunctionRef fn) const {
0 commit comments