Omit recording conversion restrictions in a solution that apply can just as easily figure out itself from the shape of the types.

This commit is contained in:
gregomni
2018-08-03 11:02:04 -07:00
parent ecdfb5d8fb
commit a37229e40a
2 changed files with 22 additions and 29 deletions

View File

@@ -6487,24 +6487,13 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
toType->getCanonicalType() });
if (knownRestriction != solution.ConstraintRestrictions.end()) {
switch (knownRestriction->second) {
case ConversionRestrictionKind::TupleToTuple: {
auto fromTuple = fromType->castTo<TupleType>();
auto toTuple = toType->castTo<TupleType>();
SmallVector<int, 4> sources;
SmallVector<unsigned, 4> variadicArgs;
bool failed = computeTupleShuffle(fromTuple, toTuple,
sources, variadicArgs);
assert(!failed && "Couldn't convert tuple to tuple?");
(void)failed;
return coerceTupleToTuple(expr, fromTuple, toTuple, locator, sources,
variadicArgs, typeFromPattern);
}
case ConversionRestrictionKind::ScalarToTuple: {
auto toTuple = toType->castTo<TupleType>();
return coerceScalarToTuple(expr, toTuple,
toTuple->getElementForScalarInit(), locator);
}
case ConversionRestrictionKind::TupleToTuple:
case ConversionRestrictionKind::ScalarToTuple:
case ConversionRestrictionKind::LValueToRValue:
// Restrictions that don't need to be recorded.
// Should match recordRestriction() in CSSimplify
break;
case ConversionRestrictionKind::DeepEquality: {
if (toType->hasUnresolvedType())
@@ -6548,22 +6537,13 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
}
case ConversionRestrictionKind::Superclass:
case ConversionRestrictionKind::ExistentialMetatypeToMetatype:
return coerceSuperclass(expr, toType, locator);
case ConversionRestrictionKind::LValueToRValue: {
if (toType->is<TupleType>() || fromType->is<TupleType>())
break;
return coerceToType(addImplicitLoadExpr(cs, expr), toType, locator);
}
case ConversionRestrictionKind::Existential:
case ConversionRestrictionKind::MetatypeToExistentialMetatype:
return coerceExistential(expr, toType, locator);
case ConversionRestrictionKind::ExistentialMetatypeToMetatype:
return coerceSuperclass(expr, toType, locator);
case ConversionRestrictionKind::ClassMetatypeToAnyObject: {
assert(tc.getLangOpts().EnableObjCInterop
&& "metatypes can only be cast to objects w/ objc runtime!");

View File

@@ -4879,6 +4879,19 @@ ConstraintSystem::simplifyRestrictedConstraintImpl(
llvm_unreachable("bad conversion restriction");
}
// Restrictions where CSApply can figure out the correct action from the shape of
// the types, rather than needing a record of the choice made.
static bool recordRestriction(ConversionRestrictionKind restriction) {
switch(restriction) {
case ConversionRestrictionKind::TupleToTuple:
case ConversionRestrictionKind::ScalarToTuple:
case ConversionRestrictionKind::LValueToRValue:
return false;
default:
return true;
}
}
ConstraintSystem::SolutionKind
ConstraintSystem::simplifyRestrictedConstraint(
ConversionRestrictionKind restriction,
@@ -4889,8 +4902,8 @@ ConstraintSystem::simplifyRestrictedConstraint(
switch (simplifyRestrictedConstraintImpl(restriction, type1, type2,
matchKind, flags, locator)) {
case SolutionKind::Solved:
ConstraintRestrictions.push_back(
std::make_tuple(type1, type2, restriction));
if (recordRestriction(restriction))
ConstraintRestrictions.push_back(std::make_tuple(type1, type2, restriction));
return SolutionKind::Solved;
case SolutionKind::Unsolved: