Skip to content

Commit 5dfd51a

Browse files
committed
[ConstraintSystem] Switch getConstraintLocator variants to use TypedNode for anchor
1 parent 398f378 commit 5dfd51a

File tree

5 files changed

+24
-39
lines changed

5 files changed

+24
-39
lines changed

lib/Sema/CSGen.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4489,7 +4489,7 @@ bool swift::areGenericRequirementsSatisfied(
44894489

44904490
ConstraintSystemOptions Options;
44914491
ConstraintSystem CS(const_cast<DeclContext *>(DC), Options);
4492-
auto Loc = CS.getConstraintLocator(nullptr);
4492+
auto Loc = CS.getConstraintLocator({});
44934493

44944494
// For every requirement, add a constraint.
44954495
for (auto Req : sig->getRequirements()) {
@@ -4564,7 +4564,7 @@ swift::resolveValueMember(DeclContext &DC, Type BaseTy, DeclName Name) {
45644564
return Result;
45654565

45664566
// Try to figure out the best overload.
4567-
ConstraintLocator *Locator = CS.getConstraintLocator(nullptr);
4567+
ConstraintLocator *Locator = CS.getConstraintLocator({});
45684568
TypeVariableType *TV = CS.createTypeVariable(Locator,
45694569
TVO_CanBindToLValue |
45704570
TVO_CanBindToNoEscape);

lib/Sema/ConstraintSystem.h

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -802,11 +802,6 @@ struct Score {
802802

803803
};
804804

805-
/// An AST node that can gain type information while solving.
806-
using TypedNode =
807-
llvm::PointerUnion<const Expr *, const TypeLoc *,
808-
const VarDecl *, const Pattern *>;
809-
810805
/// Display a score.
811806
llvm::raw_ostream &operator<<(llvm::raw_ostream &out, const Score &score);
812807

@@ -1020,7 +1015,7 @@ class Solution {
10201015
bool lookThroughApply = true) const;
10211016

10221017
ConstraintLocator *
1023-
getConstraintLocator(const Expr *anchor,
1018+
getConstraintLocator(TypedNode anchor,
10241019
ArrayRef<LocatorPathElt> path = {}) const;
10251020

10261021
ConstraintLocator *getConstraintLocator(ConstraintLocator *baseLocator,
@@ -1867,11 +1862,7 @@ class ConstraintSystem {
18671862
if (!locator)
18681863
continue;
18691864

1870-
if (auto *anchor = locator->getAnchor()) {
1871-
auto *OSR = dyn_cast<OverloadSetRefExpr>(anchor);
1872-
if (!OSR)
1873-
continue;
1874-
1865+
if (auto *OSR = getAsExpr<OverloadSetRefExpr>(locator->getAnchor())) {
18751866
if (shrunkExprs.count(OSR) > 0)
18761867
--unsolvedDisjunctions;
18771868
}
@@ -2606,36 +2597,31 @@ class ConstraintSystem {
26062597
/// Retrieve the constraint locator for the given anchor and
26072598
/// path, uniqued.
26082599
ConstraintLocator *
2609-
getConstraintLocator(Expr *anchor,
2600+
getConstraintLocator(TypedNode anchor,
26102601
ArrayRef<ConstraintLocator::PathElement> path,
26112602
unsigned summaryFlags);
26122603

26132604
/// Retrive the constraint locator for the given anchor and
26142605
/// path, uniqued and automatically infer the summary flags
26152606
ConstraintLocator *
2616-
getConstraintLocator(Expr *anchor,
2607+
getConstraintLocator(TypedNode anchor,
26172608
ArrayRef<ConstraintLocator::PathElement> path);
26182609

26192610
/// Retrieve the constraint locator for the given anchor and
26202611
/// an empty path, uniqued.
2621-
ConstraintLocator *getConstraintLocator(Expr *anchor) {
2612+
ConstraintLocator *getConstraintLocator(TypedNode anchor) {
26222613
return getConstraintLocator(anchor, {}, 0);
26232614
}
26242615

26252616
/// Retrieve the constraint locator for the given anchor and
26262617
/// path element.
26272618
ConstraintLocator *
2628-
getConstraintLocator(Expr *anchor, ConstraintLocator::PathElement pathElt) {
2619+
getConstraintLocator(TypedNode anchor,
2620+
ConstraintLocator::PathElement pathElt) {
26292621
return getConstraintLocator(anchor, llvm::makeArrayRef(pathElt),
26302622
pathElt.getNewSummaryFlags());
26312623
}
26322624

2633-
ConstraintLocator *
2634-
getConstraintLocator(const Expr *anchor,
2635-
ConstraintLocator::PathElement pathElt) {
2636-
return getConstraintLocator(const_cast<Expr *>(anchor), pathElt);
2637-
}
2638-
26392625
/// Extend the given constraint locator with a path element.
26402626
ConstraintLocator *
26412627
getConstraintLocator(ConstraintLocator *locator,
@@ -4967,23 +4953,22 @@ ConstraintLocator *simplifyLocator(ConstraintSystem &cs,
49674953
ConstraintLocator *locator,
49684954
SourceRange &range);
49694955

4970-
void simplifyLocator(Expr *&anchor,
4971-
ArrayRef<LocatorPathElt> &path,
4956+
void simplifyLocator(TypedNode &anchor, ArrayRef<LocatorPathElt> &path,
49724957
SourceRange &range);
49734958

49744959
/// Simplify the given locator down to a specific anchor expression,
49754960
/// if possible.
49764961
///
49774962
/// \returns the anchor expression if it fully describes the locator, or
49784963
/// null otherwise.
4979-
Expr *simplifyLocatorToAnchor(ConstraintLocator *locator);
4964+
TypedNode simplifyLocatorToAnchor(ConstraintLocator *locator);
49804965

4981-
/// Retrieve argument at specified index from given expression.
4966+
/// Retrieve argument at specified index from given node.
49824967
/// The expression could be "application", "subscript" or "member" call.
49834968
///
49844969
/// \returns argument expression or `nullptr` if given "base" expression
49854970
/// wasn't of one of the kinds listed above.
4986-
Expr *getArgumentExpr(Expr *expr, unsigned index);
4971+
Expr *getArgumentExpr(TypedNode node, unsigned index);
49874972

49884973
/// Determine whether given locator points to one of the arguments
49894974
/// associated with the call to an operator. If the operator name

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,14 @@ bool TypeVariableType::Implementation::isClosureType() const {
8787
if (!(locator && locator->getAnchor()))
8888
return false;
8989

90-
return isa<ClosureExpr>(locator->getAnchor()) && locator->getPath().empty();
90+
return isExpr<ClosureExpr>(locator->getAnchor()) && locator->getPath().empty();
9191
}
9292

9393
bool TypeVariableType::Implementation::isClosureResultType() const {
9494
if (!(locator && locator->getAnchor()))
9595
return false;
9696

97-
return isa<ClosureExpr>(locator->getAnchor()) &&
97+
return isExpr<ClosureExpr>(locator->getAnchor()) &&
9898
locator->isLastElement<LocatorPathElt::ClosureResult>();
9999
}
100100

@@ -184,18 +184,18 @@ bool constraints::computeTupleShuffle(ArrayRef<TupleTypeElt> fromTuple,
184184

185185
Expr *ConstraintLocatorBuilder::trySimplifyToExpr() const {
186186
SmallVector<LocatorPathElt, 4> pathBuffer;
187-
Expr *anchor = getLocatorParts(pathBuffer);
187+
auto anchor = getLocatorParts(pathBuffer);
188188
// Locators are not guaranteed to have an anchor
189189
// if constraint system is used to verify generic
190190
// requirements.
191-
if (!anchor)
191+
if (!anchor.is<const Expr *>())
192192
return nullptr;
193193

194194
ArrayRef<LocatorPathElt> path = pathBuffer;
195195

196196
SourceRange range;
197197
simplifyLocator(anchor, path, range);
198-
return (path.empty() ? anchor : nullptr);
198+
return (path.empty() ? getAsExpr(anchor) : nullptr);
199199
}
200200

201201
//===----------------------------------------------------------------------===//
@@ -2671,7 +2671,7 @@ static Type replaceArchetypesWithTypeVariables(ConstraintSystem &cs,
26712671
else if (root != archetypeType)
26722672
return Type();
26732673

2674-
auto locator = cs.getConstraintLocator(nullptr);
2674+
auto locator = cs.getConstraintLocator({});
26752675
auto replacement = cs.createTypeVariable(locator,
26762676
TVO_CanBindToNoEscape);
26772677

@@ -2689,7 +2689,7 @@ static Type replaceArchetypesWithTypeVariables(ConstraintSystem &cs,
26892689

26902690
// FIXME: Remove this case
26912691
assert(cast<GenericTypeParamType>(origType));
2692-
auto locator = cs.getConstraintLocator(nullptr);
2692+
auto locator = cs.getConstraintLocator({});
26932693
auto replacement = cs.createTypeVariable(locator,
26942694
TVO_CanBindToNoEscape);
26952695
types[origType] = replacement;
@@ -2711,7 +2711,7 @@ bool TypeChecker::typesSatisfyConstraint(Type type1, Type type2,
27112711
type2 = replaceArchetypesWithTypeVariables(cs, type2);
27122712
}
27132713

2714-
cs.addConstraint(kind, type1, type2, cs.getConstraintLocator(nullptr));
2714+
cs.addConstraint(kind, type1, type2, cs.getConstraintLocator({}));
27152715

27162716
if (openArchetypes) {
27172717
assert(!unwrappedIUO && "FIXME");

lib/Sema/TypeCheckPropertyWrapper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ PropertyWrapperBackingPropertyTypeRequest::evaluate(
593593
using namespace constraints;
594594
auto dc = var->getInnermostDeclContext();
595595
ConstraintSystem cs(dc, None);
596-
auto emptyLocator = cs.getConstraintLocator(nullptr);
596+
auto emptyLocator = cs.getConstraintLocator({});
597597

598598
auto wrapperAttrs = var->getAttachedPropertyWrappers();
599599
Type valueMemberType;

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -943,8 +943,8 @@ swift::matchWitness(WitnessChecker::RequirementEnvironmentCache &reqEnvCache,
943943
// Open up the witness type.
944944
witnessType = witness->getInterfaceType();
945945
// FIXME: witness as a base locator?
946-
locator = cs->getConstraintLocator(nullptr);
947-
witnessLocator = cs->getConstraintLocator(static_cast<Expr *>(nullptr),
946+
locator = cs->getConstraintLocator({});
947+
witnessLocator = cs->getConstraintLocator({},
948948
LocatorPathElt::Witness(witness));
949949
if (witness->getDeclContext()->isTypeContext()) {
950950
std::tie(openedFullWitnessType, openWitnessType)

0 commit comments

Comments
 (0)