Skip to content

Commit 1d47dc9

Browse files
authored
Merge pull request #18494 from gregomni/omitRestrictions
[Sema] Omit recording some conversion restrictions in constraint solutions
2 parents d924be3 + a37229e commit 1d47dc9

File tree

2 files changed

+22
-29
lines changed

2 files changed

+22
-29
lines changed

lib/Sema/CSApply.cpp

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6487,24 +6487,13 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
64876487
toType->getCanonicalType() });
64886488
if (knownRestriction != solution.ConstraintRestrictions.end()) {
64896489
switch (knownRestriction->second) {
6490-
case ConversionRestrictionKind::TupleToTuple: {
6491-
auto fromTuple = fromType->castTo<TupleType>();
6492-
auto toTuple = toType->castTo<TupleType>();
6493-
SmallVector<int, 4> sources;
6494-
SmallVector<unsigned, 4> variadicArgs;
6495-
bool failed = computeTupleShuffle(fromTuple, toTuple,
6496-
sources, variadicArgs);
6497-
assert(!failed && "Couldn't convert tuple to tuple?");
6498-
(void)failed;
6499-
return coerceTupleToTuple(expr, fromTuple, toTuple, locator, sources,
6500-
variadicArgs, typeFromPattern);
6501-
}
65026490

6503-
case ConversionRestrictionKind::ScalarToTuple: {
6504-
auto toTuple = toType->castTo<TupleType>();
6505-
return coerceScalarToTuple(expr, toTuple,
6506-
toTuple->getElementForScalarInit(), locator);
6507-
}
6491+
case ConversionRestrictionKind::TupleToTuple:
6492+
case ConversionRestrictionKind::ScalarToTuple:
6493+
case ConversionRestrictionKind::LValueToRValue:
6494+
// Restrictions that don't need to be recorded.
6495+
// Should match recordRestriction() in CSSimplify
6496+
break;
65086497

65096498
case ConversionRestrictionKind::DeepEquality: {
65106499
if (toType->hasUnresolvedType())
@@ -6548,22 +6537,13 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
65486537
}
65496538

65506539
case ConversionRestrictionKind::Superclass:
6540+
case ConversionRestrictionKind::ExistentialMetatypeToMetatype:
65516541
return coerceSuperclass(expr, toType, locator);
65526542

6553-
case ConversionRestrictionKind::LValueToRValue: {
6554-
if (toType->is<TupleType>() || fromType->is<TupleType>())
6555-
break;
6556-
6557-
return coerceToType(addImplicitLoadExpr(cs, expr), toType, locator);
6558-
}
6559-
65606543
case ConversionRestrictionKind::Existential:
65616544
case ConversionRestrictionKind::MetatypeToExistentialMetatype:
65626545
return coerceExistential(expr, toType, locator);
65636546

6564-
case ConversionRestrictionKind::ExistentialMetatypeToMetatype:
6565-
return coerceSuperclass(expr, toType, locator);
6566-
65676547
case ConversionRestrictionKind::ClassMetatypeToAnyObject: {
65686548
assert(tc.getLangOpts().EnableObjCInterop
65696549
&& "metatypes can only be cast to objects w/ objc runtime!");

lib/Sema/CSSimplify.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4880,6 +4880,19 @@ ConstraintSystem::simplifyRestrictedConstraintImpl(
48804880
llvm_unreachable("bad conversion restriction");
48814881
}
48824882

4883+
// Restrictions where CSApply can figure out the correct action from the shape of
4884+
// the types, rather than needing a record of the choice made.
4885+
static bool recordRestriction(ConversionRestrictionKind restriction) {
4886+
switch(restriction) {
4887+
case ConversionRestrictionKind::TupleToTuple:
4888+
case ConversionRestrictionKind::ScalarToTuple:
4889+
case ConversionRestrictionKind::LValueToRValue:
4890+
return false;
4891+
default:
4892+
return true;
4893+
}
4894+
}
4895+
48834896
ConstraintSystem::SolutionKind
48844897
ConstraintSystem::simplifyRestrictedConstraint(
48854898
ConversionRestrictionKind restriction,
@@ -4890,8 +4903,8 @@ ConstraintSystem::simplifyRestrictedConstraint(
48904903
switch (simplifyRestrictedConstraintImpl(restriction, type1, type2,
48914904
matchKind, flags, locator)) {
48924905
case SolutionKind::Solved:
4893-
ConstraintRestrictions.push_back(
4894-
std::make_tuple(type1, type2, restriction));
4906+
if (recordRestriction(restriction))
4907+
ConstraintRestrictions.push_back(std::make_tuple(type1, type2, restriction));
48954908
return SolutionKind::Solved;
48964909

48974910
case SolutionKind::Unsolved:

0 commit comments

Comments
 (0)