Skip to content

Commit ee8ce80

Browse files
committed
[Constraint generation] Simplify association of argument labels with calls.
1 parent b40c89d commit ee8ce80

File tree

1 file changed

+9
-28
lines changed

1 file changed

+9
-28
lines changed

lib/Sema/CSGen.cpp

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2886,19 +2886,9 @@ namespace {
28862886

28872887
using State = ConstraintSystem::ArgumentLabelState;
28882888

2889-
void associateArgumentLabels(Expr *arg, State labels,
2889+
void associateArgumentLabels(Expr *fn, State labels,
28902890
bool labelsArePermanent) {
2891-
// Our parent must be a call.
2892-
auto call = dyn_cast_or_null<CallExpr>(ParentMap[arg]);
2893-
if (!call)
2894-
return;
2895-
2896-
// We must have originated at the call argument.
2897-
if (arg != call->getArg())
2898-
return;
2899-
29002891
// Dig out the function, looking through, parentheses, ?, and !.
2901-
auto fn = call->getFn();
29022892
do {
29032893
fn = fn->getSemanticsProvidingExpr();
29042894

@@ -2922,25 +2912,16 @@ namespace {
29222912
}
29232913

29242914
std::pair<bool, Expr *> walkToExprPre(Expr *expr) override {
2925-
if (auto tuple = dyn_cast<TupleExpr>(expr)) {
2926-
if (tuple->hasElementNames())
2927-
associateArgumentLabels(expr,
2928-
{ tuple->getElementNames(),
2929-
tuple->hasTrailingClosure() },
2930-
/*labelsArePermanent*/ true);
2931-
else {
2932-
llvm::SmallVector<Identifier, 4> names(tuple->getNumElements(),
2933-
Identifier());
2934-
associateArgumentLabels(expr, { names, tuple->hasTrailingClosure() },
2935-
/*labelsArePermanent*/ false);
2936-
}
2937-
} else if (auto paren = dyn_cast<ParenExpr>(expr)) {
2938-
associateArgumentLabels(paren,
2939-
{ { Identifier() },
2940-
paren->hasTrailingClosure() },
2941-
/*labelsArePermanent*/ false);
2915+
if (auto call = dyn_cast<CallExpr>(expr)) {
2916+
associateArgumentLabels(call->getFn(),
2917+
{ call->getArgumentLabels(),
2918+
call->hasTrailingClosure() },
2919+
/*labelsArePermanent=*/true);
2920+
return { true, expr };
29422921
}
29432922

2923+
// FIXME: other expressions have argument labels, but this is an
2924+
// optimization, so stage it in later.
29442925
return { true, expr };
29452926
}
29462927
};

0 commit comments

Comments
 (0)