Skip to content

Commit 1683fb9

Browse files
committed
[ConstraintSystem] Remove RValueAdjustment locator element
It was used for unresolved member and `.dynamicType` references as well as a couple of other places, but now unresolved member references no longer need that due to new implicit "chain result" AST node and other places could use more precise locators e.g. new `.dynamicType` locator or `sequence element` for `for in` loops.
1 parent 860e14e commit 1683fb9

File tree

7 files changed

+20
-27
lines changed

7 files changed

+20
-27
lines changed

include/swift/Sema/ConstraintLocatorPathElts.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ ABSTRACT_LOCATOR_PATH_ELT(AnyRequirement)
147147
/// A single requirement placed on the type parameters.
148148
CUSTOM_LOCATOR_PATH_ELT(TypeParameterRequirement)
149149

150-
/// RValue adjustment.
151-
SIMPLE_LOCATOR_PATH_ELT(RValueAdjustment)
150+
/// Access to `.dynamicType` element
151+
SIMPLE_LOCATOR_PATH_ELT(DynamicType)
152152

153153
/// The element type of a sequence in a for ... in ... loop.
154154
SIMPLE_LOCATOR_PATH_ELT(SequenceElementType)

lib/Sema/BuilderTransform.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -810,10 +810,10 @@ class BuilderClosureVisitor
810810
VarDecl *arrayVar = buildVar(loc);
811811
Type arrayElementType = cs->createTypeVariable(
812812
cs->getConstraintLocator(forEachStmt), 0);
813-
cs->addConstraint(
814-
ConstraintKind::Equal, cs->getType(bodyVar), arrayElementType,
815-
cs->getConstraintLocator(
816-
forEachStmt, ConstraintLocator::RValueAdjustment));
813+
cs->addConstraint(ConstraintKind::Equal, cs->getType(bodyVar),
814+
arrayElementType,
815+
cs->getConstraintLocator(
816+
forEachStmt, ConstraintLocator::SequenceElementType));
817817
Type arrayType = ArraySliceType::get(arrayElementType);
818818
cs->setType(arrayVar, arrayType);
819819

lib/Sema/CSDiagnostics.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2463,9 +2463,6 @@ void ContextualFailure::tryFixIts(InFlightDiagnostic &diagnostic) const {
24632463
}
24642464

