Skip to content

Commit 0ededb6

Browse files
authored
Merge pull request #14585 from rudkx/rdar37073401-4.1
[4.1] Fix an issue with the constraint favoring code in the constraint optimizer.
2 parents 935d876 + 0b60439 commit 0ededb6

File tree

14 files changed

+54
-376
lines changed

14 files changed

+54
-376
lines changed

include/swift/Basic/LangOptions.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,6 @@ namespace swift {
152152
/// solver should be debugged.
153153
unsigned DebugConstraintSolverAttempt = 0;
154154

155-
/// \brief Enable the experimental constraint propagation in the
156-
/// type checker.
157-
bool EnableConstraintPropagation = false;
158-
159155
/// \brief Enable the iterative type checker.
160156
bool IterativeTypeChecker = false;
161157

include/swift/Option/FrontendOptions.td

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,6 @@ def debug_constraints : Flag<["-"], "debug-constraints">,
149149
def debug_constraints_attempt : Separate<["-"], "debug-constraints-attempt">,
150150
HelpText<"Debug the constraint solver at a given attempt">;
151151

152-
def propagate_constraints : Flag<["-"], "propagate-constraints">,
153-
HelpText<"Enable constraint propagation in the type checker">;
154-
155152
def iterative_type_checker : Flag<["-"], "iterative-type-checker">,
156153
HelpText<"Enable the iterative type checker">;
157154

lib/Frontend/CompilerInvocation.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,6 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
988988

989989
Opts.EnableASTScopeLookup |= Args.hasArg(OPT_enable_astscope_lookup);
990990
Opts.DebugConstraintSolver |= Args.hasArg(OPT_debug_constraints);
991-
Opts.EnableConstraintPropagation |= Args.hasArg(OPT_propagate_constraints);
992991
Opts.IterativeTypeChecker |= Args.hasArg(OPT_iterative_type_checker);
993992
Opts.NamedLazyMemberLoading &= !Args.hasArg(OPT_disable_named_lazy_member_loading);
994993
Opts.DebugGenericSignatures |= Args.hasArg(OPT_debug_generic_signatures);

lib/Sema/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ add_swift_library(swiftSema STATIC
88
CSBindings.cpp
99
CSDiag.cpp
1010
CSGen.cpp
11-
CSPropagate.cpp
1211
CSRanking.cpp
1312
CSSimplify.cpp
1413
CSSolver.cpp

lib/Sema/CSGen.cpp

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,20 @@ namespace {
828828

829829
Type firstArgTy = argTupleTy->getElement(0).getType()->getWithoutParens();
830830
Type secondArgTy = argTupleTy->getElement(1).getType()->getWithoutParens();
831-
831+
832+
auto isOptionalWithMatchingObjectType = [](Type optional,
833+
Type object) -> bool {
834+
if (auto objTy = optional->getRValueType()->getAnyOptionalObjectType())
835+
return objTy->getRValueType()->isEqual(object->getRValueType());
836+
837+
return false;
838+
};
839+
840+
auto isPotentialForcingOpportunity = [&](Type first, Type second) -> bool {
841+
return isOptionalWithMatchingObjectType(first, second) ||
842+
isOptionalWithMatchingObjectType(second, first);
843+
};
844+
832845
// Determine whether the given declaration is favored.
833846
auto isFavoredDecl = [&](ValueDecl *value) -> bool {
834847
auto valueTy = value->getInterfaceType();
@@ -882,14 +895,14 @@ namespace {
882895

883896
auto resultTy = fnTy->getResult();
884897
auto contextualTy = CS.getContextualType(expr);
885-
886-
return
887-
(isFavoredParamAndArg(CS, firstParamTy, firstArg, firstArgTy,
888-
secondArgTy) ||
889-
isFavoredParamAndArg(CS, secondParamTy, secondArg, secondArgTy,
890-
firstArgTy)) &&
891-
firstParamTy->isEqual(secondParamTy) &&
892-
(!contextualTy || contextualTy->isEqual(resultTy));
898+
899+
return (isFavoredParamAndArg(CS, firstParamTy, firstArg, firstArgTy,
900+
secondArgTy) ||
901+
isFavoredParamAndArg(CS, secondParamTy, secondArg, secondArgTy,
902+
firstArgTy)) &&
903+
firstParamTy->isEqual(secondParamTy) &&
904+
!isPotentialForcingOpportunity(firstArgTy, secondArgTy) &&
905+
(!contextualTy || contextualTy->isEqual(resultTy));
893906
};
894907

895908
favorCallOverloads(expr, CS, isFavoredDecl);

0 commit comments

Comments
 (0)