Skip to content

Commit 04bddc2

Browse files
authored
Merge pull request #19587 from xedin/remove-applying-op-param-flag
[ConstraintSystem] Remove rudimental `TMF_ApplyingOperatorParameter` …
2 parents 8c8f822 + effd86f commit 04bddc2

File tree

5 files changed

+33
-49
lines changed

5 files changed

+33
-49
lines changed

lib/Sema/CSApply.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7916,11 +7916,8 @@ Expr *TypeChecker::callWitness(Expr *base, DeclContext *dc,
79167916
// Add the conversion from the argument to the function parameter type.
79177917
auto openedFuncType = openedType->castTo<FunctionType>();
79187918
::matchCallArguments(
7919-
cs, /*isOperator=*/false,
7920-
args,
7921-
openedFuncType->getParams(),
7922-
cs.getConstraintLocator(call,
7923-
ConstraintLocator::ApplyArgument));
7919+
cs, args, openedFuncType->getParams(),
7920+
cs.getConstraintLocator(call, ConstraintLocator::ApplyArgument));
79247921

79257922
// Solve the system.
79267923
SmallVector<Solution, 1> solutions;

lib/Sema/CSGen.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,9 +1340,8 @@ namespace {
13401340
AnyFunctionType::decomposeInput(constrParamType, params);
13411341

13421342
::matchCallArguments(
1343-
CS, /*isOperator=*/false, args, params,
1344-
CS.getConstraintLocator(expr,
1345-
ConstraintLocator::ApplyArgument));
1343+
CS, args, params,
1344+
CS.getConstraintLocator(expr, ConstraintLocator::ApplyArgument));
13461345

13471346
Type result = tv;
13481347
if (constr->getFailability() != OTK_None)

lib/Sema/CSSimplify.cpp

Lines changed: 18 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -756,11 +756,9 @@ class ArgumentFailureTracker : public MatchCallArgumentListener {
756756
};
757757