24652465
bool ContextualFailure::diagnoseMissingFunctionCall() const {
2466-
if (getLocator()->isLastElement<LocatorPathElt::RValueAdjustment>())
2467-
return false;
2468-
24692466
if (getLocator()
24702467
->isLastElement<LocatorPathElt::UnresolvedMemberChainResult>())
24712468
return false;

lib/Sema/CSGen.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2591,9 +2591,9 @@ namespace {
25912591
Type visitDynamicTypeExpr(DynamicTypeExpr *expr) {
25922592
auto tv = CS.createTypeVariable(CS.getConstraintLocator(expr),
25932593
TVO_CanBindToNoEscape);
2594-
CS.addConstraint(ConstraintKind::DynamicTypeOf, tv,
2595-
CS.getType(expr->getBase()),
2596-
CS.getConstraintLocator(expr, ConstraintLocator::RValueAdjustment));
2594+
CS.addConstraint(
2595+
ConstraintKind::DynamicTypeOf, tv, CS.getType(expr->getBase()),
2596+
CS.getConstraintLocator(expr, ConstraintLocator::DynamicType));
25972597
return tv;
25982598
}
25992599

lib/Sema/CSSimplify.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4371,9 +4371,6 @@ bool ConstraintSystem::repairFailures(
43714371
break;
43724372
}
43734373

4374-
case ConstraintLocator::RValueAdjustment:
4375-
return true;
4376-
43774374
case ConstraintLocator::UnresolvedMemberChainResult: {
43784375
if (repairViaOptionalUnwrap(*this, lhs, rhs, matchKind, conversionsOrFixes,
43794376
locator))

lib/Sema/ConstraintLocator.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ unsigned LocatorPathElt::getNewSummaryFlags() const {
5454
case ConstraintLocator::ParentType:
5555
case ConstraintLocator::ExistentialSuperclassType:
5656
case ConstraintLocator::LValueConversion:
57-
case ConstraintLocator::RValueAdjustment:
57+
case ConstraintLocator::DynamicType:
5858
case ConstraintLocator::SubscriptMember:
5959
case ConstraintLocator::OpenedGeneric:
6060
case ConstraintLocator::GenericParameter:
@@ -350,8 +350,8 @@ void ConstraintLocator::dump(SourceManager *sm, raw_ostream &out) const {
350350
out << "@lvalue-to-inout conversion";
351351
break;
352352

353-
case RValueAdjustment:
354-
out << "rvalue adjustment";
353+
case DynamicType:
354+
out << "`.dynamicType` reference";
355355
break;
356356

357357
case SubscriptMember:

lib/Sema/ConstraintSystem.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1868,8 +1868,9 @@ static std::pair<Type, Type> getTypeOfReferenceWithSpecialTypeCheckingSemantics(
18681868
FunctionType::Param inputArg(input,
18691869
CS.getASTContext().getIdentifier("of"));
18701870

1871-
CS.addConstraint(ConstraintKind::DynamicTypeOf, output, input,
1872-
CS.getConstraintLocator(locator, ConstraintLocator::RValueAdjustment));
1871+
CS.addConstraint(
1872+
ConstraintKind::DynamicTypeOf, output, input,
1873+
CS.getConstraintLocator(locator, ConstraintLocator::DynamicType));
18731874
auto refType = FunctionType::get({inputArg}, output);
18741875
return {refType, refType};
18751876
}
@@ -1883,9 +1884,8 @@ static std::pair<Type, Type> getTypeOfReferenceWithSpecialTypeCheckingSemantics(
18831884
auto escapeClosure = CS.createTypeVariable(
18841885
CS.getConstraintLocator(locator, ConstraintLocator::FunctionArgument),
18851886
TVO_CanBindToNoEscape);
1886-
CS.addConstraint(ConstraintKind::EscapableFunctionOf,
1887-
escapeClosure, noescapeClosure,
1888-
CS.getConstraintLocator(locator, ConstraintLocator::RValueAdjustment));
1887+
CS.addConstraint(ConstraintKind::EscapableFunctionOf, escapeClosure,
1888+
noescapeClosure, CS.getConstraintLocator(locator));
18891889
auto result = CS.createTypeVariable(
18901890
CS.getConstraintLocator(locator, ConstraintLocator::FunctionResult),
18911891
TVO_CanBindToNoEscape);
@@ -1916,9 +1916,8 @@ static std::pair<Type, Type> getTypeOfReferenceWithSpecialTypeCheckingSemantics(
19161916
auto existentialTy = CS.createTypeVariable(
19171917
CS.getConstraintLocator(locator, ConstraintLocator::FunctionArgument),
19181918
TVO_CanBindToNoEscape);
1919-
CS.addConstraint(ConstraintKind::OpenedExistentialOf,
1920-
openedTy, existentialTy,
1921-
CS.getConstraintLocator(locator, ConstraintLocator::RValueAdjustment));
1919+
CS.addConstraint(ConstraintKind::OpenedExistentialOf, openedTy,
1920+
existentialTy, CS.getConstraintLocator(locator));
19221921
auto result = CS.createTypeVariable(
19231922
CS.getConstraintLocator(locator, ConstraintLocator::FunctionResult),
19241923
TVO_CanBindToNoEscape);
@@ -3914,7 +3913,7 @@ void constraints::simplifyLocator(ASTNode &anchor,
39143913

39153914
case ConstraintLocator::AutoclosureResult:
39163915
case ConstraintLocator::LValueConversion:
3917-
case ConstraintLocator::RValueAdjustment:
3916+
case ConstraintLocator::DynamicType:
39183917
case ConstraintLocator::UnresolvedMember:
39193918
case ConstraintLocator::ImplicitCallAsFunction:
39203919
// Arguments in autoclosure positions, lvalue and rvalue adjustments,

0 commit comments

Comments
 (0)