Skip to content

Commit bf1ed00

Browse files
authored
A few minor cleanups (swiftlang#28427)
A few minor cleanups
2 parents 777435c + b0b68fc commit bf1ed00

File tree

6 files changed

+27
-83
lines changed

6 files changed

+27
-83
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());

lib/Sema/CSDiagnostics.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1626,8 +1626,7 @@ bool AssignmentFailure::diagnoseAsError() {
16261626
if (auto typeContext = DC->getInnermostTypeContext()) {
16271627
SmallVector<ValueDecl *, 2> results;
16281628
DC->lookupQualified(typeContext->getSelfNominalTypeDecl(),
1629-
VD->getFullName(),
1630-
NL_QualifiedDefault | NL_RemoveNonVisible, results);
1629+
VD->getFullName(), NL_QualifiedDefault, results);
16311630

16321631
auto foundProperty = llvm::find_if(results, [&](ValueDecl *decl) {
16331632
// We're looking for a settable property that is the same type as the

lib/Sema/ConstraintLocator.cpp

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -52,24 +52,6 @@ void ConstraintLocator::Profile(llvm::FoldingSetNodeID &id, Expr *anchor,
5252
id.AddPointer(kpElt.getKeyPathDecl());
5353
break;
5454
}
55-
case ApplyArgument:
56-
case ApplyFunction:
57-
case FunctionArgument:
58-
case FunctionResult:
59-
case OptionalPayload:
60-
case Member:
61-
case MemberRefBase:
62-
case UnresolvedMember:
63-
case SubscriptMember:
64-
case ConstructorMember:
65-
case LValueConversion:
66-
case RValueAdjustment:
67-
case ClosureResult:
68-
case ParentType:
69-
case ExistentialSuperclassType:
70-
case InstanceType:
71-
case SequenceElementType:
72-
case AutoclosureResult:
7355
case GenericArgument:
7456
case NamedTupleElement:
7557
case TupleElement:
@@ -78,20 +60,18 @@ void ConstraintLocator::Profile(llvm::FoldingSetNodeID &id, Expr *anchor,
7860
case KeyPathComponent:
7961
case ConditionalRequirement:
8062
case TypeParameterRequirement:
81-
case ImplicitlyUnwrappedDisjunctionChoice:
82-
case DynamicLookupResult:
8363
case ContextualType:
84-
case SynthesizedArgument:
85-
case KeyPathType:
86-
case KeyPathRoot:
87-
case KeyPathValue:
88-
case KeyPathComponentResult:
89-
case Condition:
64+
case SynthesizedArgument: {
9065
auto numValues = numNumericValuesInPathElement(elt.getKind());
9166
for (unsigned i = 0; i < numValues; ++i)
9267
id.AddInteger(elt.getValue(i));
9368
break;
9469
}
70+
#define SIMPLE_LOCATOR_PATH_ELT(Name) case Name :
71+
#include "ConstraintLocatorPathElts.def"
72+
// Nothing to do for simple locator elements.
73+
break;
74+
}
9575
}
9676
}
9777

lib/Sema/ConstraintLocator.h

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -63,34 +63,11 @@ class ConstraintLocator : public llvm::FoldingSetNode {
6363
/// element kind.
6464
static unsigned numNumericValuesInPathElement(PathElementKind kind) {
6565
switch (kind) {
66-
case ApplyArgument:
67-
case ApplyFunction:
66+
#define SIMPLE_LOCATOR_PATH_ELT(Name) case Name :
67+
#include "ConstraintLocatorPathElts.def"
6868
case GenericParameter:
69-
case FunctionArgument:
70-
case FunctionResult:
71-
case OptionalPayload:
72-
case Member:
73-
case MemberRefBase:
74-
case UnresolvedMember:
75-
case SubscriptMember:
76-
case ConstructorMember:
77-
case LValueConversion:
78-
case RValueAdjustment:
79-
case ClosureResult:
80-
case ParentType:
81-
case InstanceType:
82-
case ExistentialSuperclassType:
83-
case SequenceElementType:
84-
case AutoclosureResult:
8569
case ProtocolRequirement:
8670
case Witness:
87-
case ImplicitlyUnwrappedDisjunctionChoice:
88-
case DynamicLookupResult:
89-
case KeyPathType:
90-
case KeyPathRoot:
91-
case KeyPathValue:
92-
case KeyPathComponentResult:
93-
case Condition:
9471
return 0;
9572

9673
case ContextualType:

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -777,10 +777,12 @@ DefaultArgumentInitContextRequest::evaluate(Evaluator &eval,
777777
// kicked off the request, make a note of it for when we return. Otherwise
778778
// cache the result ourselves.
779779
auto *initDC = new (ctx) DefaultArgumentInitializer(parentDC, idx);
780-
if (param == otherParam)
780+
if (param == otherParam) {
781781
result = initDC;
782-
else
783-
eval.cacheOutput(DefaultArgumentInitContextRequest{otherParam}, std::move(initDC));
782+
} else {
783+
eval.cacheOutput(DefaultArgumentInitContextRequest{otherParam},
784+
std::move(initDC));
785+
}
784786
}
785787
assert(result && "Didn't create init context?");
786788
return result;

lib/Sema/TypeCheckStmt.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,6 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
635635
Type exnType = getASTContext().getErrorDecl()->getDeclaredType();
636636
if (!exnType) return TS;
637637

638-
// FIXME: Remove TypeChecker dependency.
639638
TypeChecker::typeCheckExpression(E, DC, TypeLoc::withoutLoc(exnType),
640639
CTP_ThrowStmt);
641640
TS->setSubExpr(E);

0 commit comments

Comments
 (0)