Skip to content

[Sema] Omit recording some conversion restrictions in constraint solutions #18494

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 7 additions & 27 deletions lib/Sema/CSApply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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!");
Expand Down
17 changes: 15 additions & 2 deletions lib/Sema/CSSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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:
Expand Down