Skip to content

Commit 25cfa13

Browse files
committed
[CS] Remove isDynamic param from buildMemberRef
Callers were either just passing choice.getKind() == OverloadChoiceKind::DeclViaDynamic or passing false. Inline the check into the function and assert for callers that don't expect a decl from dynamic lookup.
1 parent 3e34c8c commit 25cfa13

File tree

1 file changed

+13
-26
lines changed

1 file changed

+13
-26
lines changed

lib/Sema/CSApply.cpp

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ namespace {
409409
ConstraintLocatorBuilder locator, bool implicit,
410410
FunctionRefKind functionRefKind,
411411
AccessSemantics semantics) {
412+
assert(choice.getKind() != OverloadChoiceKind::DeclViaDynamic);
412413
auto *decl = choice.getDecl();
413414

414415
// Determine the declaration selected for this overloaded reference.
@@ -486,8 +487,7 @@ namespace {
486487

487488
return buildMemberRef(base, openedType, SourceLoc(), choice, loc,
488489
openedFnType->getResult(), locator, locator,
489-
implicit, functionRefKind, semantics,
490-
/*isDynamic=*/false);
490+
implicit, functionRefKind, semantics);
491491
}
492492

493493
auto type = solution.simplifyType(openedType);
@@ -760,7 +760,7 @@ namespace {
760760
Type openedType, ConstraintLocatorBuilder locator,
761761
ConstraintLocatorBuilder memberLocator, bool Implicit,
762762
FunctionRefKind functionRefKind,
763-
AccessSemantics semantics, bool isDynamic) {
763+
AccessSemantics semantics) {
764764
ValueDecl *member = choice.getDecl();
765765

766766
auto &context = cs.getASTContext();
@@ -860,6 +860,7 @@ namespace {
860860
semantics = getImplicitMemberReferenceAccessSemantics(base, VD, dc);
861861
}
862862

863+
auto isDynamic = choice.getKind() == OverloadChoiceKind::DeclViaDynamic;
863864
if (baseIsInstance) {
864865
// Convert the base to the appropriate container type, turning it
865866
// into an lvalue if required.
@@ -2346,14 +2347,11 @@ namespace {
23462347
auto memberLocator = cs.getConstraintLocator(expr,
23472348
ConstraintLocator::Member);
23482349
auto selected = solution.getOverloadChoice(memberLocator);
2349-
bool isDynamic
2350-
= selected.choice.getKind() == OverloadChoiceKind::DeclViaDynamic;
23512350
return buildMemberRef(
23522351
expr->getBase(), selected.openedFullType, expr->getDotLoc(),
23532352
selected.choice, expr->getNameLoc(), selected.openedType,
23542353
cs.getConstraintLocator(expr), memberLocator, expr->isImplicit(),
2355-
selected.choice.getFunctionRefKind(), expr->getAccessSemantics(),
2356-
isDynamic);
2354+
selected.choice.getFunctionRefKind(), expr->getAccessSemantics());
23572355
}
23582356

23592357
Expr *visitDynamicMemberRefExpr(DynamicMemberRefExpr *expr) {
@@ -2393,15 +2391,12 @@ namespace {
23932391
cs.cacheExprTypes(base);
23942392

23952393
// Build the member reference.
2396-
bool isDynamic
2397-
= selected.choice.getKind() == OverloadChoiceKind::DeclViaDynamic;
23982394
auto *exprLoc = cs.getConstraintLocator(expr);
23992395
auto result = buildMemberRef(
24002396
base, selected.openedFullType, expr->getDotLoc(), selected.choice,
24012397
expr->getNameLoc(), selected.openedType,
24022398
exprLoc, memberLocator, expr->isImplicit(),
2403-
selected.choice.getFunctionRefKind(), AccessSemantics::Ordinary,
2404-
isDynamic);
2399+
selected.choice.getFunctionRefKind(), AccessSemantics::Ordinary);
24052400
if (!result)
24062401
return nullptr;
24072402

@@ -2538,7 +2533,7 @@ namespace {
25382533
ConstraintLocator *ctorLocator,
25392534
OverloadChoice choice,
25402535
FunctionRefKind functionRefKind, Type openedType) {
2541-
2536+
assert(choice.getKind() != OverloadChoiceKind::DeclViaDynamic);
25422537
auto *ctor = cast<ConstructorDecl>(choice.getDecl());
25432538

25442539
// If the subexpression is a metatype, build a direct reference to the
@@ -2547,8 +2542,7 @@ namespace {
25472542
return buildMemberRef(
25482543
base, openedType, dotLoc, choice, nameLoc, cs.getType(expr),
25492544
ConstraintLocatorBuilder(cs.getConstraintLocator(expr)),
2550-
ctorLocator, implicit, functionRefKind, AccessSemantics::Ordinary,
2551-
/*isDynamic=*/false);
2545+
ctorLocator, implicit, functionRefKind, AccessSemantics::Ordinary);
25522546
}
25532547

25542548
// The subexpression must be either 'self' or 'super'.
@@ -2672,15 +2666,12 @@ namespace {
26722666

26732667
case OverloadChoiceKind::Decl:
26742668
case OverloadChoiceKind::DeclViaUnwrappedOptional:
2675-
case OverloadChoiceKind::DeclViaDynamic: {
2676-
bool isDynamic
2677-
= selected.choice.getKind() == OverloadChoiceKind::DeclViaDynamic;
2669+
case OverloadChoiceKind::DeclViaDynamic:
26782670
return buildMemberRef(base, selected.openedFullType, dotLoc,
26792671
selected.choice, nameLoc, selected.openedType,
26802672
cs.getConstraintLocator(expr), memberLocator,
26812673
implicit, selected.choice.getFunctionRefKind(),
2682-
AccessSemantics::Ordinary, isDynamic);
2683-
}
2674+
AccessSemantics::Ordinary);
26842675

26852676
case OverloadChoiceKind::TupleIndex: {
26862677
Type toType = simplifyType(cs.getType(expr));
@@ -6617,12 +6608,11 @@ static Expr *finishApplyCallAsFunctionMethod(
66176608
auto *fn = apply->getFn();
66186609
auto choice = selected.choice;
66196610
// Create direct reference to `callAsFunction` method.
6620-
bool isDynamic = choice.getKind() == OverloadChoiceKind::DeclViaDynamic;
66216611
auto *declRef = rewriter.buildMemberRef(
66226612
fn, selected.openedFullType, /*dotLoc*/ SourceLoc(), choice,
66236613
DeclNameLoc(fn->getEndLoc()), selected.openedType, applyFunctionLoc,
66246614
applyFunctionLoc, /*implicit*/ true, choice.getFunctionRefKind(),
6625-
AccessSemantics::Ordinary, isDynamic);
6615+
AccessSemantics::Ordinary);
66266616
if (!declRef)
66276617
return nullptr;
66286618
declRef->setImplicit(apply->isImplicit());
@@ -6668,14 +6658,12 @@ ExprRewriter::finishApplyDynamicCallable(ApplyExpr *apply,
66686658
bool useKwargsMethod = argumentLabel == ctx.Id_withKeywordArguments;
66696659

66706660
// Construct expression referencing the `dynamicallyCall` method.
6671-
bool isDynamic =
6672-
selected.choice.getKind() == OverloadChoiceKind::DeclViaDynamic;
66736661
auto member = buildMemberRef(fn, selected.openedFullType,
66746662
SourceLoc(), selected.choice,
66756663
DeclNameLoc(method->getNameLoc()),
66766664
selected.openedType, loc, loc, /*implicit*/ true,
66776665
selected.choice.getFunctionRefKind(),
6678-
AccessSemantics::Ordinary, isDynamic);
6666+
AccessSemantics::Ordinary);
66796667

66806668
// Construct argument to the method (either an array or dictionary
66816669
// expression).
@@ -7022,15 +7010,14 @@ Expr *ExprRewriter::finishApply(ApplyExpr *apply, ConcreteDeclRef callee,
70227010

70237011
// Consider the constructor decl reference expr 'implicit', but the
70247012
// constructor call expr itself has the apply's 'implicitness'.
7025-
bool isDynamic = choice.getKind() == OverloadChoiceKind::DeclViaDynamic;
70267013
auto ctorRef = resolveConcreteDeclRef(choice.getDecl(), ctorLocator);
70277014
Expr *declRef = buildMemberRef(fn, selected->openedFullType,
70287015
/*dotLoc=*/SourceLoc(), choice,
70297016
DeclNameLoc(fn->getEndLoc()),
70307017
selected->openedType, locator, ctorLocator,
70317018
/*Implicit=*/true,
70327019
choice.getFunctionRefKind(),
7033-
AccessSemantics::Ordinary, isDynamic);
7020+
AccessSemantics::Ordinary);
70347021
if (!declRef)
70357022
return nullptr;
70367023
declRef->setImplicit(apply->isImplicit());

0 commit comments

Comments
 (0)