758758
// Match the argument of a call to the parameter.
759-
ConstraintSystem::TypeMatchResult
760-
constraints::matchCallArguments(ConstraintSystem &cs, bool isOperator,
761-
ArrayRef<AnyFunctionType::Param> args,
762-
ArrayRef<AnyFunctionType::Param> params,
763-
ConstraintLocatorBuilder locator) {
759+
ConstraintSystem::TypeMatchResult constraints::matchCallArguments(
760+
ConstraintSystem &cs, ArrayRef<AnyFunctionType::Param> args,
761+
ArrayRef<AnyFunctionType::Param> params, ConstraintLocatorBuilder locator) {
764762
// Extract the parameters.
765763
ValueDecl *callee;
766764
unsigned calleeLevel;
@@ -821,6 +819,15 @@ constraints::matchCallArguments(ConstraintSystem &cs, bool isOperator,
821819
// Check the argument types for each of the parameters.
822820
ConstraintSystem::TypeMatchOptions subflags =
823821
ConstraintSystem::TMF_GenerateConstraints;
822+
823+
// If this application is part of an operator, then we allow an implicit
824+
// lvalue to be compatible with inout arguments. This is used by
825+
// assignment operators.
826+
auto *anchor = locator.getAnchor();
827+
assert(anchor && "locator without anchor expression?");
828+
bool isOperator = (isa<PrefixUnaryExpr>(anchor) ||
829+
isa<PostfixUnaryExpr>(anchor) || isa<BinaryExpr>(anchor));
830+
824831
ConstraintKind subKind = (isOperator
825832
? ConstraintKind::OperatorArgumentConversion
826833
: ConstraintKind::ArgumentConversion);
@@ -841,15 +848,6 @@ constraints::matchCallArguments(ConstraintSystem &cs, bool isOperator,
841848
getApplyArgToParam(argIdx,
842849
paramIdx));
843850
auto argTy = argsWithLabels[argIdx].getOldType();
844-
845-
// FIXME: This should be revisited. If one of argTy or paramTy
846-
// is a type variable, matchTypes() will add a constraint, and
847-
// when the constraint is later solved, we will have lost the
848-
// value of 'subflags'.
849-
if (isOperator) {
850-
subflags |= ConstraintSystem::TMF_ApplyingOperatorParameter;
851-
}
852-
853851
auto result = cs.matchTypes(argTy, paramTy, subKind, subflags, loc);
854852
if (result.isFailure())
855853
return result;
@@ -2196,11 +2194,9 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
21962194
ConversionRestrictionKind::InoutToPointer);
21972195
}
21982196
}
2199-
2200-
if (!flags.contains(TMF_ApplyingOperatorParameter) &&
2201-
// Operators cannot use these implicit conversions.
2202-
kind == ConstraintKind::ArgumentConversion) {
22032197

2198+
// Operators cannot use these implicit conversions.
2199+
if (kind == ConstraintKind::ArgumentConversion) {
22042200
// We can potentially convert from an UnsafeMutablePointer
22052201
// of a different type, if we're a void pointer.
22062202
Type unwrappedType1 = type1;
@@ -3846,7 +3842,6 @@ ConstraintSystem::simplifyBridgingConstraint(Type type1,
38463842

38473843
// Explicit bridging from a value type to an Objective-C class type.
38483844
if (unwrappedFromType->isPotentiallyBridgedValueType() &&
3849-
!flags.contains(TMF_ApplyingOperatorParameter) &&
38503845
(unwrappedToType->isBridgeableObjectType() ||
38513846
(unwrappedToType->isExistentialType() &&
38523847
!unwrappedToType->isAny()))) {
@@ -4450,19 +4445,11 @@ ConstraintSystem::simplifyApplicableFnConstraint(
44504445
// For a function, bind the output and convert the argument to the input.
44514446
auto func1 = type1->castTo<FunctionType>();
44524447
if (auto func2 = dyn_cast<FunctionType>(desugar2)) {
4453-
// If this application is part of an operator, then we allow an implicit
4454-
// lvalue to be compatible with inout arguments. This is used by
4455-
// assignment operators.
4456-
bool isOperator = (isa<PrefixUnaryExpr>(anchor) ||
4457-
isa<PostfixUnaryExpr>(anchor) ||
4458-
isa<BinaryExpr>(anchor));
4459-
44604448
// The argument type must be convertible to the input type.
4461-
if (::matchCallArguments(*this, isOperator,
4462-
func1->getParams(),
4463-
func2->getParams(),
4464-
outerLocator.withPathElement(
4465-
ConstraintLocator::ApplyArgument)).isFailure())
4449+
if (::matchCallArguments(
4450+
*this, func1->getParams(), func2->getParams(),
4451+
outerLocator.withPathElement(ConstraintLocator::ApplyArgument))
4452+
.isFailure())
44664453
return SolutionKind::Error;
44674454

44684455
// The result types are equivalent.
@@ -4565,12 +4552,6 @@ ConstraintSystem::simplifyRestrictedConstraintImpl(
45654552
return SolutionKind::Unsolved;
45664553
};
45674554

4568-
// We'll apply user conversions for operator arguments at the application
4569-
// site.
4570-
if (matchKind == ConstraintKind::OperatorArgumentConversion) {
4571-
flags |= TMF_ApplyingOperatorParameter;
4572-
}
4573-
45744555
TypeMatchOptions subflags = getDefaultDecompositionOptions(flags);
45754556

45764557
switch (restriction) {

lib/Sema/ConstraintLocator.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,17 @@ class ConstraintLocatorBuilder {
573573
return nullptr;
574574
}
575575

576+
/// Get anchor expression associated with this locator builder.
577+
Expr *getAnchor() const {
578+
for (auto prev = this; prev;
579+
prev = prev->previous.dyn_cast<ConstraintLocatorBuilder *>()) {
580+
if (auto *locator = prev->previous.dyn_cast<ConstraintLocator *>())
581+
return locator->getAnchor();
582+
}
583+
584+
return nullptr;
585+
}
586+
576587
/// \brief Retrieve the components of the complete locator, which includes
577588
/// the anchor expression and the path.
578589
Expr *getLocatorParts(SmallVectorImpl<LocatorPathElt> &path) const {

lib/Sema/ConstraintSystem.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2006,9 +2006,6 @@ class ConstraintSystem {
20062006

20072007
/// Indicates that we are applying a fix.
20082008
TMF_ApplyingFix = 0x02,
2009-
2010-
/// Indicates we're matching an operator parameter.
2011-
TMF_ApplyingOperatorParameter = 0x4,
20122009
};
20132010

20142011
/// Options that govern how type matching should proceed.
@@ -3305,7 +3302,6 @@ bool matchCallArguments(ArrayRef<AnyFunctionType::Param> args,
33053302

33063303
ConstraintSystem::TypeMatchResult
33073304
matchCallArguments(ConstraintSystem &cs,
3308-
bool isOperator,
33093305
ArrayRef<AnyFunctionType::Param> args,
33103306
ArrayRef<AnyFunctionType::Param> params,
33113307
ConstraintLocatorBuilder locator);

0 commit comments

Comments
 (0)