Skip to content

Commit cc20487

Browse files
committedJan 8, 2025
Sema: Clean up local property wrapper bookkeeping

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed
 

‎include/swift/Sema/ConstraintSystem.h

+7
Original file line numberDiff line numberDiff line change
@@ -1632,6 +1632,13 @@ class Solution {
16321632
/// A map from argument expressions to their applied property wrapper expressions.
16331633
llvm::DenseMap<ASTNode, SmallVector<AppliedPropertyWrapper, 2>> appliedPropertyWrappers;
16341634

1635+
ArrayRef<AppliedPropertyWrapper> getAppliedPropertyWrappers(ASTNode anchor) {
1636+
auto found = appliedPropertyWrappers.find(anchor);
1637+
if (found != appliedPropertyWrappers.end())
1638+
return found->second;
1639+
return ArrayRef<AppliedPropertyWrapper>();
1640+
}
1641+
16351642
/// A mapping from the constraint locators for references to various
16361643
/// names (e.g., member references, normal name references, possible
16371644
/// constructions) to the argument lists for the call to that locator.

‎lib/Sema/CSApply.cpp

+10-6
Original file line numberDiff line numberDiff line change
@@ -1190,8 +1190,8 @@ namespace {
11901190
calleeFnTy = calleeFnTy->getResult()->castTo<FunctionType>();
11911191
}
11921192

1193-
const auto &appliedPropertyWrappers =
1194-
solution.appliedPropertyWrappers[locator.getAnchor()];
1193+
auto appliedPropertyWrappers =
1194+
solution.getAppliedPropertyWrappers(locator.getAnchor());
11951195
const auto calleeDeclRef = resolveConcreteDeclRef(
11961196
dyn_cast<AbstractFunctionDecl>(declOrClosure), locator);
11971197

@@ -2319,8 +2319,8 @@ namespace {
23192319
->castTo<FunctionType>();
23202320
auto fullSubscriptTy = openedFullFnType->getResult()
23212321
->castTo<FunctionType>();
2322-
auto &appliedWrappers =
2323-
solution.appliedPropertyWrappers[memberLoc->getAnchor()];
2322+
auto appliedWrappers =
2323+
solution.getAppliedPropertyWrappers(memberLoc->getAnchor());
23242324
args = coerceCallArguments(
23252325
args, fullSubscriptTy, subscriptRef, nullptr,
23262326
locator.withPathElement(ConstraintLocator::ApplyArgument),
@@ -6286,6 +6286,7 @@ ArgumentList *ExprRewriter::coerceCallArguments(
62866286
auto *paramDecl = getParameterAt(callee, paramIdx);
62876287
assert(paramDecl);
62886288

6289+
ASSERT(appliedWrapperIndex < appliedPropertyWrappers.size());
62896290
auto appliedWrapper = appliedPropertyWrappers[appliedWrapperIndex++];
62906291
auto wrapperType = solution.simplifyType(appliedWrapper.wrapperType);
62916292
auto initKind = appliedWrapper.initKind;
@@ -8179,7 +8180,8 @@ Expr *ExprRewriter::finishApply(ApplyExpr *apply, Type openedType,
81798180
// Resolve into a DynamicTypeExpr.
81808181
auto args = apply->getArgs();
81818182

8182-
auto &appliedWrappers = solution.appliedPropertyWrappers[calleeLocator.getAnchor()];
8183+
auto appliedWrappers = solution.getAppliedPropertyWrappers(
8184+
calleeLocator.getAnchor());
81838185
auto fnType = cs.getType(fn)->getAs<FunctionType>();
81848186
args = coerceCallArguments(
81858187
args, fnType, declRef, apply,
@@ -8375,7 +8377,9 @@ Expr *ExprRewriter::finishApply(ApplyExpr *apply, Type openedType,
83758377
// For function application, convert the argument to the input type of
83768378
// the function.
83778379
if (auto fnType = cs.getType(fn)->getAs<FunctionType>()) {
8378-
auto &appliedWrappers = solution.appliedPropertyWrappers[calleeLocator.getAnchor()];
8380+
auto appliedWrappers = solution.getAppliedPropertyWrappers(
8381+
calleeLocator.getAnchor());
8382+
83798383
args = coerceCallArguments(
83808384
args, fnType, callee, apply,
83818385
locator.withPathElement(ConstraintLocator::ApplyArgument),

0 commit comments

Comments
 (0)
Please sign in to comment.